sysuni.inc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. {
  2. *********************************************************************
  3. Copyright (C) 2002-2005 by Florian Klaempfl
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. *********************************************************************
  16. }
  17. function Trim(const S: unicodestring): unicodestring;
  18. var
  19. Ofs, Len: sizeint;
  20. begin
  21. len := Length(S);
  22. while (Len>0) and (S[Len]<=' ') do
  23. dec(Len);
  24. Ofs := 1;
  25. while (Ofs<=Len) and (S[Ofs]<=' ') do
  26. Inc(Ofs);
  27. result := Copy(S, Ofs, 1 + Len - Ofs);
  28. end;
  29. { TrimLeft returns a copy of S with all blank characters on the left stripped off }
  30. function TrimLeft(const S: unicodestring): unicodestring;
  31. var
  32. i,l:sizeint;
  33. begin
  34. l := length(s);
  35. i := 1;
  36. while (i<=l) and (s[i]<=' ') do
  37. inc(i);
  38. Result := copy(s, i, l);
  39. end;
  40. { TrimRight returns a copy of S with all blank characters on the right stripped off }
  41. function TrimRight(const S: unicodestring): unicodestring;
  42. var
  43. l:sizeint;
  44. begin
  45. l := length(s);
  46. while (l>0) and (s[l]<=' ') do
  47. dec(l);
  48. result := copy(s,1,l);
  49. end;
  50. function UnicodeUpperCase(const s : UnicodeString) : UnicodeString;{$ifdef SYSUTILSINLINE}inline;{$endif}
  51. begin
  52. result:=widestringmanager.UpperUnicodeStringProc(s);
  53. end;
  54. function UnicodeLowerCase(const s : UnicodeString) : UnicodeString;{$ifdef SYSUTILSINLINE}inline;{$endif}
  55. begin
  56. result:=widestringmanager.LowerUnicodeStringProc(s);
  57. end;
  58. function UnicodeCompareStr(const s1, s2 : UnicodeString) : PtrInt;{$ifdef SYSUTILSINLINE}inline;{$endif}
  59. begin
  60. result:=widestringmanager.CompareUnicodeStringProc(s1,s2);
  61. end;
  62. function UnicodeSameStr(const s1, s2 : UnicodeString) : Boolean;{$ifdef SYSUTILSINLINE}inline;{$endif}
  63. begin
  64. result:=widestringmanager.CompareUnicodeStringProc(s1,s2)=0;
  65. end;
  66. function UnicodeCompareText(const s1, s2 : UnicodeString) : PtrInt;{$ifdef SYSUTILSINLINE}inline;{$endif}
  67. begin
  68. result:=widestringmanager.CompareTextUnicodeStringProc(s1,s2);
  69. end;
  70. function UnicodeSameText(const s1, s2 : UnicodeString) : Boolean;{$ifdef SYSUTILSINLINE}inline;{$endif}
  71. begin
  72. result:=widestringmanager.CompareTextUnicodeStringProc(s1,s2)=0;
  73. end;
  74. { we've no templates, but with includes we can simulate this :) }
  75. {$macro on}
  76. {$define INWIDEFORMAT}
  77. {$define TFormatString:=unicodestring}
  78. {$define TFormatChar:=unicodechar}
  79. Function UnicodeFormat (Const Fmt : UnicodeString; const Args : Array of const; Const FormatSettings: TFormatSettings) : UnicodeString;
  80. {$i sysformt.inc}
  81. {$undef TFormatString}
  82. {$undef TFormatChar}
  83. {$undef INWIDEFORMAT}
  84. {$macro off}
  85. Function UnicodeFormat (Const Fmt : UnicodeString; const Args : Array of const) : UnicodeString;
  86. begin
  87. Result:=UnicodeFormat(Fmt,Args,DefaultFormatSettings);
  88. end;
  89. Function UnicodeFormatBuf (Var Buffer; BufLen : Cardinal;
  90. Const Fmt; fmtLen : Cardinal;
  91. Const Args : Array of const; Const FormatSettings: TFormatSettings) : Cardinal;
  92. Var
  93. S,F : UnicodeString;
  94. begin
  95. Setlength(F,fmtlen);
  96. if fmtlen > 0 then
  97. Move(fmt,F[1],fmtlen*sizeof(Unicodechar));
  98. S:=UnicodeFormat (F,Args);
  99. If Cardinal(Length(S))<Buflen then
  100. Result:=Length(S)
  101. else
  102. Result:=Buflen;
  103. Move(S[1],Buffer,Result);
  104. end;
  105. Function UnicodeFormatBuf (Var Buffer; BufLen : Cardinal;
  106. Const Fmt; fmtLen : Cardinal;
  107. Const Args : Array of const) : Cardinal;
  108. begin
  109. Result:=UnicodeFormatBuf(Buffer,BufLEn,Fmt,FmtLen,Args,DefaultFormatSettings);
  110. end;
  111. Procedure UnicodeFmtStr(Var Res: UnicodeString; Const Fmt : UnicodeString; Const args: Array of const; Const FormatSettings: TFormatSettings);
  112. begin
  113. Res:=UnicodeFormat(fmt,Args);
  114. end;
  115. Procedure UnicodeFmtStr(Var Res: UnicodeString; Const Fmt : UnicodeString; Const args: Array of const);
  116. begin
  117. UnicodeFmtStr(Res,Fmt,Args,DefaultFormatSettings);
  118. end;