wstringh.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. Type
  38. TWideStringManager = record
  39. Wide2AnsiMoveProc : procedure(source:pwidechar;dest:pchar;len:SizeInt);
  40. Ansi2WideMoveProc : procedure(source:pchar;dest:pwidechar;len:SizeInt);
  41. // UpperUTF8 : procedure(p:PUTF8String);
  42. UpperWideStringProc : function(const S: WideString): WideString;
  43. // UpperUCS4 : procedure(p:PUCS4Char);
  44. // LowerUTF8 : procedure(p:PUTF8String);
  45. LowerWideStringProc : function(const S: WideString): WideString;
  46. // LowerUCS4 : procedure(p:PUCS4Char);
  47. {
  48. CompUTF8 : function(p1,p2:PUTF8String) : shortint;
  49. CompUCS2 : function(p1,p2:PUCS2Char) : shortint;
  50. CompUCS4 : function(p1,p2:PUC42Char) : shortint;
  51. }
  52. CompareWideStringProc : function(const s1, s2 : WideString) : PtrInt;
  53. CompareTextWideStringProc : function(const s1, s2 : WideString): PtrInt;
  54. CharLengthPCharProc : function(const Str: PChar): PtrInt;
  55. end;
  56. function UnicodeToUtf8(Dest: PChar; Source: PWideChar; MaxBytes: SizeInt): SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
  57. function UnicodeToUtf8(Dest: PChar; MaxDestBytes: SizeUInt; Source: PWideChar; SourceChars: SizeUInt): SizeUInt;
  58. function Utf8ToUnicode(Dest: PWideChar; Source: PChar; MaxChars: SizeInt): SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
  59. function Utf8ToUnicode(Dest: PWideChar; MaxDestChars: SizeUInt; Source: PChar; SourceBytes: SizeUInt): SizeUInt;
  60. function UTF8Encode(const s : WideString) : UTF8String;
  61. function UTF8Decode(const s : UTF8String): WideString;
  62. function AnsiToUtf8(const s : ansistring): UTF8String;{$ifdef SYSTEMINLINE}inline;{$endif}
  63. function Utf8ToAnsi(const s : UTF8String) : ansistring;{$ifdef SYSTEMINLINE}inline;{$endif}
  64. var
  65. widestringmanager : TWideStringManager;
  66. Procedure GetWideStringManager (Var Manager : TWideStringManager);
  67. Procedure SetWideStringManager (Const New : TWideStringManager);
  68. Procedure SetWideStringManager (Const New : TWideStringManager; Var Old: TWideStringManager);
  69. {
  70. $Log$
  71. Revision 1.5 2005-02-26 15:00:14 florian
  72. + WideSameStr
  73. Revision 1.4 2005/02/26 10:21:17 florian
  74. + implemented WideFormat
  75. + some Widestring stuff implemented
  76. * some Widestring stuff fixed
  77. Revision 1.3 2005/02/06 09:38:45 florian
  78. + StrCharLength infrastructure
  79. Revision 1.2 2005/02/03 18:40:50 florian
  80. + infrastructure for WideCompareText implemented
  81. Revision 1.1 2005/02/01 20:22:49 florian
  82. * improved widestring infrastructure manager
  83. }