home *** CD-ROM | disk | FTP | other *** search
- #ifndef FWCHARAC_H
- #define FWCHARAC_H
- //========================================================================================
- //
- // File: FWCharac.h
- // Release Version: $ 1.0d11 $
- //
- // Copyright: (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #ifndef FWPRIMEM_H
- #include "FWPriMem.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- // Native Character sets are determined by two parameters: 1) maximum character size,
- // and 2) fixed vs. variable width characters. If characters are fixed width, then
- // all characters are maximum character size in width.
- //
- // This strings component also uses a "median" character size value when dealing with
- // variable width characters. In all variable width systems we're aware of, the median
- // value should be 2 bytes. This median value is used in one place: computing
- // the capacity of a bounded string from the template capacity parameter.
- //
- // Note that all strings are terminated with a "NUL" character, which is a FW_Char(0).
- // This may be more zero bytes than necessary in some characters sets, but it's a simple
- // and safe rule to follow.
-
- typedef char FW_Char; // default to byte wide
- typedef unsigned short FW_WChar; // for two-byte ("Wide") characters
- typedef unsigned long FW_LChar; // big enough to hold characters 1-4 bytes in size
-
- typedef unsigned char FW_PascalChar;
- typedef unsigned char FW_Byte;
-
- typedef long FW_CharacterCount;
- typedef long FW_CharacterPosition;
-
- typedef long FW_ByteCount;
- typedef long FW_BytePosition;
-
- //========================================================================================
- // ----- Constants -----
- //========================================================================================
-
- enum {FW_kNulCharacter=0};
-
- enum {FW_kMedianCharacterSize=sizeof(FW_WChar)};
-
- #ifdef FW_BUILD_MAC
- const FW_Char FW_PlatformNewLineChar = '\n';
- #endif
- #ifdef FW_BUILD_WIN
- const FW_Char FW_PlatformNewLineChar = '\r';
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_StringLength
- //----------------------------------------------------------------------------------------
-
- FW_CharacterCount FW_FUNC_ATTR FW_StringLength(const FW_Char * string);
-
- //----------------------------------------------------------------------------------------
- // FW_BlockMove
- //----------------------------------------------------------------------------------------
-
- void FW_BlockMove(const FW_Byte *source, FW_Byte *destination, FW_ByteCount numberBytes);
-
- //========================================================================================
- // ----- Utility functions for byte <==> character mapping
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_BytePositionInString
- //----------------------------------------------------------------------------------------
-
- FW_Byte* FW_BytePositionInString(const void* string, FW_CharacterCount position);
- // Returns pointer to given character in string.
- // Uses FW_CharsToBytes()
-
- //----------------------------------------------------------------------------------------
- // FW_CharactersInBlock
- //----------------------------------------------------------------------------------------
-
- FW_CharacterCount FW_CharactersInBlock(const void *block, FW_ByteCount length);
- // Returns number of characters in block of bytes, using sizeof(FW_Char)
-
- //----------------------------------------------------------------------------------------
- // FW_CharsToBytes
- //----------------------------------------------------------------------------------------
-
- FW_ByteCount FW_CharsToBytes(FW_CharacterCount length);
- // Calculates number of bytes in length, using sizeof(FW_Char)
-
- //----------------------------------------------------------------------------------------
- // FW_PreviousCharacter
- //----------------------------------------------------------------------------------------
-
- FW_Byte* FW_PreviousCharacter(FW_Byte* string, FW_Byte* current, short delta=1);
- // Return a pointer to the character delta positions before the character at current,
- // i.e. current decremented by the number of bytes in the delta previous characters.
-
- //----------------------------------------------------------------------------------------
- // FW_PreviousCharacter
- //----------------------------------------------------------------------------------------
-
- const FW_Byte* FW_PreviousCharacter(const FW_Byte* string, const FW_Byte* current, short delta=1);
- // The const version of the above function.
-
- //========================================================================================
- // Inline functions
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_BlockMove
- //----------------------------------------------------------------------------------------
-
- inline void FW_BlockMove(const FW_Byte *source, FW_Byte *destination, FW_ByteCount numberItems)
- {
- FW_PrimitiveCopyMemory(source, destination, numberItems);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_BytePositionInString
- //----------------------------------------------------------------------------------------
-
- inline FW_Byte* FW_BytePositionInString(const void* string, FW_CharacterCount position)
- {
- return (FW_Byte*) string + FW_CharsToBytes(position);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CharactersInBlock
- //----------------------------------------------------------------------------------------
-
- inline FW_CharacterCount FW_CharactersInBlock(const void *block, FW_ByteCount length)
- {
- return length / sizeof(FW_Char);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PreviousCharacter
- //----------------------------------------------------------------------------------------
-
- inline FW_Byte* FW_PreviousCharacter(FW_Byte* string, FW_Byte* current, short delta)
- {
- return current - sizeof(FW_Char)*delta;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PreviousCharacter
- //----------------------------------------------------------------------------------------
-
- inline const FW_Byte* FW_PreviousCharacter(const FW_Byte* string, const FW_Byte* current, short delta)
- {
- return current - sizeof(FW_Char)*delta;
- }
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export off
- #endif
-
- #endif
-
-