wstringh.inc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2005 by Florian Klaempfl,
  5. member of the Free Pascal development team.
  6. This file implements support routines for WideStrings/Unicode with FPC
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {$ifndef INTERNSETLENGTH}
  14. Procedure SetLength (Var S : WideString; l : SizeInt);
  15. {$endif INTERNSETLENGTH}
  16. procedure UniqueString(Var S : WideString);external name 'FPC_WIDESTR_UNIQUE';
  17. {$ifndef INTERNLENGTH}
  18. Function Length (Const S : WideString) : SizeInt;
  19. {$endif INTERNLENGTH}
  20. {$ifndef InternCopy}
  21. Function Copy (Const S : WideString; Index,Size : SizeInt) : WideString;
  22. {$endif interncopy}
  23. Function Pos (Const Substr : WideString; Const Source : WideString) : SizeInt;
  24. Function Pos (c : Char; Const s : WideString) : SizeInt;
  25. Function Pos (c : WideChar; Const s : WideString) : SizeInt;
  26. Function Pos (c : WideChar; Const s : AnsiString) : SizeInt;
  27. Function UpCase(const s : WideString) : WideString;
  28. Procedure Insert (Const Source : WideString; Var S : WideString; Index : SizeInt);
  29. Procedure Delete (Var S : WideString; Index,Size: SizeInt);
  30. Procedure SetString (Var S : WideString; Buf : PWideChar; Len : SizeInt);
  31. Procedure SetString (Var S : WideString; Buf : PChar; Len : SizeInt);
  32. function WideCharToString(S : PWideChar) : AnsiString;
  33. function StringToWideChar(const Src : AnsiString;Dest : PWideChar;DestSize : SizeInt) : PWideChar;
  34. function WideCharLenToString(S : PWideChar;Len : SizeInt) : AnsiString;
  35. procedure WideCharLenToStrVar(Src : PWideChar;Len : SizeInt;var Dest : AnsiString);
  36. procedure WideCharToStrVar(S : PWideChar;var Dest : AnsiString);
  37. procedure DefaultWide2AnsiMove(source:pwidechar;var dest:ansistring;len:SizeInt);
  38. procedure DefaultAnsi2WideMove(source:pchar;var dest:widestring;len:SizeInt);
  39. Type
  40. TWideStringManager = record
  41. Wide2AnsiMoveProc : procedure(source:pwidechar;var dest:ansistring;len:SizeInt);
  42. Ansi2WideMoveProc : procedure(source:pchar;var dest:widestring;len:SizeInt);
  43. // UpperUTF8 : procedure(p:PUTF8String);
  44. UpperWideStringProc : function(const S: WideString): WideString;
  45. // UpperUCS4 : procedure(p:PUCS4Char);
  46. // LowerUTF8 : procedure(p:PUTF8String);
  47. LowerWideStringProc : function(const S: WideString): WideString;
  48. // LowerUCS4 : procedure(p:PUCS4Char);
  49. {
  50. CompUTF8 : function(p1,p2:PUTF8String) : shortint;
  51. CompUCS2 : function(p1,p2:PUCS2Char) : shortint;
  52. CompUCS4 : function(p1,p2:PUC42Char) : shortint;
  53. }
  54. CompareWideStringProc : function(const s1, s2 : WideString) : PtrInt;
  55. CompareTextWideStringProc : function(const s1, s2 : WideString): PtrInt;
  56. CharLengthPCharProc : function(const Str: PChar): PtrInt;
  57. UpperAnsiStringProc : function(const s : ansistring) : ansistring;
  58. LowerAnsiStringProc : function(const s : ansistring) : ansistring;
  59. CompareStrAnsiStringProc : function(const S1, S2: ansistring): PtrInt;
  60. CompareTextAnsiStringProc : function(const S1, S2: ansistring): PtrInt;
  61. StrCompAnsiStringProc : function(S1, S2: PChar): PtrInt;
  62. StrICompAnsiStringProc : function(S1, S2: PChar): PtrInt;
  63. StrLCompAnsiStringProc : function(S1, S2: PChar; MaxLen: PtrUInt): PtrInt;
  64. StrLICompAnsiStringProc : function(S1, S2: PChar; MaxLen: PtrUInt): PtrInt;
  65. StrLowerAnsiStringProc : function(Str: PChar): PChar;
  66. StrUpperAnsiStringProc : function(Str: PChar): PChar;
  67. end;
  68. function UnicodeToUtf8(Dest: PChar; Source: PWideChar; MaxBytes: SizeInt): SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
  69. function UnicodeToUtf8(Dest: PChar; MaxDestBytes: SizeUInt; Source: PWideChar; SourceChars: SizeUInt): SizeUInt;
  70. function Utf8ToUnicode(Dest: PWideChar; Source: PChar; MaxChars: SizeInt): SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
  71. function Utf8ToUnicode(Dest: PWideChar; MaxDestChars: SizeUInt; Source: PChar; SourceBytes: SizeUInt): SizeUInt;
  72. function UTF8Encode(const s : WideString) : UTF8String;
  73. function UTF8Decode(const s : UTF8String): WideString;
  74. function AnsiToUtf8(const s : ansistring): UTF8String;{$ifdef SYSTEMINLINE}inline;{$endif}
  75. function Utf8ToAnsi(const s : UTF8String) : ansistring;{$ifdef SYSTEMINLINE}inline;{$endif}
  76. var
  77. widestringmanager : TWideStringManager;
  78. Procedure GetWideStringManager (Var Manager : TWideStringManager);
  79. Procedure SetWideStringManager (Const New : TWideStringManager);
  80. Procedure SetWideStringManager (Const New : TWideStringManager; Var Old: TWideStringManager);
  81. {
  82. $Log$
  83. Revision 1.7 2005-03-14 21:09:04 florian
  84. * widestring manager can handle now ansi<->wide string conversions even if the lens don't match
  85. Revision 1.6 2005/03/12 14:56:22 florian
  86. + added Ansi* routines to widestring manager
  87. * made them using OS calls on windows
  88. Revision 1.5 2005/02/26 15:00:14 florian
  89. + WideSameStr
  90. Revision 1.4 2005/02/26 10:21:17 florian
  91. + implemented WideFormat
  92. + some Widestring stuff implemented
  93. * some Widestring stuff fixed
  94. Revision 1.3 2005/02/06 09:38:45 florian
  95. + StrCharLength infrastructure
  96. Revision 1.2 2005/02/03 18:40:50 florian
  97. + infrastructure for WideCompareText implemented
  98. Revision 1.1 2005/02/01 20:22:49 florian
  99. * improved widestring infrastructure manager
  100. }