home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWString / Include / FWCharac.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-08  |  6.6 KB  |  173 lines  |  [TEXT/MPS ]

  1. #ifndef FWCHARAC_H
  2. #define FWCHARAC_H
  3. //========================================================================================
  4. //
  5. //    File:                FWCharac.h
  6. //    Release Version:    $ 1.0d11 $
  7. //
  8. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWSTDDEF_H
  13. #include "FWStdDef.h"
  14. #endif
  15.  
  16. #ifndef FWPRIMEM_H
  17. #include "FWPriMem.h"
  18. #endif
  19.  
  20. #if FW_LIB_EXPORT_PRAGMAS
  21. #pragma lib_export on
  22. #endif
  23.  
  24. // Native Character sets are determined by two parameters: 1) maximum character size,
  25. // and 2) fixed vs. variable width characters.  If characters are fixed width, then
  26. // all characters are maximum character size in width.
  27. //
  28. // This strings component also uses a "median" character size value when dealing with
  29. // variable width characters.  In all variable width systems we're aware of, the median
  30. // value should be 2 bytes.  This median value is used in one place: computing
  31. // the capacity of a bounded string from the template capacity parameter.
  32. //
  33. // Note that all strings are terminated with a "NUL" character, which is a FW_Char(0).
  34. // This may be more zero bytes than necessary in some characters sets, but it's a simple
  35. // and safe rule to follow.
  36.  
  37. typedef char FW_Char;                // default to byte wide
  38. typedef unsigned short FW_WChar;    // for two-byte ("Wide") characters
  39. typedef unsigned long  FW_LChar;    // big enough to hold characters 1-4 bytes in size
  40.  
  41. typedef unsigned char  FW_PascalChar;
  42. typedef unsigned char  FW_Byte;
  43.  
  44. typedef long FW_CharacterCount;
  45. typedef long FW_CharacterPosition;
  46.  
  47. typedef long FW_ByteCount;
  48. typedef long FW_BytePosition;
  49.  
  50. //========================================================================================
  51. // ----- Constants -----
  52. //========================================================================================
  53.     
  54. enum {FW_kNulCharacter=0};
  55.  
  56. enum {FW_kMedianCharacterSize=sizeof(FW_WChar)};
  57.  
  58. #ifdef FW_BUILD_MAC
  59. const FW_Char FW_PlatformNewLineChar = '\n';
  60. #endif
  61. #ifdef FW_BUILD_WIN
  62. const FW_Char FW_PlatformNewLineChar = '\r';
  63. #endif
  64.  
  65. //----------------------------------------------------------------------------------------
  66. //    FW_StringLength
  67. //----------------------------------------------------------------------------------------
  68.  
  69. FW_CharacterCount FW_FUNC_ATTR FW_StringLength(const FW_Char * string);
  70.  
  71. //----------------------------------------------------------------------------------------
  72. //    FW_BlockMove
  73. //----------------------------------------------------------------------------------------
  74.  
  75. void FW_BlockMove(const FW_Byte *source, FW_Byte *destination, FW_ByteCount numberBytes);
  76.  
  77. //========================================================================================
  78. // ----- Utility functions for byte <==> character mapping
  79. //========================================================================================
  80.     
  81. //----------------------------------------------------------------------------------------
  82. //    FW_BytePositionInString
  83. //----------------------------------------------------------------------------------------
  84.  
  85. FW_Byte* FW_BytePositionInString(const void* string, FW_CharacterCount position);
  86.     // Returns pointer to given character in string.
  87.     // Uses FW_CharsToBytes()
  88.     
  89. //----------------------------------------------------------------------------------------
  90. //    FW_CharactersInBlock
  91. //----------------------------------------------------------------------------------------
  92.  
  93. FW_CharacterCount FW_CharactersInBlock(const void *block, FW_ByteCount length);
  94.     // Returns number of characters in block of bytes, using sizeof(FW_Char)
  95.  
  96. //----------------------------------------------------------------------------------------
  97. //    FW_CharsToBytes
  98. //----------------------------------------------------------------------------------------
  99.  
  100. FW_ByteCount FW_CharsToBytes(FW_CharacterCount length);
  101.     // Calculates number of bytes in length, using sizeof(FW_Char)
  102.     
  103. //----------------------------------------------------------------------------------------
  104. //    FW_PreviousCharacter
  105. //----------------------------------------------------------------------------------------
  106.  
  107. FW_Byte* FW_PreviousCharacter(FW_Byte* string, FW_Byte* current, short delta=1);
  108.     // Return a pointer to the character delta positions before the character at current,
  109.     // i.e. current decremented by the number of bytes in the delta previous characters.
  110.     
  111. //----------------------------------------------------------------------------------------
  112. //    FW_PreviousCharacter
  113. //----------------------------------------------------------------------------------------
  114.  
  115. const FW_Byte* FW_PreviousCharacter(const FW_Byte* string, const FW_Byte* current, short delta=1);
  116.     // The const version of the above function.
  117.  
  118. //========================================================================================
  119. //    Inline functions
  120. //========================================================================================
  121.  
  122. //----------------------------------------------------------------------------------------
  123. //    FW_BlockMove
  124. //----------------------------------------------------------------------------------------
  125.  
  126. inline void FW_BlockMove(const FW_Byte *source, FW_Byte *destination, FW_ByteCount numberItems)
  127. {
  128.     FW_PrimitiveCopyMemory(source, destination, numberItems);
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. //    FW_BytePositionInString
  133. //----------------------------------------------------------------------------------------
  134.  
  135. inline FW_Byte* FW_BytePositionInString(const void* string, FW_CharacterCount position)
  136. {
  137.     return (FW_Byte*) string + FW_CharsToBytes(position);
  138. }
  139.  
  140. //----------------------------------------------------------------------------------------
  141. //    FW_CharactersInBlock
  142. //----------------------------------------------------------------------------------------
  143.  
  144. inline FW_CharacterCount FW_CharactersInBlock(const void *block, FW_ByteCount length)
  145. {
  146.     return length / sizeof(FW_Char);
  147. }
  148.         
  149. //----------------------------------------------------------------------------------------
  150. //    FW_PreviousCharacter
  151. //----------------------------------------------------------------------------------------
  152.  
  153. inline FW_Byte* FW_PreviousCharacter(FW_Byte* string, FW_Byte* current, short delta)
  154. {
  155.     return current - sizeof(FW_Char)*delta;
  156. }
  157.  
  158. //----------------------------------------------------------------------------------------
  159. //    FW_PreviousCharacter
  160. //----------------------------------------------------------------------------------------
  161.  
  162. inline const FW_Byte* FW_PreviousCharacter(const FW_Byte* string, const FW_Byte* current, short delta)
  163. {
  164.     return current - sizeof(FW_Char)*delta;
  165. }
  166.  
  167. #if FW_LIB_EXPORT_PRAGMAS
  168. #pragma lib_export off
  169. #endif
  170.  
  171. #endif
  172.  
  173.