syswide.inc 5.4 KB

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