wstringh.inc 5.4 KB

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