syswide.inc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. {
  2. *********************************************************************
  3. Copyright (C) 2002-2005 by Florian Klaempfl
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. *********************************************************************
  10. }
  11. function Trim(const S: widestring): widestring;
  12. var
  13. Ofs, Len: sizeint;
  14. begin
  15. len := Length(S);
  16. while (Len>0) and (S[Len]<=' ') do
  17. dec(Len);
  18. Ofs := 1;
  19. while (Ofs<=Len) and (S[Ofs]<=' ') do
  20. Inc(Ofs);
  21. result := Copy(S, Ofs, 1 + Len - Ofs);
  22. end;
  23. { TrimLeft returns a copy of S with all blank characters on the left stripped off }
  24. function TrimLeft(const S: widestring): widestring;
  25. var
  26. i,l:sizeint;
  27. begin
  28. l := length(s);
  29. i := 1;
  30. while (i<=l) and (s[i]<=' ') do
  31. inc(i);
  32. Result := copy(s, i, l);
  33. end;
  34. { TrimRight returns a copy of S with all blank characters on the right stripped off }
  35. function TrimRight(const S: widestring): widestring;
  36. var
  37. l:sizeint;
  38. begin
  39. l := length(s);
  40. while (l>0) and (s[l]<=' ') do
  41. dec(l);
  42. result := copy(s,1,l);
  43. end;
  44. function WideUpperCase(const s : WideString) : WideString;{$ifdef SYSUTILSINLINE}inline;{$endif}
  45. begin
  46. result:=widestringmanager.UpperWideStringProc(s);
  47. end;
  48. function WideLowerCase(const s : WideString) : WideString;{$ifdef SYSUTILSINLINE}inline;{$endif}
  49. begin
  50. result:=widestringmanager.LowerWideStringProc(s);
  51. end;
  52. function WideCompareStr(const s1, s2 : WideString) : PtrInt;{$ifdef SYSUTILSINLINE}inline;{$endif}
  53. begin
  54. result:=widestringmanager.CompareWideStringProc(s1,s2,[]);
  55. end;
  56. function WideSameStr(const s1, s2 : WideString) : Boolean;{$ifdef SYSUTILSINLINE}inline;{$endif}
  57. begin
  58. result:=widestringmanager.CompareWideStringProc(s1,s2,[])=0;
  59. end;
  60. function WideCompareText(const s1, s2 : WideString) : PtrInt;{$ifdef SYSUTILSINLINE}inline;{$endif}
  61. begin
  62. result:=widestringmanager.CompareWideStringProc(s1,s2,[coIgnoreCase]);
  63. end;
  64. function WideSameText(const s1, s2 : WideString) : Boolean;{$ifdef SYSUTILSINLINE}inline;{$endif}
  65. begin
  66. result:=widestringmanager.CompareWideStringProc(s1,s2,[coIgnoreCase])=0;
  67. end;
  68. { we've no templates, but with includes we can simulate this :) }
  69. {$macro on}
  70. {$define INWIDEFORMAT}
  71. {$define TFormatString:=widestring}
  72. {$define TFormatChar:=widechar}
  73. Function WideFormat (Const Fmt : WideString; const Args : Array of const; Const FormatSettings: TFormatSettings) : WideString;
  74. {$i sysformt.inc}
  75. {$undef TFormatString}
  76. {$undef TFormatChar}
  77. {$undef INWIDEFORMAT}
  78. {$macro off}
  79. Function WideFormat (Const Fmt : WideString; const Args : Array of const) : WideString;
  80. begin
  81. Result:=WideFormat(Fmt,Args,DefaultFormatSettings);
  82. end;
  83. Function WideFormatBuf (Var Buffer; BufLen : Cardinal;
  84. Const Fmt; fmtLen : Cardinal;
  85. Const Args : Array of const; Const FormatSettings: TFormatSettings) : Cardinal;
  86. Var
  87. S,F : WideString;
  88. begin
  89. Setlength(F,fmtlen);
  90. if fmtlen > 0 then
  91. Move(fmt,F[1],fmtlen*sizeof(Widechar));
  92. S:=WideFormat (F,Args);
  93. If Cardinal(Length(S))<Buflen then
  94. Result:=Length(S)
  95. else
  96. Result:=Buflen;
  97. Move(S[1],Buffer,Result);
  98. end;
  99. Function WideFormatBuf (Var Buffer; BufLen : Cardinal;
  100. Const Fmt; fmtLen : Cardinal;
  101. Const Args : Array of const) : Cardinal;
  102. begin
  103. Result:=WideFormatBuf(Buffer,BufLEn,Fmt,FmtLen,Args,DefaultFormatSettings);
  104. end;
  105. Procedure WideFmtStr(Var Res: WideString; Const Fmt : WideString; Const args: Array of const; Const FormatSettings: TFormatSettings);
  106. begin
  107. Res:=WideFormat(fmt,Args);
  108. end;
  109. Procedure WideFmtStr(Var Res: WideString; Const Fmt : WideString; Const args: Array of const);
  110. begin
  111. WideFmtStr(Res,Fmt,Args,DefaultFormatSettings);
  112. end;
  113. function StrCopy(Dest, Source: PWideChar): PWideChar; overload;
  114. var
  115. counter : SizeInt;
  116. begin
  117. counter := 0;
  118. while Source[counter] <> #0 do
  119. begin
  120. Dest[counter] := widechar(Source[counter]);
  121. Inc(counter);
  122. end;
  123. { terminate the string }
  124. Dest[counter] := #0;
  125. StrCopy := Dest;
  126. end;
  127. function StrLCopy(Dest,Source: PWideChar; MaxLen: SizeInt): PWideChar; overload;
  128. var
  129. counter: SizeInt;
  130. begin
  131. counter := 0;
  132. while (Source[counter] <> #0) and (counter < MaxLen) do
  133. begin
  134. Dest[counter] := widechar(Source[counter]);
  135. Inc(counter);
  136. end;
  137. { terminate the string }
  138. Dest[counter] := #0;
  139. StrLCopy := Dest;
  140. end;
  141. Function CharInSet(Ch:WideChar;Const CSet : TSysCharSet) : Boolean;
  142. begin
  143. result:=(Ch<=#$FF) and (ansichar(byte(ch)) in CSet);
  144. end;
  145. {$macro on}
  146. {$define INWIDESTRINGREPLACE}
  147. {$define SRString:=WideString}
  148. {$define SRUpperCase:=WideUppercase}
  149. {$define SRPChar:=PWideChar}
  150. {$define SRChar:=WideChar}
  151. function WideStringReplace(const S, OldPattern, NewPattern: WideString; Flags: TReplaceFlags): WideString;
  152. {$i syssr.inc}
  153. {$undef INWIDESTRINGREPLACE}
  154. {$undef SRString}
  155. {$undef SRUpperCase}
  156. {$undef SRPChar}
  157. {$undef SRChar}