justringh.inc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2011 by Jonas Maebe,
  4. member of the Free Pascal development team.
  5. This file implements support routines for UnicodeStrings 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. {$define FPC_HAS_BUILTIN_WIDESTR_MANAGER}
  13. Type
  14. TCollatorThreadVar = class(JLThreadLocal)
  15. protected
  16. function initialValue: JLObject; override;
  17. end;
  18. TCharsetDecoderThreadvar = class(JLThreadLocal)
  19. protected
  20. function initialValue: JLObject; override;
  21. public
  22. function getForCodePage(cp: TSystemCodePage): JNCCharsetDecoder;
  23. end;
  24. TCharsetEncoderThreadvar = class(JLThreadLocal)
  25. protected
  26. function initialValue: JLObject; override;
  27. public
  28. function getForCodePage(cp: TSystemCodePage): JNCCharsetEncoder;
  29. end;
  30. { hooks for internationalization
  31. please add new procedures at the end, it makes it easier to detect new procedures }
  32. TUnicodeStringManager = class(JLObject)
  33. class var
  34. collator: TCollatorThreadVar;
  35. decoder: TCharsetDecoderThreadvar;
  36. encoder: TCharsetEncoderThreadvar;
  37. class constructor ClassCreate;
  38. procedure Wide2AnsiMoveProc(source:pwidechar;var dest:RawByteString;cp : TSystemCodePage;len:SizeInt); virtual;
  39. procedure Ansi2WideMoveProc(source:pchar;cp : TSystemCodePage;var dest:widestring;len:SizeInt); virtual;
  40. function UpperWideStringProc(const S: WideString): WideString; virtual;
  41. function LowerWideStringProc(const S: WideString): WideString; virtual;
  42. function CompareWideStringProc(const s1, s2 : WideString) : PtrInt; virtual;
  43. function CompareTextWideStringProc(const s1, s2 : WideString): PtrInt; virtual;
  44. { return value: number of code points in the string. Whenever an invalid
  45. code point is encountered, all characters part of this invalid code point
  46. are considered to form one "character" and the next character is
  47. considered to be the start of a new (possibly also invalid) code point
  48. Note: different signature compared to version in native targets: extra
  49. "Index" parameter, since you cannot increment pchars to point to the
  50. next character here }
  51. function CharLengthPCharProc(const Str: PChar; Index: PtrInt): PtrInt; virtual;
  52. { return value:
  53. -1 if incomplete or invalid code point
  54. 0 if NULL character,
  55. > 0 if that's the length in bytes of the code point
  56. Note: different signature compared to version in native targets: extra
  57. "Index" parameter, since you cannot increment pchars to point to the
  58. next character here }
  59. function CodePointLengthProc(const Str: PChar; Index, MaxLookAhead: PtrInt): Ptrint; virtual;
  60. function UpperAnsiStringProc(const s : ansistring) : ansistring; virtual;
  61. function LowerAnsiStringProc(const s : ansistring) : ansistring; virtual;
  62. function CompareStrAnsiStringProc(const S1, S2: ansistring): PtrInt; virtual;
  63. function CompareTextAnsiStringProc(const S1, S2: ansistring): PtrInt; virtual;
  64. function StrCompAnsiStringProc(S1, S2: PChar): PtrInt; virtual;
  65. function StrICompAnsiStringProc(S1, S2: PChar): PtrInt; virtual;
  66. function StrLCompAnsiStringProc(S1, S2: PChar; MaxLen: PtrUInt): PtrInt; virtual;
  67. function StrLICompAnsiStringProc(S1, S2: PChar; MaxLen: PtrUInt): PtrInt; virtual;
  68. function StrLowerAnsiStringProc(Str: PChar): PChar; virtual;
  69. function StrUpperAnsiStringProc(Str: PChar): PChar; virtual;
  70. // not possible to automatically run code when new thread is started in the
  71. // JVM -- and not needed either, because threadvars can do so when first
  72. // accessed from a thread
  73. // ThreadInitProc : procedure;
  74. // ThreadFiniProc : procedure;
  75. { this is only different on windows }
  76. procedure Unicode2AnsiMoveProc(source:punicodechar;var dest:RawByteString;cp : TSystemCodePage;len:SizeInt); virtual;
  77. procedure Ansi2UnicodeMoveProc(source:pchar;cp : TSystemCodePage;var dest:unicodestring;len:SizeInt); virtual;
  78. function UpperUnicodeStringProc(const S: UnicodeString): UnicodeString; virtual;
  79. function LowerUnicodeStringProc(const S: UnicodeString): UnicodeString; virtual;
  80. function CompareUnicodeStringProc(const s1, s2 : UnicodeString) : PtrInt; virtual;
  81. function CompareTextUnicodeStringProc(const s1, s2 : UnicodeString): PtrInt; virtual;
  82. end;