TextUtils.h
上传用户:xjjlds
上传日期:2015-12-05
资源大小:22823k
文件大小:18k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. /*
  2.      File:       TextUtils.h
  3.  
  4.      Contains:   Text Utilities Interfaces.
  5.  
  6.      Version:    Technology: Mac OS 8
  7.                  Release:    QuickTime 6.0.2
  8.  
  9.      Copyright:  (c) 1985-2001 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:      For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __TEXTUTILS__
  18. #define __TEXTUTILS__
  19. #ifndef __MACTYPES__
  20. #include "MacTypes.h"
  21. #endif
  22. #ifndef __NUMBERFORMATTING__
  23. #include "NumberFormatting.h"
  24. #endif
  25. #ifndef __STRINGCOMPARE__
  26. #include "StringCompare.h"
  27. #endif
  28. #ifndef __DATETIMEUTILS__
  29. #include "DateTimeUtils.h"
  30. #endif
  31. #if PRAGMA_ONCE
  32. #pragma once
  33. #endif
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. #if PRAGMA_IMPORT
  38. #pragma import on
  39. #endif
  40. #if PRAGMA_STRUCT_ALIGN
  41.     #pragma options align=mac68k
  42. #elif PRAGMA_STRUCT_PACKPUSH
  43.     #pragma pack(push, 2)
  44. #elif PRAGMA_STRUCT_PACK
  45.     #pragma pack(2)
  46. #endif
  47. /*
  48.     Here are the current System 7 routine names and the translations to the older forms.
  49.     Please use the newer forms in all new code and migrate the older names out of existing
  50.     code as maintainance permits.
  51.     
  52.     NEW NAME                    OLD NAMEs                   OBSOLETE FORM (no script code)
  53.     FindScriptRun
  54.     FindWordBreaks                                          NFindWord, FindWord
  55.     GetIndString            
  56.     GetString
  57.     Munger
  58.     NewString               
  59.     SetString               
  60.     StyledLineBreak
  61.     TruncString
  62.     TruncText
  63.     UpperString ($A054)         UprString, UprText
  64.     UppercaseText               SCUpperText (a only)        UpperText ($A456)
  65.     LowercaseText                                           LwrString, LowerText, LwrText ($A056)
  66.     StripDiacritics                                         StripText ($A256)
  67.     UppercaseStripDiacritics                                StripUpperText ($A656)
  68. */
  69. /* Type for truncWhere parameter in TruncString, TruncText */
  70. typedef short                           TruncCode;
  71. enum {
  72.                                                                 /* Constants for truncWhere argument in TruncString and TruncText */
  73.     truncEnd                    = 0,                            /* Truncate at end */
  74.     truncMiddle                 = 0x4000,                       /* Truncate in middle */
  75.     smTruncEnd                  = 0,                            /* Truncate at end - obsolete */
  76.     smTruncMiddle               = 0x4000                        /* Truncate in middle - obsolete */
  77. };
  78. enum {
  79.                                                                 /* Constants for TruncString and TruncText results */
  80.     notTruncated                = 0,                            /* No truncation was necessary */
  81.     truncated                   = 1,                            /* Truncation performed */
  82.     truncErr                    = -1,                           /* General error */
  83.     smNotTruncated              = 0,                            /* No truncation was necessary - obsolete */
  84.     smTruncated                 = 1,                            /* Truncation performed   - obsolete */
  85.     smTruncErr                  = -1                            /* General error - obsolete */
  86. };
  87. typedef SInt8                           StyledLineBreakCode;
  88. enum {
  89.     smBreakWord                 = 0,
  90.     smBreakChar                 = 1,
  91.     smBreakOverflow             = 2
  92. };
  93. struct ScriptRunStatus {
  94.     SInt8                           script;
  95.     SInt8                           runVariant;
  96. };
  97. typedef struct ScriptRunStatus          ScriptRunStatus;
  98. struct BreakTable {
  99.     char                            charTypes[256];
  100.     short                           tripleLength;
  101.     short                           triples[1];
  102. };
  103. typedef struct BreakTable               BreakTable;
  104. typedef BreakTable *                    BreakTablePtr;
  105. struct NBreakTable {
  106.     SInt8                           flags1;
  107.     SInt8                           flags2;
  108.     short                           version;
  109.     short                           classTableOff;
  110.     short                           auxCTableOff;
  111.     short                           backwdTableOff;
  112.     short                           forwdTableOff;
  113.     short                           doBackup;
  114.     short                           length;                     /* length of NBreakTable */
  115.     char                            charTypes[256];
  116.     short                           tables[1];
  117. };
  118. typedef struct NBreakTable              NBreakTable;
  119. typedef NBreakTable *                   NBreakTablePtr;
  120. /* The following functions are new names that work on 68k and PowerPC*/
  121. EXTERN_API( long )
  122. Munger                          (Handle                 h,
  123.                                  long                   offset,
  124.                                  const void *           ptr1,
  125.                                  long                   len1,
  126.                                  const void *           ptr2,
  127.                                  long                   len2)                               ONEWORDINLINE(0xA9E0);
  128. EXTERN_API( StringHandle )
  129. NewString                       (ConstStr255Param       theString)                          ONEWORDINLINE(0xA906);
  130. EXTERN_API( void )
  131. SetString                       (StringHandle           theString,
  132.                                  ConstStr255Param       strNew)                             ONEWORDINLINE(0xA907);
  133. EXTERN_API( StringHandle )
  134. GetString                       (short                  stringID)                           ONEWORDINLINE(0xA9BA);
  135. EXTERN_API( void )
  136. GetIndString                    (Str255                 theString,
  137.                                  short                  strListID,
  138.                                  short                  index);
  139. #if CALL_NOT_IN_CARBON
  140. EXTERN_API_C( void )
  141. setstring                       (StringHandle           theString,
  142.                                  const char *           strNew);
  143. EXTERN_API_C( StringHandle )
  144. newstring                       (const char *           theString);
  145. EXTERN_API_C( void )
  146. getindstring                    (char *                 theString,
  147.                                  short                  strListID,
  148.                                  short                  index);
  149. #endif  /* CALL_NOT_IN_CARBON */
  150. EXTERN_API( StyledLineBreakCode )
  151. StyledLineBreak                 (Ptr                    textPtr,
  152.                                  long                   textLen,
  153.                                  long                   textStart,
  154.                                  long                   textEnd,
  155.                                  long                   flags,
  156.                                  Fixed *                textWidth,
  157.                                  long *                 textOffset)                         FOURWORDINLINE(0x2F3C, 0x821C, 0xFFFE, 0xA8B5);
  158. EXTERN_API( short )
  159. TruncString                     (short                  width,
  160.                                  Str255                 theString,
  161.                                  TruncCode              truncWhere)                         FOURWORDINLINE(0x2F3C, 0x8208, 0xFFE0, 0xA8B5);
  162. EXTERN_API( short )
  163. TruncText                       (short                  width,
  164.                                  Ptr                    textPtr,
  165.                                  short *                length,
  166.                                  TruncCode              truncWhere)                         FOURWORDINLINE(0x2F3C, 0x820C, 0xFFDE, 0xA8B5);
  167. EXTERN_API( void )
  168. FindWordBreaks                  (Ptr                    textPtr,
  169.                                  short                  textLength,
  170.                                  short                  offset,
  171.                                  Boolean                leadingEdge,
  172.                                  BreakTablePtr          breaks,
  173.                                  OffsetTable            offsets,
  174.                                  ScriptCode             script)                             FOURWORDINLINE(0x2F3C, 0xC012, 0x001A, 0xA8B5);
  175. EXTERN_API( void )
  176. LowercaseText                   (Ptr                    textPtr,
  177.                                  short                  len,
  178.                                  ScriptCode             script)                             SIXWORDINLINE(0x3F3C, 0x0000, 0x2F3C, 0x800A, 0xFFB6, 0xA8B5);
  179. EXTERN_API( void )
  180. UppercaseText                   (Ptr                    textPtr,
  181.                                  short                  len,
  182.                                  ScriptCode             script)                             SIXWORDINLINE(0x3F3C, 0x0400, 0x2F3C, 0x800A, 0xFFB6, 0xA8B5);
  183. EXTERN_API( void )
  184. StripDiacritics                 (Ptr                    textPtr,
  185.                                  short                  len,
  186.                                  ScriptCode             script)                             SIXWORDINLINE(0x3F3C, 0x0200, 0x2F3C, 0x800A, 0xFFB6, 0xA8B5);
  187. EXTERN_API( void )
  188. UppercaseStripDiacritics        (Ptr                    textPtr,
  189.                                  short                  len,
  190.                                  ScriptCode             script)                             SIXWORDINLINE(0x3F3C, 0x0600, 0x2F3C, 0x800A, 0xFFB6, 0xA8B5);
  191. EXTERN_API( ScriptRunStatus )
  192. FindScriptRun                   (Ptr                    textPtr,
  193.                                  long                   textLen,
  194.                                  long *                 lenUsed)                            FOURWORDINLINE(0x2F3C, 0x820C, 0x0026, 0xA8B5);
  195. #if CALL_NOT_IN_CARBON
  196. /*
  197.     The following functions are old names, but are required for PowerPC builds
  198.     because InterfaceLib exports these names, instead of the new ones.
  199. */
  200. #if CALL_NOT_IN_CARBON
  201. EXTERN_API( void )
  202. FindWord                        (Ptr                    textPtr,
  203.                                  short                  textLength,
  204.                                  short                  offset,
  205.                                  Boolean                leadingEdge,
  206.                                  BreakTablePtr          breaks,
  207.                                  OffsetTable            offsets)                            FOURWORDINLINE(0x2F3C, 0x8012, 0x001A, 0xA8B5);
  208. EXTERN_API( void )
  209. NFindWord                       (Ptr                    textPtr,
  210.                                  short                  textLength,
  211.                                  short                  offset,
  212.                                  Boolean                leadingEdge,
  213.                                  NBreakTablePtr         nbreaks,
  214.                                  OffsetTable            offsets)                            FOURWORDINLINE(0x2F3C, 0x8012, 0xFFE2, 0xA8B5);
  215. /*
  216.    On 68K machines, LwrText, LowerText, StripText, UpperText and StripUpperText
  217.    return an error code in register D0, but System 7 PowerMacs do not emulate
  218.    this properly, so checking D0 is unreliable.
  219. */
  220.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  221.                                                                                             #pragma parameter LwrText(__A0, __D0)
  222.                                                                                             #endif
  223. EXTERN_API( void )
  224. LwrText                         (Ptr                    textPtr,
  225.                                  short                  len)                                ONEWORDINLINE(0xA056);
  226.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  227.                                                                                             #pragma parameter LowerText(__A0, __D0)
  228.                                                                                             #endif
  229. EXTERN_API( void )
  230. LowerText                       (Ptr                    textPtr,
  231.                                  short                  len)                                ONEWORDINLINE(0xA056);
  232.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  233.                                                                                             #pragma parameter StripText(__A0, __D0)
  234.                                                                                             #endif
  235. EXTERN_API( void )
  236. StripText                       (Ptr                    textPtr,
  237.                                  short                  len)                                ONEWORDINLINE(0xA256);
  238.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  239.                                                                                             #pragma parameter UpperText(__A0, __D0)
  240.                                                                                             #endif
  241. EXTERN_API( void )
  242. UpperText                       (Ptr                    textPtr,
  243.                                  short                  len)                                ONEWORDINLINE(0xA456);
  244.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  245.                                                                                             #pragma parameter StripUpperText(__A0, __D0)
  246.                                                                                             #endif
  247. EXTERN_API( void )
  248. StripUpperText                  (Ptr                    textPtr,
  249.                                  short                  len)                                ONEWORDINLINE(0xA656);
  250. #endif  /* CALL_NOT_IN_CARBON */
  251. #endif  /* CALL_NOT_IN_CARBON */
  252. /* The following are new names which are exported by InterfaceLib*/
  253. EXTERN_API( void )
  254. UpperString                     (Str255                 theString,
  255.                                  Boolean                diacSensitive);
  256. EXTERN_API_C( void )
  257. upperstring                     (char *                 theString,
  258.                                  Boolean                diacSensitive);
  259. /* The following are macros which map old names to the names exported by InterfaceLib*/
  260. #if OLDROUTINENAMES
  261. #define UprString(theString, diacSensitive)  
  262.          UpperString(theString, diacSensitive)
  263. #endif  /* OLDROUTINENAMES */
  264. /* Old routine name but no new names are mapped to it:*/
  265. #if CALL_NOT_IN_CARBON
  266. #if CALL_NOT_IN_CARBON
  267.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  268.                                                                                             #pragma parameter UprText(__A0, __D0)
  269.                                                                                             #endif
  270. EXTERN_API( void )
  271. UprText                         (Ptr                    textPtr,
  272.                                  short                  len)                                ONEWORDINLINE(0xA054);
  273. #endif  /* CALL_NOT_IN_CARBON */
  274. #endif  /* CALL_NOT_IN_CARBON */
  275. /*
  276.     Functions for converting between C and Pascal Strings
  277.     (Previously in Strings.h)
  278.     
  279.     Note: CopyPascalStringToC, CopyCStringToPascal, c2pstrcpy, and p2cstrcpy
  280.           are written to allow inplace conversion.  That is, the src and dst
  281.           parameters can point to the memory location.  
  282.           
  283.     Note: c2pstr, C2PStr, p2cstr, and P2CStr are all deprecated.  These functions
  284.           only do inplace conversion and often require casts to call them.  This can
  285.           cause bugs because you can easily cast away a const and change the 
  286.           contents of a read-only buffer.  Do you know what c2pstr("Hello") will do?
  287.     
  288. */
  289. EXTERN_API_C( void )
  290. c2pstrcpy                       (Str255                 dst,
  291.                                  const char *           src);
  292. EXTERN_API_C( void )
  293. p2cstrcpy                       (char *                 dst,
  294.                                  ConstStr255Param       src);
  295. EXTERN_API_C( void )
  296. CopyPascalStringToC             (ConstStr255Param       src,
  297.                                  char *                 dst);
  298. EXTERN_API_C( void )
  299. CopyCStringToPascal             (const char *           src,
  300.                                  Str255                 dst);
  301. #if CALL_NOT_IN_CARBON
  302. #if CALL_NOT_IN_CARBON
  303. EXTERN_API_C( StringPtr )
  304. c2pstr                          (char *                 aStr);
  305. EXTERN_API( StringPtr )
  306. C2PStr                          (Ptr                    cString);
  307. EXTERN_API_C( char *)
  308. p2cstr                          (StringPtr              aStr);
  309. EXTERN_API( Ptr )
  310. P2CStr                          (StringPtr              pString);
  311. #endif  /* CALL_NOT_IN_CARBON */
  312. #endif  /* CALL_NOT_IN_CARBON */
  313. #if !TARGET_OS_MAC
  314.     /* Added for QuickTime 3.0 */
  315.     #define C2PStr(a)  (StringPtr)c2pstr((Ptr)(a))
  316.     #define P2CStr(a)  (Ptr)p2cstr(a)
  317.     #define CopyPascalStringToC(src,dst) p2cstrcpy(dst,src)
  318.     #define CopyCStringToPascal(src,dst) c2pstrcpy(dst,src)
  319. #endif
  320. /*
  321.    Added macros to convert p2cstr and c2pstr calls into p2cstrcpy and c2pstrcpy calls,
  322.    and map C2PStr and P2CStr to c2pstr and p2cstr for Carbon.
  323.    The use of the often unappreciated comma operator to coerce the proper return values,
  324.    since the p2cstrcpy and c2pstrcpy routines have no return value.
  325. */
  326. #if TARGET_OS_MAC && TARGET_API_MAC_CARBON && OLDP2C
  327.     #define p2cstr(aStr) (p2cstrcpy((char *) aStr, aStr) , (char *) aStr)
  328.     #define c2pstr(aStr) (c2pstrcpy(aStr, (char *) aStr) , (StringPtr) aStr)
  329.     #define C2PStr(a)  (StringPtr)c2pstr((Ptr)(a))
  330.     #define P2CStr(a)  (Ptr)p2cstr(a)
  331. #endif
  332. #if PRAGMA_STRUCT_ALIGN
  333.     #pragma options align=reset
  334. #elif PRAGMA_STRUCT_PACKPUSH
  335.     #pragma pack(pop)
  336. #elif PRAGMA_STRUCT_PACK
  337.     #pragma pack()
  338. #endif
  339. #ifdef PRAGMA_IMPORT_OFF
  340. #pragma import off
  341. #elif PRAGMA_IMPORT
  342. #pragma import reset
  343. #endif
  344. #ifdef __cplusplus
  345. }
  346. #endif
  347. #endif /* __TEXTUTILS__ */