Sign in Join
Wiki copytemporary

UTF8 string class/en: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: UTF8 string class/en

OldNewLine
1+## What is TbUtf8?
2+
3+With the library TbUtf8 you can easily change UTF8 Strings.
4+
5+### Problem
6+
7+With Lazarus (Free Pascal) the string UTF8 encoded. However, the "String" type is nothing more than a dynamic byte array. Length returns the number of bytes in the array but not the number of characters. With UTF8, a character can be 4 bytes long and even 7 bytes with combined characters. An example should illustrate this. 'Thomas' 6 characters, 6 bytes in size. 'Thömäs' 6 characters, 8 bytes in size.
8+
9+### Solution
10+
11+With TbUtf8 you can now easily change and search UTF8 strings with special and combined characters, such as "üäößẶặǺǻǼǽǞǟǍǎḂḃÞþÇçĆćĊċ...". Essentially, the library consists of a UTF8 string class (TIbUtf8).
12+
13+### Benefits
14+
15+- TIbUtf8 is a class type of TInterfacedObject and does not need to be cleaned up with free.
16+- All indexes are character based.
17+- All returned characters are of type String.
18+- Returns the number of characters in the string.
19+- Returns the number of bytes in the string.
20+- Delete characters or character groups.
21+- Insertion of characters and character groups.
22+- Appending characters and character groups.
23+- Reading / writing of characters and character groups.
24+- Read from file / write to a file.
25+- Read from stream / write to a stream.
26+
27+### Disadvantage
28+
29+- Since UTF8 does not have a constant offset from character to character, searching for characters is much more complex. Iterating over the characters is about 20 times slower than with the string. (Comfort has its price)
30+- Slightly more memory is required.
31+
32+### Example
33+
34+``` pascal
35+proceudre Demo01: Boolean;
36+var
37+ u: IbUtf8;
38+ i: Integer;
39+begin
40+ u:= TIbUtf8.Create('Thömäß');
41+ for i:= 1 to u.NumberOfChars do begin
42+ case u.Chars[i] of
43+ 'ö': u.Chars[i]:= 'o';
44+ 'ä': u.Chars[i]:= 'a';
45+ 'ß': u.Chars[i]:= 's';
46+ end;
47+ end;
48+ if u.Text = 'Thomas' then begin
49+ WriteLn('That's right!');
50+ end;
51+end;
52+```
53+
54+## DownLoad
55+
56+- GitLab FpTuxe/TbUtf8 repository
57+
58+[`FpTuxe/TbUtf8`](https://gitlab.com/FpTuxe/tbutf8)
59+
60+- Git clone
61+
62+``` bash
63+git clone https://gitlab.com/FpTuxe/tbutf8.git
64+```
65+
66+## Installation
67+
68+Variant 1
69+Start Lazarus and open your project.
70+
71+Lazarus-\>File-\>Open your workspace/tbutf8/src/tb_utf8.pas
72+
73+Lazarus-\>Project-\>Add Editor File to Project
74+
75+Variant 2
76+Start Lazarus and open your project.
77+
78+Lazarus-\>Package-\>Open Package File (.lpk) your workspace/tbutf8/src/tbutf8.lpk
79+
80+Now, click Use-\>Add to Project
81+
82+Close then Package window.
83+
84+## Functional Description
85+
86+The functional description, you can found under the project folder "doc/".
87+
88+---
89+*From the Free Pascal wiki, page "UTF8 string class/en", as it stood on 2022-01-23 after a change by FpTuxe, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
90+Category: Unicode

Back to history