TextUtils.pas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. {
  2. File: TextUtils.p
  3. Contains: Text Utilities Interfaces.
  4. Version: Technology: Mac OS 8
  5. Release: Universal Interfaces 3.4.2
  6. Copyright: © 1985-2002 by Apple Computer, Inc., all rights reserved.
  7. Bugs?: For bug reports, consult the following page on
  8. the World Wide Web:
  9. http://www.freepascal.org/bugs.html
  10. }
  11. {
  12. Modified for use with Free Pascal
  13. Version 200
  14. Please report any bugs to <[email protected]>
  15. }
  16. {$mode macpas}
  17. {$packenum 1}
  18. {$macro on}
  19. {$inline on}
  20. {$CALLING MWPASCAL}
  21. unit TextUtils;
  22. interface
  23. {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
  24. {$setc GAP_INTERFACES_VERSION := $0200}
  25. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  26. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  27. {$endc}
  28. {$ifc defined CPUPOWERPC and defined CPUI386}
  29. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  30. {$endc}
  31. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  32. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  33. {$endc}
  34. {$ifc not defined __ppc__ and defined CPUPOWERPC}
  35. {$setc __ppc__ := 1}
  36. {$elsec}
  37. {$setc __ppc__ := 0}
  38. {$endc}
  39. {$ifc not defined __i386__ and defined CPUI386}
  40. {$setc __i386__ := 1}
  41. {$elsec}
  42. {$setc __i386__ := 0}
  43. {$endc}
  44. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  45. {$error Conflicting definitions for __ppc__ and __i386__}
  46. {$endc}
  47. {$ifc defined __ppc__ and __ppc__}
  48. {$setc TARGET_CPU_PPC := TRUE}
  49. {$setc TARGET_CPU_X86 := FALSE}
  50. {$elifc defined __i386__ and __i386__}
  51. {$setc TARGET_CPU_PPC := FALSE}
  52. {$setc TARGET_CPU_X86 := TRUE}
  53. {$elsec}
  54. {$error Neither __ppc__ nor __i386__ is defined.}
  55. {$endc}
  56. {$setc TARGET_CPU_PPC_64 := FALSE}
  57. {$ifc defined FPC_BIG_ENDIAN}
  58. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  59. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  60. {$elifc defined FPC_LITTLE_ENDIAN}
  61. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  62. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  63. {$elsec}
  64. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  65. {$endc}
  66. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  67. {$setc CALL_NOT_IN_CARBON := FALSE}
  68. {$setc OLDROUTINENAMES := FALSE}
  69. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  70. {$setc OPAQUE_UPP_TYPES := TRUE}
  71. {$setc OTCARBONAPPLICATION := TRUE}
  72. {$setc OTKERNEL := FALSE}
  73. {$setc PM_USE_SESSION_APIS := TRUE}
  74. {$setc TARGET_API_MAC_CARBON := TRUE}
  75. {$setc TARGET_API_MAC_OS8 := FALSE}
  76. {$setc TARGET_API_MAC_OSX := TRUE}
  77. {$setc TARGET_CARBON := TRUE}
  78. {$setc TARGET_CPU_68K := FALSE}
  79. {$setc TARGET_CPU_MIPS := FALSE}
  80. {$setc TARGET_CPU_SPARC := FALSE}
  81. {$setc TARGET_OS_MAC := TRUE}
  82. {$setc TARGET_OS_UNIX := FALSE}
  83. {$setc TARGET_OS_WIN32 := FALSE}
  84. {$setc TARGET_RT_MAC_68881 := FALSE}
  85. {$setc TARGET_RT_MAC_CFM := FALSE}
  86. {$setc TARGET_RT_MAC_MACHO := TRUE}
  87. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  88. {$setc TYPE_BOOL := FALSE}
  89. {$setc TYPE_EXTENDED := FALSE}
  90. {$setc TYPE_LONGLONG := TRUE}
  91. uses MacTypes,IntlResources,NumberFormatting,StringCompare,DateTimeUtils;
  92. {$ALIGN MAC68K}
  93. {
  94. Here are the current System 7 routine names and the translations to the older forms.
  95. Please use the newer forms in all new code and migrate the older names out of existing
  96. code as maintainance permits.
  97. NEW NAME OLD NAMEs OBSOLETE FORM (no script code)
  98. FindScriptRun
  99. FindWordBreaks NFindWord, FindWord
  100. GetIndString
  101. GetString
  102. Munger
  103. NewString
  104. SetString
  105. StyledLineBreak
  106. TruncString
  107. TruncText
  108. UpperString ($A054) UprString, UprText
  109. UppercaseText SCUpperText (a only) UpperText ($A456)
  110. LowercaseText LwrString, LowerText, LwrText ($A056)
  111. StripDiacritics StripText ($A256)
  112. UppercaseStripDiacritics StripUpperText ($A656)
  113. }
  114. { TruncCode, StyledLineBreakCode, and truncation constants moved to QuickDrawText.i }
  115. type
  116. ScriptRunStatusPtr = ^ScriptRunStatus;
  117. ScriptRunStatus = record
  118. script: SInt8;
  119. runVariant: SInt8;
  120. end;
  121. BreakTablePtr = ^BreakTable;
  122. BreakTable = record
  123. charTypes: packed array [0..255] of char;
  124. tripleLength: SInt16;
  125. triples: array [0..0] of SInt16;
  126. end;
  127. NBreakTablePtr = ^NBreakTable;
  128. NBreakTable = record
  129. flags1: SInt8;
  130. flags2: SInt8;
  131. version: SInt16;
  132. classTableOff: SInt16;
  133. auxCTableOff: SInt16;
  134. backwdTableOff: SInt16;
  135. forwdTableOff: SInt16;
  136. doBackup: SInt16;
  137. length: SInt16; { length of NBreakTable }
  138. charTypes: packed array [0..255] of char;
  139. tables: array [0..0] of SInt16;
  140. end;
  141. { The following functions are new names that work on 68k and PowerPC }
  142. {
  143. * Munger()
  144. *
  145. * Availability:
  146. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  147. * CarbonLib: in CarbonLib 1.0 and later
  148. * Mac OS X: in version 10.0 and later
  149. }
  150. function Munger(h: Handle; offset: SInt32; ptr1: UnivPtr; len1: SInt32; ptr2: UnivPtr; len2: SInt32): SInt32; external name '_Munger';
  151. {
  152. * NewString()
  153. *
  154. * Availability:
  155. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  156. * CarbonLib: in CarbonLib 1.0 and later
  157. * Mac OS X: in version 10.0 and later
  158. }
  159. function NewString(const (*var*) theString: Str255): StringHandle; external name '_NewString';
  160. {
  161. * SetString()
  162. *
  163. * Availability:
  164. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  165. * CarbonLib: in CarbonLib 1.0 and later
  166. * Mac OS X: in version 10.0 and later
  167. }
  168. procedure SetString(theString: StringHandle; const (*var*) strNew: Str255); external name '_SetString';
  169. {
  170. * GetString()
  171. *
  172. * Availability:
  173. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  174. * CarbonLib: in CarbonLib 1.0 and later
  175. * Mac OS X: in version 10.0 and later
  176. }
  177. function GetString(stringID: SInt16): StringHandle; external name '_GetString';
  178. {
  179. * GetIndString()
  180. *
  181. * Availability:
  182. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  183. * CarbonLib: in CarbonLib 1.0 and later
  184. * Mac OS X: in version 10.0 and later
  185. }
  186. procedure GetIndString(var theString: Str255; strListID: SInt16; index: SInt16); external name '_GetIndString';
  187. {
  188. * FindWordBreaks()
  189. *
  190. * Availability:
  191. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  192. * CarbonLib: in CarbonLib 1.0 and later
  193. * Mac OS X: in version 10.0 and later
  194. }
  195. procedure FindWordBreaks(textPtr: Ptr; textLength: SInt16; offset: SInt16; leadingEdge: boolean; breaks: BreakTablePtr; var offsets: OffsetTable; script: ScriptCode); external name '_FindWordBreaks';
  196. {
  197. * LowercaseText()
  198. *
  199. * Availability:
  200. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  201. * CarbonLib: in CarbonLib 1.0 and later
  202. * Mac OS X: in version 10.0 and later
  203. }
  204. procedure LowercaseText(textPtr: Ptr; len: SInt16; script: ScriptCode); external name '_LowercaseText';
  205. {
  206. * UppercaseText()
  207. *
  208. * Availability:
  209. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  210. * CarbonLib: in CarbonLib 1.0 and later
  211. * Mac OS X: in version 10.0 and later
  212. }
  213. procedure UppercaseText(textPtr: Ptr; len: SInt16; script: ScriptCode); external name '_UppercaseText';
  214. {
  215. * StripDiacritics()
  216. *
  217. * Availability:
  218. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  219. * CarbonLib: in CarbonLib 1.0 and later
  220. * Mac OS X: in version 10.0 and later
  221. }
  222. procedure StripDiacritics(textPtr: Ptr; len: SInt16; script: ScriptCode); external name '_StripDiacritics';
  223. {
  224. * UppercaseStripDiacritics()
  225. *
  226. * Availability:
  227. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  228. * CarbonLib: in CarbonLib 1.0 and later
  229. * Mac OS X: in version 10.0 and later
  230. }
  231. procedure UppercaseStripDiacritics(textPtr: Ptr; len: SInt16; script: ScriptCode); external name '_UppercaseStripDiacritics';
  232. {
  233. * FindScriptRun()
  234. *
  235. * Availability:
  236. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  237. * CarbonLib: in CarbonLib 1.0 and later
  238. * Mac OS X: in version 10.0 and later
  239. }
  240. function FindScriptRun(textPtr: Ptr; textLen: SInt32; var lenUsed: SInt32): ScriptRunStatus; external name '_FindScriptRun';
  241. {
  242. The following functions are old names, but are required for PowerPC builds
  243. because InterfaceLib exports these names, instead of the new ones.
  244. }
  245. {$ifc CALL_NOT_IN_CARBON}
  246. {
  247. * FindWord()
  248. *
  249. * Availability:
  250. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  251. * CarbonLib: not available
  252. * Mac OS X: not available
  253. }
  254. procedure FindWord(textPtr: Ptr; textLength: SInt16; offset: SInt16; leadingEdge: boolean; breaks: BreakTablePtr; var offsets: OffsetTable); external name '_FindWord';
  255. {
  256. * NFindWord()
  257. *
  258. * Availability:
  259. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  260. * CarbonLib: not available
  261. * Mac OS X: not available
  262. }
  263. procedure NFindWord(textPtr: Ptr; textLength: SInt16; offset: SInt16; leadingEdge: boolean; nbreaks: NBreakTablePtr; var offsets: OffsetTable); external name '_NFindWord';
  264. {
  265. On 68K machines, LwrText, LowerText, StripText, UpperText and StripUpperText
  266. return an error code in register D0, but System 7 PowerMacs do not emulate
  267. this properly, so checking D0 is unreliable.
  268. }
  269. {
  270. * LwrText()
  271. *
  272. * Availability:
  273. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  274. * CarbonLib: not available
  275. * Mac OS X: not available
  276. }
  277. procedure LwrText(textPtr: Ptr; len: SInt16); external name '_LwrText';
  278. {
  279. * LowerText()
  280. *
  281. * Availability:
  282. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  283. * CarbonLib: not available
  284. * Mac OS X: not available
  285. }
  286. procedure LowerText(textPtr: Ptr; len: SInt16); external name '_LowerText';
  287. {
  288. * StripText()
  289. *
  290. * Availability:
  291. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  292. * CarbonLib: not available
  293. * Mac OS X: not available
  294. }
  295. procedure StripText(textPtr: Ptr; len: SInt16); external name '_StripText';
  296. {
  297. * UpperText()
  298. *
  299. * Availability:
  300. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  301. * CarbonLib: not available
  302. * Mac OS X: not available
  303. }
  304. procedure UpperText(textPtr: Ptr; len: SInt16); external name '_UpperText';
  305. {
  306. * StripUpperText()
  307. *
  308. * Availability:
  309. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  310. * CarbonLib: not available
  311. * Mac OS X: not available
  312. }
  313. procedure StripUpperText(textPtr: Ptr; len: SInt16); external name '_StripUpperText';
  314. { The following are new names which are exported by InterfaceLib }
  315. {$endc} {CALL_NOT_IN_CARBON}
  316. {
  317. * UpperString()
  318. *
  319. * Availability:
  320. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  321. * CarbonLib: in CarbonLib 1.0 and later
  322. * Mac OS X: in version 10.0 and later
  323. }
  324. procedure UpperString(var theString: Str255; diacSensitive: boolean); external name '_UpperString';
  325. { Old routine name but no new names are mapped to it: }
  326. {$ifc CALL_NOT_IN_CARBON}
  327. {
  328. * UprText()
  329. *
  330. * Availability:
  331. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  332. * CarbonLib: not available
  333. * Mac OS X: not available
  334. }
  335. procedure UprText(textPtr: Ptr; len: SInt16); external name '_UprText';
  336. {$endc} {CALL_NOT_IN_CARBON}
  337. {
  338. Functions for converting between C and Pascal Strings
  339. (Previously in Strings.h)
  340. Note: CopyPascalStringToC, CopyCStringToPascal, c2pstrcpy, and p2cstrcpy
  341. are written to allow inplace conversion. That is, the src and dst
  342. parameters can point to the memory location. These functions
  343. are available in CarbonLib and CarbonAccessors.o.
  344. Note: c2pstr, C2PStr, p2cstr, and P2CStr are all deprecated. These functions
  345. only do inplace conversion and often require casts to call them. This can
  346. cause bugs because you can easily cast away a const and change the
  347. contents of a read-only buffer. These functions are available
  348. in InterfaceLib, or when building for Carbon if you #define OLDP2C,
  349. then they are available as a macro.
  350. }
  351. {
  352. * c2pstrcpy()
  353. *
  354. * Availability:
  355. * Non-Carbon CFM: in CarbonAccessors.o 1.0.2 and later
  356. * CarbonLib: in CarbonLib 1.0 and later
  357. * Mac OS X: in version 10.0 and later
  358. }
  359. procedure c2pstrcpy(var dst: Str255; src: ConstCStringPtr); external name '_c2pstrcpy';
  360. {
  361. * p2cstrcpy()
  362. *
  363. * Availability:
  364. * Non-Carbon CFM: in CarbonAccessors.o 1.0.2 and later
  365. * CarbonLib: in CarbonLib 1.0 and later
  366. * Mac OS X: in version 10.0 and later
  367. }
  368. procedure p2cstrcpy(dst: CStringPtr; const (*var*) src: Str255); external name '_p2cstrcpy';
  369. {
  370. * CopyPascalStringToC()
  371. *
  372. * Availability:
  373. * Non-Carbon CFM: in CarbonAccessors.o 1.0.2 and later
  374. * CarbonLib: in CarbonLib 1.0 and later
  375. * Mac OS X: in version 10.0 and later
  376. }
  377. procedure CopyPascalStringToC(const (*var*) src: Str255; dst: CStringPtr); external name '_CopyPascalStringToC';
  378. {
  379. * CopyCStringToPascal()
  380. *
  381. * Availability:
  382. * Non-Carbon CFM: in CarbonAccessors.o 1.0.2 and later
  383. * CarbonLib: in CarbonLib 1.0 and later
  384. * Mac OS X: in version 10.0 and later
  385. }
  386. procedure CopyCStringToPascal(src: ConstCStringPtr; var dst: Str255); external name '_CopyCStringToPascal';
  387. {$ifc CALL_NOT_IN_CARBON}
  388. {
  389. * C2PStrProc()
  390. *
  391. * Availability:
  392. * Non-Carbon CFM: not available
  393. * CarbonLib: not available
  394. * Mac OS X: not available
  395. }
  396. procedure C2PStrProc(aStr: UnivPtr); external name '_C2PStrProc';
  397. {
  398. * P2CStrProc()
  399. *
  400. * Availability:
  401. * Non-Carbon CFM: not available
  402. * CarbonLib: not available
  403. * Mac OS X: not available
  404. }
  405. procedure P2CStrProc(aStr: StringPtr); external name '_P2CStrProc';
  406. {
  407. * C2PStr()
  408. *
  409. * Availability:
  410. * Non-Carbon CFM: not available
  411. * CarbonLib: not available
  412. * Mac OS X: not available
  413. }
  414. function C2PStr(cString: UnivPtr): StringPtr; external name '_C2PStr';
  415. {
  416. * P2CStr()
  417. *
  418. * Availability:
  419. * Non-Carbon CFM: not available
  420. * CarbonLib: not available
  421. * Mac OS X: not available
  422. }
  423. function P2CStr(pString: StringPtr): Ptr; external name '_P2CStr';
  424. {$endc} {CALL_NOT_IN_CARBON}
  425. {$ALIGN MAC68K}
  426. end.