sstringh.inc 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 Shortstrings with FPC/JVM
  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. type
  13. TAnsiCharArray = array of ansichar;
  14. ShortstringClass = class sealed (JLObject,JLCloneable)
  15. public
  16. { "length byte" }
  17. curlen: byte;
  18. { length is always the maximum length of the string (so that even reads
  19. past the current length of the shortstring work, just like in regular
  20. shortstrings }
  21. fdata: TAnsiCharArray;
  22. public
  23. constructor Create(const arr: array of ansichar; maxlen: byte);overload;
  24. constructor Create(const arr: array of unicodechar; maxlen: byte);overload;
  25. constructor Create(const u: unicodestring; maxlen: byte);overload;
  26. constructor Create(const a: ansistring; maxlen: byte);overload;
  27. constructor Create(const s: shortstring; maxlen: byte);overload;
  28. constructor Create(ch: ansichar; maxlen: byte);overload;
  29. constructor Create(ch: unicodechar; maxlen: byte);overload;
  30. class function CreateEmpty(maxlen: byte): ShortstringClass; static;
  31. class function CreateFromLiteralStringBytes(const u: unicodestring): shortstring; static;
  32. procedure FpcDeepCopy(dest: ShortstringClass);
  33. procedure setChar(index: jint; char: ansichar);
  34. function charAt(index: jint): ansichar;
  35. function toUnicodeString: unicodestring;
  36. function toAnsistring: ansistring;
  37. function toString: JLString; override;
  38. function clone: JLObject; override;
  39. // function concat(const a: shortstring): shortstring;
  40. // function concatmultiple(const arr: array of shortstring): shortstring;
  41. function length: jint;
  42. end;
  43. AnsiCharArrayClass = class sealed (JLObject)
  44. class function CreateFromLiteralStringBytes(const u: unicodestring; maxlen: byte): TAnsiCharArray; static;
  45. end;
  46. //Function Pos (Const Substr : Ansistring; Const Source : Ansistring) : SizeInt;
  47. //Function Pos (c : AnsiChar; Const s : Ansistring) : SizeInt;
  48. //Function Pos (c : AnsiString; Const s : UnicodeString) : SizeInt;
  49. //Function Pos (c : UnicodeString; Const s : AnsiString) : SizeInt;
  50. //Function Pos (c : ShortString; Const s : UnicodeString) : SizeInt;
  51. Function Pos (c : AnsiChar; Const s : Shortstring) : SizeInt;
  52. Function Pos (const substr : ShortString; Const source : Shortstring) : SizeInt;
  53. //Function Pos (c : char; Const s : UnicodeString) : SizeInt;
  54. Function UpCase(const s : shortstring) : shortstring;
  55. Function LowerCase(const s : shortstring) : shortstring;
  56. //Function UpCase(c:UnicodeChar):UnicodeChar;
  57. //Procedure Insert (Const Source : UnicodeString; Var S : UnicodeString; Index : SizeInt);
  58. //Procedure Delete (Var S : UnicodeString; Index,Size: SizeInt);
  59. //Procedure SetString (Out S : UnicodeString; Buf : PUnicodeChar; Len : SizeInt);
  60. //Procedure SetString (Out S : UnicodeString; Buf : PChar; Len : SizeInt);
  61. //
  62. //function WideCharToString(S : PWideChar) : AnsiString;
  63. //function StringToWideChar(const Src : AnsiString;Dest : PWideChar;DestSize : SizeInt) : PWideChar;
  64. //function WideCharLenToString(S : PWideChar;Len : SizeInt) : AnsiString;
  65. //procedure WideCharLenToStrVar(Src : PWideChar;Len : SizeInt;out Dest : AnsiString);
  66. //procedure WideCharToStrVar(S : PWideChar;out Dest : AnsiString);
  67. //
  68. //function UnicodeCharToString(S : PUnicodeChar) : AnsiString;
  69. //function StringToUnicodeChar(const Src : AnsiString;Dest : PUnicodeChar;DestSize : SizeInt) : PUnicodeChar;
  70. //function UnicodeCharLenToString(S : PUnicodeChar;Len : SizeInt) : AnsiString;
  71. //procedure UnicodeCharLenToStrVar(Src : PUnicodeChar;Len : SizeInt;out Dest : AnsiString);
  72. //procedure UnicodeCharToStrVar(S : PUnicodeChar;out Dest : AnsiString);
  73. //
  74. //procedure DefaultUnicode2AnsiMove(source:punicodechar;var dest:ansistring;len:SizeInt);
  75. //procedure DefaultAnsi2UnicodeMove(source:pchar;var dest:unicodestring;len:SizeInt);
  76. //function UnicodeToUtf8(Dest: PChar; Source: PUnicodeChar; MaxBytes: SizeInt): SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
  77. //function UnicodeToUtf8(Dest: PChar; MaxDestBytes: SizeUInt; Source: PUnicodeChar; SourceChars: SizeUInt): SizeUInt;
  78. //function Utf8ToUnicode(Dest: PUnicodeChar; Source: PChar; MaxChars: SizeInt): SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
  79. //function Utf8ToUnicode(Dest: PUnicodeChar; MaxDestChars: SizeUInt; Source: PChar; SourceBytes: SizeUInt): SizeUInt;
  80. //function UTF8Encode(const s : Ansistring) : UTF8String; inline;
  81. //function UTF8Encode(const s : UnicodeString) : UTF8String;
  82. //function UTF8Decode(const s : UTF8String): UnicodeString;
  83. //function AnsiToUtf8(const s : ansistring): UTF8String;{$ifdef SYSTEMINLINE}inline;{$endif}
  84. //function Utf8ToAnsi(const s : UTF8String) : ansistring;{$ifdef SYSTEMINLINE}inline;{$endif}
  85. //function UnicodeStringToUCS4String(const s : UnicodeString) : UCS4String;
  86. //function UCS4StringToUnicodeString(const s : UCS4String) : UnicodeString;
  87. //function WideStringToUCS4String(const s : WideString) : UCS4String;
  88. //function UCS4StringToWideString(const s : UCS4String) : WideString;
  89. //Procedure GetWideStringManager (Var Manager : TUnicodeStringManager);
  90. //Procedure SetWideStringManager (Const New : TUnicodeStringManager);
  91. //Procedure SetWideStringManager (Const New : TUnicodeStringManager; Var Old: TUnicodeStringManager);
  92. //Procedure GetUnicodeStringManager (Var Manager : TUnicodeStringManager);
  93. //Procedure SetUnicodeStringManager (Const New : TUnicodeStringManager);
  94. //Procedure SetUnicodeStringManager (Const New : TUnicodeStringManager; Var Old: TUnicodeStringManager);