textmgr.pp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. {$MACRO ON}
  2. (******************************************************************************
  3. *
  4. * Copyright (c) 1998-2000 Palm, Inc. or its subsidiaries.
  5. * All rights reserved.
  6. *
  7. * File: TextMgr.h
  8. *
  9. * Release: Palm OS SDK 4.0 (63220)
  10. *
  11. * Description:
  12. * Header file for Text Manager.
  13. *
  14. * History:
  15. * 03/05/98 kwk Created by Ken Krugler.
  16. * 02/02/99 kwk Added charEncodingPalmLatin & charEncodingPalmSJIS,
  17. * since we've extended the CP1252 & CP932 encodings.
  18. * Added TxtUpperStr, TxtLowerStr, TxtUpperChar, and
  19. * TxtLowerChar macros.
  20. * 03/11/99 kwk Changed TxtTruncate to TxtGetTruncationOffset.
  21. * 04/24/99 kwk Moved string & character upper/lower casing macros
  22. * to IntlGlue library.
  23. * 04/28/99 kwk Changed kMaxCharSize to maxCharBytes, as per Roger's request.
  24. * 05/15/99 kwk Changed TxtIsValidChar to TxtCharIsValid.
  25. * 05/29/99 kwk Removed include of CharAttr.h.
  26. * 07/13/99 kwk Moved TxtPrepFindString into TextPrv.h
  27. * 09/22/99 kwk Added TxtParamString (OS 3.5).
  28. * 10/28/99 kwk Added the TxtCharIsVirtual macro.
  29. * 03/01/00 kwk Added the TxtConvertEncoding routine (OS 4.0), and the
  30. * txtErrUnknownEncoding and txtErrConvertOverflow errors.
  31. * 05/12/00 kwk Deprecated the TxtCharWidth routine.
  32. * 05/26/00 kwk Added TxtGetWordWrapOffset (OS 4.0). Convert CharEncodingType
  33. * to #define format versus enums. Re-ordered into logical
  34. * groups, and fixed up names to match existing convention.
  35. * 05/30/00 kwk Added txtErrTranslitUnderflow.
  36. * 06/02/00 CS Moved character encoding constants to PalmLocale.h so that
  37. * Rez has access to them.
  38. * 07/13/00 kwk Added TxtNameToEncoding (OS 4.0).
  39. * 07/23/00 kwk Updated TxtConvertEncoding to match new API.
  40. * 10/05/00 kwk Added charAttr_<whatever> as substitutes for the old
  41. * character attribute flags in CharAttr.h (e.g. _XA, _LO).
  42. * kwk Moved sizeOf7BitChar here from CharAttr.h
  43. * 11/21/00 kwk Undeprecated TxtCharWidth, in anticipation of future,
  44. * proper deprecation.
  45. * 11/24/00 kwk Reverted maxCharBytes to 3 (was 4). You only need more than
  46. * three bytes for surrogate Unicode characters, which we don't
  47. * support, as this would require a 32 bit WChar variable to
  48. * hold the result (potentially 21 bits of data). Since we
  49. * never use more than 3 bytes, it's OK to shrink this back down.
  50. *
  51. *****************************************************************************)
  52. unit textmgr;
  53. interface
  54. uses palmos, coretraps, errorbase, intlmgr;
  55. (***********************************************************************
  56. * Public types & constants
  57. ***********************************************************************)
  58. // See PalmLocale.h for encoding constants of type CharEncodingType, and
  59. // character encoding names.
  60. type
  61. CharEncodingType = UInt8;
  62. // Transliteration operations for the TxtTransliterate call. We don't use
  63. // an enum, since each character encoding contains its own set of special
  64. // transliteration operations (which begin at translitOpCustomBase).
  65. type
  66. TranslitOpType = UInt16;
  67. // Standard transliteration operations.
  68. const
  69. translitOpStandardBase = 0; // Beginning of standard operations.
  70. translitOpUpperCase = 0;
  71. translitOpLowerCase = 1;
  72. translitOpReserved2 = 2;
  73. translitOpReserved3 = 3;
  74. // Custom transliteration operations (defined in CharXXXX.h encoding-specific
  75. // header files.
  76. translitOpCustomBase = 1000; // Beginning of char-encoding specific ops.
  77. translitOpPreprocess = $8000; // Mask for pre-process option, where
  78. // no transliteration actually is done.
  79. // Structure used to maintain state across calls to TxtConvertEncoding, for
  80. // proper handling of source or destination encodings with have modes.
  81. kTxtConvertStateSize = 32;
  82. type
  83. TxtConvertStateType = record
  84. ioSrcState: array [0..kTxtConvertStateSize - 1] of UInt8;
  85. ioDstState: array [0..kTxtConvertStateSize - 1] of UInt8;
  86. end;
  87. // Flags available in the sysFtrNumCharEncodingFlags feature attribute.
  88. const
  89. charEncodingOnlySingleByte = $00000001;
  90. charEncodingHasDoubleByte = $00000002;
  91. charEncodingHasLigatures = $00000004;
  92. charEncodingLeftToRight = $00000008;
  93. // Various byte attribute flags. Note that multiple flags can be
  94. // set, thus a byte could be both a single-byte character, or the first
  95. // byte of a multi-byte character.
  96. byteAttrFirst = $80; // First byte of multi-byte char.
  97. byteAttrLast = $40; // Last byte of multi-byte char.
  98. byteAttrMiddle = $20; // Middle byte of muli-byte char.
  99. byteAttrSingle = $01; // Single byte.
  100. // Character attribute flags. These replace the old flags defined in
  101. // CharAttr.h, but are bit-compatible.
  102. charAttr_XA = $0200; // extra alphabetic
  103. charAttr_XS = $0100; // extra space
  104. charAttr_BB = $0080; // BEL, BS, etc.
  105. charAttr_CN = $0040; // CR, FF, HT, NL, VT
  106. charAttr_DI = $0020; // '0'-'9'
  107. charAttr_LO = $0010; // 'a'-'z' and lowercase extended chars.
  108. charAttr_PU = $0008; // punctuation
  109. charAttr_SP = $0004; // space
  110. charAttr_UP = $0002; // 'A'-'Z' and uppercase extended chars.
  111. charAttr_XD = $0001; // '0'-'9', 'A'-'F', 'a'-'f'
  112. // Various sets of character attribute flags.
  113. charAttrPrint = charAttr_DI or charAttr_LO or charAttr_PU or charAttr_SP or charAttr_UP or charAttr_XA;
  114. charAttrSpace = charAttr_CN or charAttr_SP or charAttr_XS;
  115. charAttrAlNum = charAttr_DI or charAttr_LO or charAttr_UP or charAttr_XA;
  116. charAttrAlpha = charAttr_LO or charAttr_UP or charAttr_XA;
  117. charAttrCntrl = charAttr_BB or charAttr_CN;
  118. charAttrGraph = charAttr_DI or charAttr_LO or charAttr_PU or charAttr_UP or charAttr_XA;
  119. charAttrDelim = charAttr_SP or charAttr_PU;
  120. // Remember that sizeof(0x0D) == 2 because 0x0D is treated like an int. The
  121. // same is true of sizeof('a'), sizeof('\0'), and sizeof(chrNull). For this
  122. // reason it's safest to use the sizeOf7BitChar macro to document buffer size
  123. // and string length calcs. Note that this can only be used with low-ascii
  124. // characters, as anything else might be the high byte of a double-byte char.
  125. //!!! sizeOf7BitChar(c) = 1;
  126. // Maximum size a single WChar character will occupy in a text string.
  127. maxCharBytes = 3;
  128. // Text manager error codes.
  129. txtErrUknownTranslitOp = txtErrorClass or 1;
  130. txtErrTranslitOverrun = txtErrorClass or 2;
  131. txtErrTranslitOverflow = txtErrorClass or 3;
  132. txtErrConvertOverflow = txtErrorClass or 4;
  133. txtErrConvertUnderflow = txtErrorClass or 5;
  134. txtErrUnknownEncoding = txtErrorClass or 6;
  135. txtErrNoCharMapping = txtErrorClass or 7;
  136. txtErrTranslitUnderflow = txtErrorClass or 8;
  137. (***********************************************************************
  138. * Public macros
  139. ***********************************************************************)
  140. function TxtCharIsSpace(ch: WChar): Boolean;
  141. function TxtCharIsPrint(ch: WChar): Boolean;
  142. function TxtCharIsDigit(ch: WChar): Boolean;
  143. function TxtCharIsAlNum(ch: WChar): Boolean;
  144. function TxtCharIsAlpha(ch: WChar): Boolean;
  145. function TxtCharIsCntrl(ch: WChar): Boolean;
  146. function TxtCharIsGraph(ch: WChar): Boolean;
  147. function TxtCharIsLower(ch: WChar): Boolean;
  148. function TxtCharIsPunct(ch: WChar): Boolean;
  149. function TxtCharIsUpper(ch: WChar): Boolean;
  150. function TxtCharIsHex(ch: WChar): Boolean;
  151. function TxtCharIsDelim(ch: WChar): Boolean;
  152. // <c> is a hard key if the event modifier <m> has the command bit set
  153. // and <c> is either in the proper range or is the calculator character.
  154. function TxtCharIsHardKey(m, c: UInt16): Boolean;
  155. // <c> is a virtual character if the event modifier <m> has the command
  156. // bit set. WARNING!!! This macro is only safe to use on Palm OS 3.5 or
  157. // later. With earlier versions of the OS, use TxtGlueCharIsVirtual()
  158. // in PalmOSGlue.lib
  159. function TxtCharIsVirtual(m, c: UInt16): Boolean;
  160. function TxtPreviousCharSize(const inText: PChar; inOffset: UInt32): UInt16;
  161. function TxtNextCharSize(const inText: PChar; inOffset: UInt32): UInt16;
  162. (***********************************************************************
  163. * Public routines
  164. ***********************************************************************)
  165. // DOLATER kwk - fix up parameter names to use i, o versus in, out
  166. // Return back byte attribute (first, last, single, middle) for <inByte>.
  167. function TxtByteAttr(inByte: UInt8): UInt8;
  168. // Return back the standard attribute bits for <inChar>.
  169. function TxtCharAttr(inChar: WChar): UInt16;
  170. // Return back the extended attribute bits for <inChar>.
  171. function TxtCharXAttr(inChar: WChar): UInt16;
  172. // Return the size (in bytes) of the character <inChar>. This represents
  173. // how many bytes would be required to store the character in a string.
  174. function TxtCharSize(inChar: WChar): UInt16;
  175. // Return the width (in pixels) of the character <inChar>. You should
  176. // use FntWCharWidth or FntGlueWCharWidth instead of this routine.
  177. function TxtCharWidth(inChar: WChar): Int16;
  178. // Load the character before offset <inOffset> in the <inText> text. Return
  179. // back the size of the character.
  180. function TxtGetPreviousChar(const inText: PChar; inOffset: UInt32; outChar: WCharPtr): UInt16;
  181. // Load the character at offset <inOffset> in the <inText> text. Return
  182. // back the size of the character.
  183. function TxtGetNextChar(const inText: PChar; inOffset: UInt32; outChar: WCharPtr): UInt16;
  184. // Return the character at offset <inOffset> in the <inText> text.
  185. function TxtGetChar(const inText: PChar; inOffset: UInt32): WChar;
  186. // Set the character at offset <inOffset> in the <inText> text, and
  187. // return back the size of the character.
  188. function TxtSetNextChar(ioText: PChar; inOffset: UInt32; inChar: WChar): UInt16;
  189. // Replace the substring "^X" (where X is 0..9, as specified by <inParamNum>)
  190. // with the string <inParamStr>. If <inParamStr> is NULL then don't modify <ioStr>.
  191. // Make sure the resulting string doesn't contain more than <inMaxLen> bytes,
  192. // excluding the terminating null. Return back the number of occurances of
  193. // the substring found in <ioStr>.
  194. function TxtReplaceStr(ioStr: PChar; inMaxLen: UInt16; const inParamStr: PChar; inParamNum: UInt16): UInt16;
  195. // Allocate a handle containing the result of substituting param0...param3
  196. // for ^0...^3 in <inTemplate>, and return the locked result. If a parameter
  197. // is NULL, replace the corresponding substring in the template with "".
  198. function TxtParamString(const inTemplate, param0, param1, param2, param3: PChar): PChar;
  199. // Return the bounds of the character at <inOffset> in the <inText>
  200. // text, via the <outStart> & <outEnd> offsets, and also return the
  201. // actual value of character at or following <inOffset>.
  202. function TxtCharBounds(const inText: PChar; inOffset: UInt32; var outStart: UInt32; var outEnd: UInt32): WChar;
  203. // Return the appropriate byte position for truncating <inText> such that it is
  204. // at most <inOffset> bytes long.
  205. function TxtGetTruncationOffset(const inText: PChar; inOffset: UInt32): UInt32;
  206. // Search for <inTargetStr> in <inSourceStr>. If found return true and pass back
  207. // the found position (byte offset) in <outPos>, and the length of the matched
  208. // text in <outLength>.
  209. function TxtFindString(const inSourceStr, inTargetStr: PChar;
  210. var outPos: UInt32; var outLength: UInt16): Boolean;
  211. // Find the bounds of the word that contains the character at <inOffset>.
  212. // Return the offsets in <*outStart> and <*outEnd>. Return true if the
  213. // word we found was not empty & not a delimiter (attribute of first char
  214. // in word not equal to space or punct).
  215. function TxtWordBounds(const inText: PChar; inLength, inOffset: UInt32;
  216. var outStart, outEnd: UInt32): Boolean;
  217. // Return the offset of the first break position (for text wrapping) that
  218. // occurs at or before <iOffset> in <iTextP>. Note that this routine will
  219. // also add trailing spaces and a trailing linefeed to the break position,
  220. // thus the result could be greater than <iOffset>.
  221. function TxtGetWordWrapOffset(const iTextP: PChar; iOffset: UInt32): UInt32;
  222. // Return the minimum (lowest) encoding required for <inChar>. If we
  223. // don't know about the character, return encoding_Unknown.
  224. function TxtCharEncoding(inChar: WChar): CharEncodingType;
  225. // Return the minimum (lowest) encoding required to represent <inStr>.
  226. // This is the maximum encoding of any character in the string, where
  227. // highest is unknown, and lowest is ascii.
  228. function TxtStrEncoding(const inStr: PChar): CharEncodingType;
  229. // Return the higher (max) encoding of <a> and <b>.
  230. function TxtMaxEncoding(a, b: CharEncodingType): CharEncodingType;
  231. // Return a pointer to the 'standard' name for <inEncoding>. If the
  232. // encoding is unknown, return a pointer to an empty string.
  233. function TxtEncodingName(inEncoding: CharEncodingType): PChar;
  234. // Map from a character set name <iEncodingName> to a CharEncodingType.
  235. // If the character set name is unknown, return charEncodingUnknown.
  236. function TxtNameToEncoding(const iEncodingName: PChar): CharEncodingType;
  237. // Transliterate <inSrcLength> bytes of text found in <inSrcText>, based
  238. // on the requested <inOp> operation. Place the results in <outDstText>,
  239. // and set the resulting length in <ioDstLength>. On entry <ioDstLength>
  240. // must contain the maximum size of the <outDstText> buffer. If the
  241. // buffer isn't large enough, return an error (note that outDestText
  242. // might have been modified during the operation). Note that if <inOp>
  243. // has the preprocess bit set, then <outDstText> is not modified, and
  244. // <ioDstLength> will contain the total space required in the destination
  245. // buffer in order to perform the operation.
  246. function TxtTransliterate(const inSrcText: PChar; inSrcLength: UInt16; outDstText: PChar;
  247. var ioDstLength: UInt16; inOp: TranslitOpType): Err;
  248. // Convert <*ioSrcBytes> of text from <srcTextP> between the <srcEncoding>
  249. // and <dstEncoding> character encodings. If <dstTextP> is not NULL, write
  250. // the resulting bytes to the buffer, and always return the number of
  251. // resulting bytes in <*ioDstBytes>. Update <*srcBytes> with the number of
  252. // bytes from the beginning of <*srcTextP> that were successfully converted.
  253. // When the routine is called with <srcTextP> pointing to the beginning of
  254. // a string or text buffer, <newConversion> should be true; if the text is
  255. // processed in multiple chunks, either because errors occurred or due to
  256. // source/destination buffer size constraints, then subsequent calls to
  257. // this routine should pass false for <newConversion>. The TxtConvertStateType
  258. // record maintains state information so that if the source or destination
  259. // character encodings have state or modes (e.g. JIS), processing a single
  260. // sequence of text with multiple calls will work correctly.
  261. // When an error occurs due to an unconvertable character, the behavior of
  262. // the routine will depend on the <substitutionStr> parameter. If it is NULL,
  263. // then <*ioSrcBytes> will be set to the offset of the unconvertable character,
  264. // <ioDstBytes> will be set to the number of successfully converted resulting
  265. // bytes, and <dstTextP>, in not NULL, will contain conversion results up to
  266. // the point of the error. The routine will return an appropriate error code,
  267. // and it is up to the caller to either terminate conversion or skip over the
  268. // unconvertable character and continue the conversion process (passing false
  269. // for the <newConversion> parameter in subsequent calls to TxtConvertEncoding).
  270. // If <substitutionStr> is not NULL, then this string is written to the
  271. // destination buffer when an unconvertable character is encountered in the
  272. // source text, and the source character is skipped. Processing continues, though
  273. // the error code will still be returned when the routine terminates. Note that
  274. // if a more serious error occurs during processing (e.g. buffer overflow) then
  275. // that error will be returned even if there was an earlier unconvertable character.
  276. // Note that the substitution string must use the destination character encoding.
  277. function TxtConvertEncoding(newConversion: Boolean; var ioStateP: TxtConvertStateType;
  278. const srcTextP: PChar; var ioSrcBytes: UInt16; srcEncoding: CharEncodingType;
  279. dstTextP: PChar; var ioDstBytes: UInt16; dstEncoding: CharEncodingType;
  280. const substitutionStr: PChar; substitutionLen: UInt16): Err;
  281. // Return true if <inChar> is a valid (drawable) character. Note that we'll
  282. // return false if it is a virtual character code.
  283. function TxtCharIsValid(inChar: WChar): Boolean;
  284. // Compare the first <s1Len> bytes of <s1> with the first <s2Len> bytes
  285. // of <s2>. Return the results of the comparison: < 0 if <s1> sorts before
  286. // <s2>, > 0 if <s1> sorts after <s2>, and 0 if they are equal. Also return
  287. // the number of bytes that matched in <s1MatchLen> and <s2MatchLen>
  288. // (either one of which can be NULL if the match length is not needed).
  289. // This comparison is "caseless", in the same manner as a find operation,
  290. // thus case, character size, etc. don't matter.
  291. function TxtCaselessCompare(const s1: PChar; s1Len: UInt16; var s1MatchLen: UInt16;
  292. const s2: PChar; s2Len: UInt16; var s2MatchLen: UInt16): Int16;
  293. // Compare the first <s1Len> bytes of <s1> with the first <s2Len> bytes
  294. // of <s2>. Return the results of the comparison: < 0 if <s1> sorts before
  295. // <s2>, > 0 if <s1> sorts after <s2>, and 0 if they are equal. Also return
  296. // the number of bytes that matched in <s1MatchLen> and <s2MatchLen>
  297. // (either one of which can be NULL if the match length is not needed).
  298. function TxtCompare(const s1: PChar; s1Len: UInt16; var s1MatchLen: UInt16;
  299. const s2: PChar; s2Len: UInt16; var s2MatchLen: UInt16): Int16;
  300. implementation
  301. uses Chars, SysEvent;
  302. function __TxtByteAttr(inByte: UInt8): UInt8; syscall sysTrapIntlDispatch;
  303. function __TxtCharAttr(inChar: WChar): UInt16; syscall sysTrapIntlDispatch;
  304. function __TxtCharXAttr(inChar: WChar): UInt16; syscall sysTrapIntlDispatch;
  305. function __TxtCharSize(inChar: WChar): UInt16; syscall sysTrapIntlDispatch;
  306. function __TxtCharWidth(inChar: WChar): Int16; syscall sysTrapIntlDispatch;
  307. function __TxtGetPreviousChar(const inText: PChar; inOffset: UInt32; outChar: WCharPtr): UInt16; syscall sysTrapIntlDispatch;
  308. function __TxtGetNextChar(const inText: PChar; inOffset: UInt32; outChar: WCharPtr): UInt16; syscall sysTrapIntlDispatch;
  309. function __TxtGetChar(const inText: PChar; inOffset: UInt32): WChar; syscall sysTrapIntlDispatch;
  310. function __TxtSetNextChar(ioText: PChar; inOffset: UInt32; inChar: WChar): UInt16; syscall sysTrapIntlDispatch;
  311. function __TxtReplaceStr(ioStr: PChar; inMaxLen: UInt16; const inParamStr: PChar; inParamNum: UInt16): UInt16; syscall sysTrapIntlDispatch;
  312. function __TxtParamString(const inTemplate, param0, param1, param2, param3: PChar): PChar; syscall sysTrapIntlDispatch;
  313. function __TxtCharBounds(const inText: PChar; inOffset: UInt32; var outStart: UInt32; var outEnd: UInt32): WChar; syscall sysTrapIntlDispatch;
  314. function __TxtGetTruncationOffset(const inText: PChar; inOffset: UInt32): UInt32; syscall sysTrapIntlDispatch;
  315. function __TxtFindString(const inSourceStr, inTargetStr: PChar;
  316. var outPos: UInt32; var outLength: UInt16): Boolean; syscall sysTrapIntlDispatch;
  317. function __TxtWordBounds(const inText: PChar; inLength, inOffset: UInt32;
  318. var outStart, outEnd: UInt32): Boolean; syscall sysTrapIntlDispatch;
  319. function __TxtGetWordWrapOffset(const iTextP: PChar; iOffset: UInt32): UInt32; syscall sysTrapIntlDispatch;
  320. function __TxtCharEncoding(inChar: WChar): CharEncodingType; syscall sysTrapIntlDispatch;
  321. function __TxtStrEncoding(const inStr: PChar): CharEncodingType; syscall sysTrapIntlDispatch;
  322. function __TxtMaxEncoding(a, b: CharEncodingType): CharEncodingType; syscall sysTrapIntlDispatch;
  323. function __TxtEncodingName(inEncoding: CharEncodingType): PChar; syscall sysTrapIntlDispatch;
  324. function __TxtNameToEncoding(const iEncodingName: PChar): CharEncodingType; syscall sysTrapIntlDispatch;
  325. function __TxtTransliterate(const inSrcText: PChar; inSrcLength: UInt16; outDstText: PChar;
  326. var ioDstLength: UInt16; inOp: TranslitOpType): Err; syscall sysTrapIntlDispatch;
  327. function __TxtConvertEncoding(newConversion: Boolean; var ioStateP: TxtConvertStateType;
  328. const srcTextP: PChar; var ioSrcBytes: UInt16; srcEncoding: CharEncodingType;
  329. dstTextP: PChar; var ioDstBytes: UInt16; dstEncoding: CharEncodingType;
  330. const substitutionStr: PChar; substitutionLen: UInt16): Err; syscall sysTrapIntlDispatch;
  331. function __TxtCharIsValid(inChar: WChar): Boolean; syscall sysTrapIntlDispatch;
  332. function __TxtCaselessCompare(const s1: PChar; s1Len: UInt16; var s1MatchLen: UInt16;
  333. const s2: PChar; s2Len: UInt16; var s2MatchLen: UInt16): Int16; syscall sysTrapIntlDispatch;
  334. function __TxtCompare(const s1: PChar; s1Len: UInt16; var s1MatchLen: UInt16;
  335. const s2: PChar; s2Len: UInt16; var s2MatchLen: UInt16): Int16; syscall sysTrapIntlDispatch;
  336. function TxtByteAttr(inByte: UInt8): UInt8;
  337. begin
  338. asm
  339. move.l #$intlTxtByteAttr, D2;
  340. end;
  341. TxtByteAttr := TxtByteAttr(inByte);
  342. end;
  343. function TxtCharAttr(inChar: WChar): UInt16;
  344. begin
  345. asm
  346. move.l #$intlTxtCharAttr, D2;
  347. end;
  348. TxtCharAttr := __TxtCharAttr(inChar);
  349. end;
  350. function TxtCharXAttr(inChar: WChar): UInt16;
  351. begin
  352. asm
  353. move.l #$intlTxtCharXAttr, D2;
  354. end;
  355. TxtCharXAttr := __TxtCharXAttr(inChar);
  356. end;
  357. function TxtCharSize(inChar: WChar): UInt16;
  358. begin
  359. asm
  360. move.l #$intlTxtCharSize, D2;
  361. end;
  362. TxtCharSize := TxtCharSize(inChar);
  363. end;
  364. function TxtCharWidth(inChar: WChar): Int16;
  365. begin
  366. asm
  367. move.l #$intlTxtCharWidth, D2;
  368. end;
  369. TxtCharWidth := TxtCharWidth(inChar);
  370. end;
  371. function TxtGetPreviousChar(const inText: PChar; inOffset: UInt32; outChar: WCharPtr): UInt16;
  372. begin
  373. asm
  374. move.l #$intlTxtGetPreviousChar, D2;
  375. end;
  376. TxtGetPreviousChar := __TxtGetPreviousChar(inText, inOffset, outChar);
  377. end;
  378. function TxtGetNextChar(const inText: PChar; inOffset: UInt32; outChar: WCharPtr): UInt16;
  379. begin
  380. asm
  381. move.l #$intlTxtGetNextChar, D2;
  382. end;
  383. TxtGetNextChar := __TxtGetNextChar(inText, inOffset, outChar);
  384. end;
  385. function TxtGetChar(const inText: PChar; inOffset: UInt32): WChar;
  386. begin
  387. asm
  388. move.l #$intlTxtGetChar, D2;
  389. end;
  390. TxtGetChar := __TxtGetChar(inText, inOffset);
  391. end;
  392. function TxtSetNextChar(ioText: PChar; inOffset: UInt32; inChar: WChar): UInt16;
  393. begin
  394. asm
  395. move.l #$intlTxtSetNextChar, D2;
  396. end;
  397. TxtSetNextChar := __TxtSetNextChar(ioText, inOffset, inChar);
  398. end;
  399. function TxtReplaceStr(ioStr: PChar; inMaxLen: UInt16; const inParamStr: PChar; inParamNum: UInt16): UInt16;
  400. begin
  401. asm
  402. move.l #$intlTxtReplaceStr, D2;
  403. end;
  404. TxtReplaceStr := __TxtReplaceStr(ioStr, inMaxLen, inParamStr, inParamNum);
  405. end;
  406. function TxtParamString(const inTemplate, param0, param1, param2, param3: PChar): PChar;
  407. begin
  408. asm
  409. move.l #$intlTxtParamString, D2;
  410. end;
  411. TxtParamString := __TxtParamString(inTemplate, param0, param1, param2, param3);
  412. end;
  413. function TxtCharBounds(const inText: PChar; inOffset: UInt32; var outStart: UInt32; var outEnd: UInt32): WChar;
  414. begin
  415. asm
  416. move.l #$intlTxtCharBounds, D2;
  417. end;
  418. TxtCharBounds := TxtCharBounds(inText, inOffset, outStart, outEnd);
  419. end;
  420. function TxtGetTruncationOffset(const inText: PChar; inOffset: UInt32): UInt32;
  421. begin
  422. asm
  423. move.l #$intlTxtGetTruncationOffset, D2;
  424. end;
  425. TxtGetTruncationOffset := __TxtGetTruncationOffset(inText, inOffset);
  426. end;
  427. function TxtFindString(const inSourceStr, inTargetStr: PChar;
  428. var outPos: UInt32; var outLength: UInt16): Boolean;
  429. begin
  430. asm
  431. move.l #$intlTxtFindString, D2;
  432. end;
  433. TxtFindString := TxtFindString(inSourceStr, inTargetStr, outPos, outLength);
  434. end;
  435. function TxtWordBounds(const inText: PChar; inLength, inOffset: UInt32;
  436. var outStart, outEnd: UInt32): Boolean;
  437. begin
  438. asm
  439. move.l #$intlTxtWordBounds, D2;
  440. end;
  441. TxtWordBounds := __TxtWordBounds(inText, inLength, inOffset, outStart, outEnd);
  442. end;
  443. function TxtGetWordWrapOffset(const iTextP: PChar; iOffset: UInt32): UInt32;
  444. begin
  445. asm
  446. move.l #$intlTxtGetWordWrapOffset, D2;
  447. end;
  448. TxtGetWordWrapOffset := __TxtGetWordWrapOffset(iTextP, iOffset);
  449. end;
  450. function TxtCharEncoding(inChar: WChar): CharEncodingType;
  451. begin
  452. asm
  453. move.l #$intlTxtCharEncoding, D2;
  454. end;
  455. TxtCharEncoding := __TxtCharEncoding(inChar);
  456. end;
  457. function TxtStrEncoding(const inStr: PChar): CharEncodingType;
  458. begin
  459. asm
  460. move.l #$intlTxtStrEncoding, D2;
  461. end;
  462. TxtStrEncoding := __TxtStrEncoding(inStr);
  463. end;
  464. function TxtMaxEncoding(a, b: CharEncodingType): CharEncodingType;
  465. begin
  466. asm
  467. move.l #$intlTxtMaxEncoding, D2;
  468. end;
  469. TxtMaxEncoding := __TxtMaxEncoding(a, b);
  470. end;
  471. function TxtEncodingName(inEncoding: CharEncodingType): PChar;
  472. begin
  473. asm
  474. move.l #$intlTxtEncodingName, D2;
  475. end;
  476. TxtEncodingName := __TxtEncodingName(inEncoding);
  477. end;
  478. function TxtNameToEncoding(const iEncodingName: PChar): CharEncodingType;
  479. begin
  480. asm
  481. move.l #$intlTxtNameToEncoding, D2;
  482. end;
  483. TxtNameToEncoding := __TxtNameToEncoding(iEncodingName);
  484. end;
  485. function TxtTransliterate(const inSrcText: PChar; inSrcLength: UInt16; outDstText: PChar;
  486. var ioDstLength: UInt16; inOp: TranslitOpType): Err;
  487. begin
  488. asm
  489. move.l #$intlTxtTransliterate, D2;
  490. end;
  491. TxtTransliterate := __TxtTransliterate(inSrcText, inSrcLength, outDstText, ioDstLength, inOp);
  492. end;
  493. function TxtConvertEncoding(newConversion: Boolean; var ioStateP: TxtConvertStateType;
  494. const srcTextP: PChar; var ioSrcBytes: UInt16; srcEncoding: CharEncodingType;
  495. dstTextP: PChar; var ioDstBytes: UInt16; dstEncoding: CharEncodingType;
  496. const substitutionStr: PChar; substitutionLen: UInt16): Err;
  497. begin
  498. asm
  499. move.l #$intlTxtConvertEncoding, D2;
  500. end;
  501. TxtConvertEncoding := __TxtConvertEncoding(newConversion, ioStateP, srcTextP, ioSrcBytes,
  502. srcEncoding, dstTextP, ioDstBytes, dstEncoding,
  503. substitutionStr, substitutionLen);
  504. end;
  505. function TxtCharIsValid(inChar: WChar): Boolean;
  506. begin
  507. asm
  508. move.l #$intlTxtCharIsValid, D2;
  509. end;
  510. TxtCharIsValid := __TxtCharIsValid(inChar);
  511. end;
  512. function TxtCaselessCompare(const s1: PChar; s1Len: UInt16; var s1MatchLen: UInt16;
  513. const s2: PChar; s2Len: UInt16; var s2MatchLen: UInt16): Int16;
  514. begin
  515. asm
  516. move.l #$intlTxtCaselessCompare, D2;
  517. end;
  518. TxtCaselessCompare := __TxtCaselessCompare(s1, s1Len, s1MatchLen, s2, s2Len, s2MatchLen);
  519. end;
  520. function TxtCompare(const s1: PChar; s1Len: UInt16; var s1MatchLen: UInt16;
  521. const s2: PChar; s2Len: UInt16; var s2MatchLen: UInt16): Int16;
  522. begin
  523. asm
  524. move.l #$intlTxtCompare, D2;
  525. end;
  526. TxtCompare := __TxtCompare(s1, s1Len, s1MatchLen, s2, s2Len, s2MatchLen);
  527. end;
  528. function TxtCharIsSpace(ch: WChar): Boolean;
  529. begin
  530. TxtCharIsSpace := (TxtCharAttr(ch) and charAttrSpace) <> 0;
  531. end;
  532. function TxtCharIsPrint(ch: WChar): Boolean;
  533. begin
  534. txtCharIsPrint := (TxtCharAttr(ch) and charAttrPrint) <> 0;
  535. end;
  536. function TxtCharIsDigit(ch: WChar): Boolean;
  537. begin
  538. TxtCharIsDigit := (TxtCharAttr(ch) and charAttr_DI) <> 0;
  539. end;
  540. function TxtCharIsAlNum(ch: WChar): Boolean;
  541. begin
  542. TxtCharIsAlNum := (TxtCharAttr(ch) and charAttrAlNum) <> 0;
  543. end;
  544. function TxtCharIsAlpha(ch: WChar): Boolean;
  545. begin
  546. TxtCharIsAlpha := (TxtCharAttr(ch) and charAttrAlpha) <> 0;
  547. end;
  548. function TxtCharIsCntrl(ch: WChar): Boolean;
  549. begin
  550. txtCharIsCntrl := (TxtCharAttr(ch) and charAttrCntrl) <> 0;
  551. end;
  552. function TxtCharIsGraph(ch: WChar): Boolean;
  553. begin
  554. TxtCharIsGraph := (TxtCharAttr(ch) and charAttrGraph) <> 0;
  555. end;
  556. function TxtCharIsLower(ch: WChar): Boolean;
  557. begin
  558. TxtCharIsLower := (TxtCharAttr(ch) and charAttr_LO) <> 0;
  559. end;
  560. function TxtCharIsPunct(ch: WChar): Boolean;
  561. begin
  562. TxtCharIsPunct := (TxtCharAttr(ch) and charAttr_PU) <> 0;
  563. end;
  564. function TxtCharIsUpper(ch: WChar): Boolean;
  565. begin
  566. TxtCharIsUpper := (TxtCharAttr(ch) and charAttr_UP) <> 0;
  567. end;
  568. function TxtCharIsHex(ch: WChar): Boolean;
  569. begin
  570. TxtCharIsHex := (TxtCharAttr(ch) and charAttr_XD) <> 0;
  571. end;
  572. function TxtCharIsDelim(ch: WChar): Boolean;
  573. begin
  574. TxtCharIsDelim := (TxtCharAttr(ch) and charAttrDelim) <> 0;
  575. end;
  576. function TxtCharIsHardKey(m, c: UInt16): Boolean;
  577. begin
  578. TxtCharIsHardKey := ((m and commandKeyMask) <> 0) and ((c >= hardKeyMin) and ((c <= hardKeyMax) or (c = calcChr)));
  579. end;
  580. function TxtCharIsVirtual(m, c: UInt16): Boolean;
  581. begin
  582. TxtCharIsVirtual := (m and commandKeyMask) <> 0;
  583. end;
  584. function TxtPreviousCharSize(const inText: PChar; inOffset: UInt32): UInt16;
  585. begin
  586. TxtPreviousCharSize := TxtGetPreviousChar(inText, inOffset, nil);
  587. end;
  588. function TxtNextCharSize(const inText: PChar; inOffset: UInt32): UInt16;
  589. begin
  590. TxtNextCharSize := TxtGetNextChar(inText, inOffset, nil);
  591. end;
  592. end.