ソースを参照

* UTF8CharAtBytePos

Michaël Van Canneyt 6 ヶ月 前
コミット
c91c6c7be7
1 ファイル変更20 行追加0 行削除
  1. 20 0
      src/base/utf8utils.pp

+ 20 - 0
src/base/utf8utils.pp

@@ -192,6 +192,9 @@ function UTF8ToUTF16(const P: PChar; ByteCnt: SizeUInt): UnicodeString; overload
 function UTF16ToUTF8(const S: UnicodeString): AnsiString; overload; inline;
 function UTF16ToUTF8(const P: PWideChar; WideCnt: SizeUInt): AnsiString; overload;
 
+function UTF8CharAtBytePos(const s: Ansistring; const BytePos: PtrInt; out aChar: AnsiString): PtrInt;
+
+
 var
   FPUpChars: array[char] of char;
 
@@ -4052,6 +4055,23 @@ begin
     Result := '';
 end;
 
+function UTF8CharAtBytePos(const s: Ansistring; const BytePos: PtrInt; out aChar: AnsiString): PtrInt;
+var
+  lCharLen: Integer;
+begin
+  if BytePos > 0 then
+  begin
+    lCharLen := UTF8CodepointSize(@s[BytePos]);
+    aChar   := Copy(s, BytePos, lCharLen);
+    Result  := BytePos + lCharLen;
+  end else
+  begin
+    aChar   := '';
+    Result  := 1;
+  end;
+end;
+
+
 procedure InitFPUpchars;
 var
   c: Char;