Browse Source

* Implemented StrCharLength and StrNextChar for PWideChar strings.

git-svn-id: branches/unicodertl@12123 -
yury 17 years ago
parent
commit
0f5f1c7c11
2 changed files with 29 additions and 4 deletions
  1. 25 2
      rtl/objpas/sysutils/sysstr.inc
  2. 4 2
      rtl/objpas/sysutils/sysstrh.inc

+ 25 - 2
rtl/objpas/sysutils/sysstr.inc

@@ -2571,18 +2571,41 @@ begin
 end;
 
 
-Function StrCharLength(const Str: PChar): Integer;
+Function StrCharLength(const Str: PAnsiChar): Integer;
 begin
   result:=widestringmanager.CharLengthPCharProc(Str);
 end;
 
 
-function StrNextChar(const Str: PChar): PChar;
+Function StrCharLength(const Str: PWideChar): Integer;
+var
+  c: WideChar;
+begin
+  Result:=0;
+  c:=Str^;
+  if c = #0 then exit;
+  Inc(Result);
+  Inc(Str);
+  if (c >= #$d800) and (c <= #$dbff) then begin
+    c:=Str^;
+    if (c <> #0) and (c >= #$dc00) and (c <= #$dfff) then
+      Inc(Result);
+  end;
+end;
+
+
+function StrNextChar(const Str: PAnsiChar): PAnsiChar;
 begin
   result:=Str+StrCharLength(Str);
 end;
 
 
+function StrNextChar(const Str: PWideChar): PWideChar;
+begin
+  Result:=Str+StrCharLength(Str);
+end;
+
+
 Function FindCmdLineSwitch(const Switch: string; const Chars: TSysCharSet;IgnoreCase: Boolean): Boolean;
 
 Var

+ 4 - 2
rtl/objpas/sysutils/sysstrh.inc

@@ -230,8 +230,10 @@ Function StrByteType(Str: PChar; Index: Cardinal): TMbcsByteType;
 Function ByteToCharLen(const S: string; MaxLen: Integer): Integer;
 Function CharToByteLen(const S: string; MaxLen: Integer): Integer;
 Function ByteToCharIndex(const S: string; Index: Integer): Integer;
-Function StrCharLength(const Str: PChar): Integer;
-function StrNextChar(const Str: PChar): PChar;
+Function StrCharLength(const Str: PAnsiChar): Integer; overload;
+Function StrCharLength(const Str: PWideChar): Integer; overload;
+function StrNextChar(const Str: PAnsiChar): PAnsiChar; overload;
+function StrNextChar(const Str: PWideChar): PWideChar; overload;
 
 
 const