Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Please define the term "Multi-byte safe" [closed]

Tags:

utf-8


I'm a bit lost with UTF-8 right now.
I'm looking for a precise definition of the term multi-byte safe.

like image 476
tex Avatar asked Jan 01 '26 01:01

tex


1 Answers

When you are dealing with unicode characters, it is not safe to assume that all the characters just take a single byte or char (java). So when reading or parsing a string, you need to take this into consideration.

Here is an excellent article which explains complexities when dealing with Unicode w.r.t Java.

  1. Stored characters can take up an inconsistent number of bytes. A UTF-8 encoded character might take between one (LATIN_CAPITAL_LETTER_A) and four (MATHEMATICAL_FRAKTUR_CAPITAL_G) bytes. Variable width encoding has implications for reading into and decoding from byte arrays.

  2. Not all code points can be stored in a char. The MATHEMATICAL_FRAKTUR_CAPITAL_G example lies in the supplementary range of characters and cannot be stored in 16 bits. It must be represented by two sequential char values, neither of which is meaningful by itself. The Character class provides methods for working with 32-bit code points.

    // Unicode code point to char array
     char[] math_fraktur_cap_g = Character.toChars(0x1D50A);
like image 127
rkg Avatar answered Jan 06 '26 09:01

rkg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!