wstringh.inc 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. Procedure Insert (Const Source : WideString; Var S : WideString; Index : SizeInt);
  27. Procedure Delete (Var S : WideString; Index,Size: SizeInt);
  28. Procedure SetString (Var S : WideString; Buf : PWideChar; Len : SizeInt);
  29. Procedure SetString (Var S : WideString; Buf : PChar; Len : SizeInt);
  30. function WideCharToString(S : PWideChar) : AnsiString;
  31. function StringToWideChar(const Src : AnsiString;Dest : PWideChar;DestSize : SizeInt) : PWideChar;
  32. function WideCharLenToString(S : PWideChar;Len : SizeInt) : AnsiString;
  33. procedure WideCharLenToStrVar(Src : PWideChar;Len : SizeInt;var Dest : AnsiString);
  34. procedure WideCharToStrVar(S : PWideChar;var Dest : AnsiString);
  35. Type
  36. TWideStringManager = record
  37. Wide2AnsiMoveProc : procedure(source:pwidechar;dest:pchar;len:SizeInt);
  38. Ansi2WideMoveProc : procedure(source:pchar;dest:pwidechar;len:SizeInt);
  39. // UpperUTF8 : procedure(p:PUTF8String);
  40. UpperWideStringProc : function(const S: WideString): WideString;
  41. // UpperUCS4 : procedure(p:PUCS4Char);
  42. // LowerUTF8 : procedure(p:PUTF8String);
  43. LowerWideStringProc : function(const S: WideString): WideString;
  44. // LowerUCS4 : procedure(p:PUCS4Char);
  45. {
  46. CompUTF8 : function(p1,p2:PUTF8String) : shortint;
  47. CompUCS2 : function(p1,p2:PUCS2Char) : shortint;
  48. CompUCS4 : function(p1,p2:PUC42Char) : shortint;
  49. }
  50. CompareWideStringProc : function(const s1, s2 : WideString) : PtrInt;
  51. SameWideStringProc : function(const s1, s2 : WideString) : Boolean;
  52. end;
  53. function UnicodeToUtf8(Dest: PChar; Source: PWideChar; MaxBytes: SizeInt): SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
  54. function UnicodeToUtf8(Dest: PChar; MaxDestBytes: SizeUInt; Source: PWideChar; SourceChars: SizeUInt): SizeUInt;
  55. function Utf8ToUnicode(Dest: PWideChar; Source: PChar; MaxChars: SizeInt): SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
  56. function Utf8ToUnicode(Dest: PWideChar; MaxDestChars: SizeUInt; Source: PChar; SourceBytes: SizeUInt): SizeUInt;
  57. function UTF8Encode(const s : WideString) : UTF8String;
  58. function UTF8Decode(const s : UTF8String): WideString;
  59. function AnsiToUtf8(const s : ansistring): UTF8String;{$ifdef SYSTEMINLINE}inline;{$endif}
  60. function Utf8ToAnsi(const s : UTF8String) : ansistring;{$ifdef SYSTEMINLINE}inline;{$endif}
  61. var
  62. widestringmanager : TWideStringManager;
  63. Procedure GetWideStringManager (Var Manager : TWideStringManager);
  64. Procedure SetWideStringManager (Const New : TWideStringManager);
  65. Procedure SetWideStringManager (Const New : TWideStringManager; Var Old: TWideStringManager);
  66. {
  67. $Log$
  68. Revision 1.1 2005-02-01 20:22:49 florian
  69. * improved widestring infrastructure manager
  70. }