note
massa
For any UTF8 string, we have four "lengths":
<ol>
<li>the length in codepoints:
<c>
perl -C63 -MDevel::Peek -Mutf8 -le '$_="(\x{5fcd} Guimarăes)"; Dump($_); print length($_); print'
SV = PV(0x8154b00) at 0x8153bd4
REFCNT = 1
FLAGS = (POK,pPOK,UTF8)
PV = 0x8170460 "(\345\277\215 Guimar\303\243es)"\0 [UTF8 "(\x{5fcd} Guimar\x{e3}es)"]
CUR = 16
LEN = 20
13
</c>
(忍 Guimarăes)
<li>the length in graphemes (the "a" is one, the composing "~" is another):
<c>
perl -C63 -MDevel::Peek -Mutf8 -MUnicode::Normalize -le '$_="(\x{5fcd} Guimarăes)"; $_ = NFD $_; Dump($_); print length($_); print'
SV = PV(0x8154b00) at 0x8153bd4
REFCNT = 1
FLAGS = (POK,pPOK,UTF8)
PV = 0x816feb8 "(\345\277\215 Guimara\314\203es)"\0 [UTF8 "(\x{5fcd} Guimara\x{303}es)"]
CUR = 17
LEN = 20
14
</c>
(忍 Guimarães)
<li>the length in columns of text used (the string has one wide character):
<c>
perl -C63 -MDevel::Peek -Mutf8 -mText::CharWidth=mbswidth -le '$_="(\x{5fcd} Guimarăes)"; Dump($_); print mbswidth($_); print'
SV = PV(0x8154b00) at 0x8153bd4
REFCNT = 1
FLAGS = (POK,pPOK,UTF8)
PV = 0x8170460 "(\345\277\215 Guimar\303\243es)"\0 [UTF8 "(\x{5fcd} Guimar\x{e3}es)"]
CUR = 16
LEN = 20
14
</c>
(忍 Guimarăes)
<li>the length in bytes of the string (notice I didn't print the string after the encode):
<c>
perl -C63 -MDevel::Peek -Mutf8 -mEncode=encode_utf8 -le '$_="(\x{5fcd} Guimarăes)"; Dump($_); print length(encode_utf8 $_)'
SV = PV(0x8154b00) at 0x8153bd4
REFCNT = 1
FLAGS = (POK,pPOK,UTF8)
PV = 0x8170460 "(\345\277\215 Guimar\303\243es)"\0 [UTF8 "(\x{5fcd} Guimar\x{e3}es)"]
CUR = 16
LEN = 20
16
</c>
</ol>
<div class="pmsig"><div class="pmsig-686728">
[]s, HTH, Massa (κς,πμ,πλ)
</div></div>
713297
713297