prosyslab-classroom / cs348-information-security

61 stars 10 forks source link

[Question][Hw6] Is there a way to handle unicode without external library? #330

Closed m-spitfire closed 1 year ago

m-spitfire commented 1 year ago

Name: Murad Bashirov

Hello. I'm trying to generate a character from unicode codepoint as described in the json specification: image

But from my search in ocaml you have to use an external library like uutf to do this, is there a way to do without an external library?

m-spitfire commented 1 year ago

oops, sorry for notification, just "\u{codepoint}" works...

bonjune commented 1 year ago
First code point Last code point Byte 1 Byte 2 Byte 3 Byte 4
U+0000 U+007F 0xxxxxxx  
U+0080 U+07FF 110xxxxx 10xxxxxx  
U+0800 U+FFFF 1110xxxx 10xxxxxx 10xxxxxx  
U+10000 U+10FFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
character
    '0020' . '10FFFF' - '"' - '\'
    '\' escape

You can implement a function that converts a code point into a stream of bytes, and call Bytes.to_string.

Reference: https://en.wikipedia.org/wiki/UTF-8#Encoding

m-spitfire commented 1 year ago

Thanks @bonjune!