From a809e7683c4288015e44c328e81496b5c55194c5 Mon Sep 17 00:00:00 2001 From: mazen Date: Wed, 15 Sep 2004 14:03:58 +0000 Subject: [PATCH] * use FreeBIDI.InsertChar for UTF8 strings --- rtl/objpas/utf8bidi.pp | 48 ++++++++---------------------------------- 1 file changed, 9 insertions(+), 39 deletions(-) diff --git a/rtl/objpas/utf8bidi.pp b/rtl/objpas/utf8bidi.pp index 76a4ec15a4..be28bbbf01 100644 --- a/rtl/objpas/utf8bidi.pp +++ b/rtl/objpas/utf8bidi.pp @@ -26,6 +26,8 @@ function UnicodeToUTF8(aChar:WideChar):TUTF8Char; function UnicodeToUTF8(const Src:TString):TUTF8String; {Converts an UTF8 character to UCS 32 bits character} function UTF8ToUCS32(const UTF8Char:TUTF8Char):TUCS32Char; +{Converts an UTF8 character to UCS 16 bits character} +function UTF8ToUCS16(const UTF8Char:TUTF8Char):TUCS16Char; {Converts an UTF8 string to UCS 16 bits string} function UTF8ToUnicode(const Src:TUTF8String):TString; {Converts an UTF8 string to a double byte string} @@ -298,7 +300,7 @@ end; {****************************Visual aspects************************************} function VLength(const Src:TUTF8String; pDir:TDirection):Cardinal; begin - Result := VLength(UTF8ToUnicode(Src), pDir); + Result := FreeBIDI.VLength(UTF8ToUnicode(Src), pDir); end; function VPos(const UTF8Str:TUTF8String; lp:Integer; pDir, cDir:TDirection):Cardinal; @@ -429,45 +431,13 @@ end; function InsertChar(Src:TUTF8Char; var Dest:TUTF8String; vp:Integer; pDir:TDirection):Integer; var - v2l:TVisualToLogical; - lp,rvp:Integer; - c:TUTF8Char; + temp:TString; + c:TCharacter; begin - v2l := VisualToLogical(Dest, pDir); - rvp := v2l[0]; - if vp > rvp - then - begin - lp := Length(Dest) + 1 - end - else - lp := v2l[vp]; - c := LCharOf(Dest, lp); - if DirectionOf(c) = drRTL - then - begin - lp := lp + Length(c); - rvp := rvp + 1; - end; - case DirectionOf(Src) of - drRTL: - begin - Result := vp; - while (Result > 0) and (DirectionOf(LCharOf(Dest, v2l[Result])) <> drLTR) do - Result := Result - 1; - while (Result < vp) and (DirectionOf(LCharOf(Dest, v2l[Result])) <> drRTL) do - Result := Result + 1; - end; - drLTR: - begin - Result := rvp + 1; - end; - else - begin - Result := rvp + 1; - end; - end; - Insert(Src, Dest, lp); + temp := UTF8ToUnicode(Dest); + c := WideChar(UTF8ToUCS16(Src)); + Result := FreeBIDI.InsertChar(c, temp, vp, pDir); + Dest := UnicodeToUTF8(temp); end; procedure VInsert(const Src:TUTF8String;var Dest:TUTF8String; vp:Integer; pDir:TDirection);