View Issue Details

IDProjectCategoryView StatusLast Update
0024319LazarusLazUtilspublic2013-09-26 18:27
ReporterBernard Marcelly Assigned ToBart Broersma  
Status resolvedResolutionfixed 
PlatformX86OSWindows XP 
Product Version1.0.8 
Fixed in Version1.1 (SVN) 
Summary0024319: Add routines for padding an UTF8 string
DescriptionI needed to PadLeft an UTF8 string. Of course PadLeft() does not work correctly with an UTF8 string containing national characters.
But I did not find an UTF8 equivalent in Lazarus. So I had to create my own:

function UTF8PadLeft(const s : UTF8string; const n : integer) : UTF8string;
  result:= PadLeft(s, n +Length(s) -UTF8Length(s))

Request for improvement:
Please add UTF8 string routines in LazUTF8 for : PadLeft, PadRight, PadCenter, AddChar, AddCharR.
TagsNo tags attached.
Fixed in Revisionr42575, r42577
Attached Files


Juha Manninen

2013-04-25 08:16

developer   ~0067142

Does the new string type in FPC trunk solve this problem?
If yes, then it may be better use it or wait for the next FPC release.

Bart Broersma

2013-09-01 14:33

developer   ~0069631

> Does the new string type in FPC trunk solve this problem?
> If yes, then it may be better use it or wait for the next FPC release.

Or just implement it, then deprecate when fpc 2.8 makes them superfluous and remove at fpc 2.10?

Juha Manninen

2013-09-01 15:51

developer   ~0069634

Ok, then Bernard please attach a patch.

Bart Broersma

2013-09-01 16:55

developer   ~0069636

I already have an implementation that does not depend on StrUtils unit.
It needs a Utf8StringOfChar and I asked at devel list about my implementation of that. If that gets the OK flag, I'll implement.

function Utf8StringOfChar(AUtf8Char: Utf8String; N: Integer): Utf8String;
  i: Integer;
  US: UniCodeString;
  WC: WideChar;
  Result := '';
  if Utf8Length(AUtf8Char) <> 1 then Exit;
  if Length(AUtf8Char) = 1 then
    Result := StringOfChar(AUtf8Char[1], N)
    //for i := 1 to N do Result := Result + AUtf8Char; //ultimate lame version
    WC := Utf8ToUtf16(AUtf8Char)[1]; //we know Utf8Length(AUtf8Char) = 1
    SetLength(US, N);
    System.FillWord(US[1], N, Word(WC));
    Result := Utf16ToUtf8(US);

It will aloow us to PadLeft etc. with any char not just a space.

Bart Broersma

2013-09-03 14:12

developer   ~0069688

Please test and close if OK.

Issue History

Date Modified Username Field Change
2013-04-24 20:22 Bernard Marcelly New Issue
2013-04-24 23:21 Maxim Ganetsky LazTarget => -
2013-04-24 23:21 Maxim Ganetsky Severity minor => feature
2013-04-25 08:16 Juha Manninen Note Added: 0067142
2013-09-01 14:33 Bart Broersma Note Added: 0069631
2013-09-01 15:51 Juha Manninen Note Added: 0069634
2013-09-01 16:55 Bart Broersma Note Added: 0069636
2013-09-01 16:55 Bart Broersma Assigned To => Bart Broersma
2013-09-01 16:55 Bart Broersma Status new => assigned
2013-09-03 14:12 Bart Broersma Fixed in Revision => r42575
2013-09-03 14:12 Bart Broersma Note Added: 0069688
2013-09-03 14:12 Bart Broersma Status assigned => resolved
2013-09-03 14:12 Bart Broersma Fixed in Version => 1.1 (SVN)
2013-09-03 14:12 Bart Broersma Resolution open => fixed
2013-09-03 18:39 Bart Broersma Fixed in Revision r42575 => r42575, r42577