summaryrefslogtreecommitdiff
path: root/testdata/scad/misc/string-unicode.scad
blob: 1386d63dd977b7f5dc697bc0db2824ec9ffbaa60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//Test length reporting
text_1bytes_len = "1234";
text_2bytes_len = "Π›Π›Π›Π›";
text_4bytes_len = "πŸ‚‘πŸ‚±πŸƒπŸƒ‘";

echo( "text_1bytes_len = ", text_1bytes_len, " len = ", len(text_1bytes_len)  );
echo( "text_2bytes_len = ", text_2bytes_len, " len = ", len(text_2bytes_len)  );
echo( "text_4bytes_len = ", text_4bytes_len, " len = ", len(text_4bytes_len)  );

//Test how well arrays of unicode string are accessed.

texts_array = [
"DEADBEEF",
"Π›Π΅Π½ΠΈΠ²Ρ‹ΠΉ Ρ€Ρ‹ΠΆΠΈΠΉ ΠΊΠΎΡ‚",
"ΩƒΨ³ΩˆΩ„ Ψ§Ω„Ψ²Ω†Ψ¬Ψ¨ΩŠΩ„ Ψ§Ω„Ω‚Ψ·",
"ζ‡Άζƒ°ηš„ε§œθ²“",
"Àâü Γ„Γ–Γœ ß",
"πŸ˜πŸ˜‚πŸ˜ƒπŸ˜„πŸ˜…πŸ˜†πŸ˜‡πŸ˜ˆπŸ˜‰πŸ˜ŠπŸ˜‹πŸ˜ŒπŸ˜πŸ˜ŽπŸ˜πŸ˜",
"β β ‚β ƒβ „β …β †β ‡β ˆβ ‰β Šβ ‹β Œβ β Žβ ",
"πŸ‚‘πŸ‚±πŸƒπŸƒ‘",
];

text_2bytes = "Π›Π΅Π½ΠΈΠ²Ρ‹ΠΉ Ρ€Ρ‹ΠΆΠΈΠΉ ΠΊΠΎΡ‚";
text_4bytes = "πŸ‚‘πŸ‚±πŸƒπŸƒ‘";


//Test all the normal accesses
for (text_array_idx = [0:(len(texts_array)-1)])
{
	echo( "[", text_array_idx, "] = ", texts_array[text_array_idx], " of len=", len(texts_array[text_array_idx]), ":"  );
    for (text_idx = [0:(len(texts_array[text_array_idx])-1)])
    {
	    echo( "    [", text_idx, ,"]=", texts_array[text_array_idx][text_idx]  );
    }
}

//Test one past the last element of (x-byte unicode). This will be one past the length but inside the char length of the string
echo( "Past end of unicode only 2-byte ", text_2bytes[len(text_2bytes)]  );
echo( "Past end of unicode only 4-byte ", text_4bytes[len(text_4bytes)]  );

//Test past the last element of (x-byte unicode). Outside both lengths.
echo( "Past end of both 2-byte ", text_2bytes[ len(text_2bytes) * 2 ]   );
echo( "Past end of both 4-byte ", text_4bytes[ len(text_4bytes) * 4 ]   );

contact: Jan Huwald // Impressum