Carbon


CharacterByteType

Header: Script.h Carbon status: Supported

Identifies a byte in a text buffer as a 1-byte character or as the first or second byte of a 2-byte character.

SInt16 CharacterByteType (
    Ptr textBuf, 
    SInt16 textOffset, 
    ScriptCode script
);
Parameter descriptions
textBuf

A pointer to a text buffer containing the byte to be identified.

textOffset

The offset to the byte to be identified. The offset is measured in bytes; the first byte has an offset of 0.

script

A value that specifies the script system of the text in the buffer. Constants for all defined script codes are listed on “Script Codes”. To specify the font script, pass smCurrentScript in this parameter.

function result

One of three identifications: a 1-byte character, the first byte of a 2-byte character, or the second byte of a 2-byte character. The first byte of a 2-byte character—the one at the lower offset in memory—is the high-order byte; the second byte of a 2-byte character—the one at the higher offset—is the low-order byte. This is the same order in which text is processed and numbers are represented.

DISCUSSION

The script system associated with the character you wish to examine must be enabled in order for the function to provide useful information. For example, if only the Roman script system is available and you attempt to identify a byte in a run of 2-byte characters, the CharacterByteType function returns 0, indicating that the byte is a 1-byte character.

For 1-byte script systems, the character-type tables reside in the string-manipulation ('itl2') resource and reflect region-specific or language-specific differences in uppercase conventions.

For 2-byte script systems, the character-type tables reside in the encoding/rendering ('itl5') resource, not the string-manipulation resource. Whenever you call CharacterByteType, the necessary character-set encoding information is taken from the encoding/rendering resource. You cannot use the GetIntlResource function to access 2-byte character-type tables directly.

From byte value alone, it is not possible to distinguish the second byte of a 2-byte character from a 1-byte character. CharacterByteType differentiates the second byte of a 2-byte character from a 1-byte character by assuming that the byte at offset 0 is the first byte of a character. With that assumption, it then sequentially identifies the size and starting position of each character in the buffer up to textOffset.

SPECIAL CONSIDERATIONS

If you specify smCurrentScript for the script parameter, the value returned by CharacterByteType can be affected by the state of the font force flag. It is unaffected by the state of the international resources selection flag.

AVAILABILITY

Supported in Carbon. Available in Carbon 1.0.2 and later when running Mac OS 8.1 or later.


© 2000 Apple Computer, Inc. (Last Updated 6/30/2000)