From 6ed53e2c704e04a1e698938e1190c957006bebc6 Mon Sep 17 00:00:00 2001 From: florian Date: Wed, 13 Jul 2005 08:32:41 +0000 Subject: [PATCH] * Trim removes now all spaces and controll chars + Trim* for widestrings git-svn-id: trunk@618 - --- rtl/objpas/sysutils/sysstr.inc | 2 +- rtl/objpas/sysutils/syswide.inc | 38 ++++++++++++++++++++++++++++++++ rtl/objpas/sysutils/syswideh.inc | 6 +++-- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/rtl/objpas/sysutils/sysstr.inc b/rtl/objpas/sysutils/sysstr.inc index 04a910c0de..cff844674f 100644 --- a/rtl/objpas/sysutils/sysstr.inc +++ b/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; diff --git a/rtl/objpas/sysutils/syswide.inc b/rtl/objpas/sysutils/syswide.inc index aca6f4a950..fb258b5082 100644 --- a/rtl/objpas/sysutils/syswide.inc +++ b/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 diff --git a/rtl/objpas/sysutils/syswideh.inc b/rtl/objpas/sysutils/syswideh.inc index 2fedd1bcb3..6c9e8c7ab9 100644 --- a/rtl/objpas/sysutils/syswideh.inc +++ b/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); - -