Sign in Join
Wiki copytemporary

UTF8 string class/en

What is TbUtf8?

With the library TbUtf8 you can easily change UTF8 Strings.

Problem

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.

Solution

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).

Benefits

Disadvantage

Example

pascal
proceudre Demo01: Boolean;
var
  u: IbUtf8;
  i: Integer;
begin
  u:= TIbUtf8.Create('Thömäß');
  for i:= 1 to u.NumberOfChars do begin
    case u.Chars[i] of
      'ö': u.Chars[i]:= 'o';
      'ä': u.Chars[i]:= 'a';
      'ß': u.Chars[i]:= 's';
    end;
  end;
  if u.Text = 'Thomas' then begin
    WriteLn('That's right!');
  end;
end;

DownLoad

text
FpTuxe/TbUtf8
bash
git clone https://gitlab.com/FpTuxe/tbutf8.git

Installation

Variant 1
Start Lazarus and open your project.

Lazarus->File->Open your workspace/tbutf8/src/tb_utf8.pas

Lazarus->Project->Add Editor File to Project

Variant 2
Start Lazarus and open your project.

Lazarus->Package->Open Package File (.lpk) your workspace/tbutf8/src/tbutf8.lpk

Now, click Use->Add to Project

Close then Package window.

Functional Description

The functional description, you can found under the project folder "doc/".


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.

Revision 2, last changed by WikiArchive .

Edited on wiki.freepascal.org by 1 person, 2022

From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.

WhenWhoWhat changed
FpTuxeCreated page
FpTuxeWhat is TbUtf8?
FpTuxeWhat is TbUtf8?
FpTuxeWhat is TbUtf8?
FpTuxeWhat is TbUtf8?
FpTuxe
FpTuxe
FpTuxeWhat is TbUtf8?
FpTuxe
FpTuxeDownload / Installation
FpTuxeWhat is TbUtf8?
FpTuxeWhat is TbUtf8?
FpTuxe
FpTuxe
FpTuxeWhat is TbUtf8?
FpTuxe

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.