2
0
Эх сурвалжийг харах

* Trim removes now all spaces and controll chars
+ Trim* for widestrings

git-svn-id: trunk@618 -

florian 20 жил өмнө
parent
commit
6ed53e2c70

+ 1 - 1
rtl/objpas/sysutils/sysstr.inc

@@ -486,7 +486,7 @@ function AnsiStrUpper(Str: PChar): PChar;{$ifdef SYSUTILSINLINE}inline;{$endif}
 
 {   Trim returns a copy of S with blanks characters on the left and right stripped off   }
 
-Const WhiteSpace = [' ',#10,#13,#9];
+Const WhiteSpace = [#0..' '];
 
 function Trim(const S: string): string;
 var Ofs, Len: integer;

+ 38 - 0
rtl/objpas/sysutils/syswide.inc

@@ -18,6 +18,44 @@
     *********************************************************************
 }
 
+function Trim(const S: widestring): widestring;
+	var 
+	  Ofs, Len: sizeint;
+	begin
+	  len := Length(S);
+	  while (Len>0) and (S[Len]<=' ') do
+	   dec(Len);
+	  Ofs := 1;
+	  while (Ofs<=Len) and (S[Ofs]<=' ') do
+	   Inc(Ofs);
+	  result := Copy(S, Ofs, 1 + Len - Ofs);
+	end;
+	
+
+{   TrimLeft returns a copy of S with all blank characters on the left stripped off  }
+function TrimLeft(const S: widestring): widestring;
+	var 
+	  i,l:sizeint;
+	begin
+	  l := length(s);
+	  i := 1;
+	  while (i<=l) and (s[i]<=' ') do
+	   inc(i);
+	  Result := copy(s, i, l);
+	end;
+	
+
+{   TrimRight returns a copy of S with all blank characters on the right stripped off  }
+function TrimRight(const S: widestring): widestring;
+	var 
+		l:sizeint;
+	begin
+	  l := length(s);
+	  while (l>0) and (s[l]<=' ') do
+	   dec(l);
+	  result := copy(s,1,l);
+	end;
+
 
 function WideUpperCase(const s : WideString) : WideString;{$ifdef SYSUTILSINLINE}inline;{$endif}
   begin

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

@@ -18,6 +18,10 @@
     *********************************************************************
 }
 
+function Trim(const S: widestring): widestring;
+function TrimLeft(const S: widestring): widestring;
+function TrimRight(const S: widestring): widestring;
+
 function WideUpperCase(const s : WideString) : WideString;{$ifdef SYSUTILSINLINE}inline;{$endif}
 function WideLowerCase(const s : WideString) : WideString;{$ifdef SYSUTILSINLINE}inline;{$endif}
 function WideCompareStr(const s1, s2 : WideString) : PtrInt;{$ifdef SYSUTILSINLINE}inline;{$endif}
@@ -30,5 +34,3 @@ Function WideFormatBuf (Var Buffer; BufLen : Cardinal;
                      Const Fmt; fmtLen : Cardinal;
                      Const Args : Array of const) : Cardinal;
 Procedure WideFmtStr(Var Res: WideString; Const Fmt : WideString; Const args: Array of const);
-
-