Previous Page Table of Contents Index Next Page

Palm OS SDK Reference


Palm Logo 47 Text Manager

This chapter provides information about the text manager by discussing these topics:

The header file TextMgr.h declares the API that this chapter describes. For more information on the text manager, see the chapter "Localized Applications" in the Palm OS Programmer's Companion.

Text Manager Data Structures

CharEncodingType

The CharEncodingType enum specifies possible character encodings. A given device supports a single character encoding. The currently available devices support either Windows code page 1252 (an extension of ISO Latin 1) or Windows code page 932 (an extension of Shift JIS).

typedef enum {
    charEncodingUnknown = 0,
   
    charEncodingAscii,
    charEncodingISO8859_1,
    charEncodingPalmLatin,
    charEncodingShiftJIS,
    charEncodingPalmSJIS,
    charEncodingUTF8,
    charEncodingCP1252,
    charEncodingCP932
} CharEncodingType;

Value Descriptions

charEncodingUnknown Unknown to this version of Palm OS®.
charEncodingAscii ISO 646-1991.
charEncodingISO8859_1 ISO 8859 Part 1 (also known as ISO Latin 1). This encoding is commonly used for the Roman alphabet.
charEncodingPalmLatin Palm OS version of Microsoft Windows code page 1252
charEncodingShiftJIS Encoding for 0208-1990 with single-byte Japanese Katakana. This encoding is commonly used for Japanese alphabets.
charEncodingPalmSJIS Palm OS version of Microsoft Windows code page 932
charEncodingCP1252 Microsoft Windows extensions to ISO 8859 Part 1.
charEncodingCP932 Microsoft Windows extensions to Shift JIS.
charEncodingUTF8 Eight-bit safe encoding for Unicode.

Text Manager Functions




TxtByteAttr

Purpose

Return the possible locations of a given byte within a multi-byte character.

Prototype

UInt8 TxtByteAttr (UInt8 inByte)

Parameters

  -> inByte
A byte representing all or part of a valid character.

Result

Returns a byte with one or more of the following bits set:

byteAttrFirst

First byte of multi-byte character.

byteAttrLast

Last byte of multi-byte character.

byteAttrMiddle

Middle byte of multi-byte character.

byteAttrSingle

Single-byte character.

Comments

If inByte is valid in more than one location of a character, multiple return bits are set. For example, 0x40 in the Shift JIS character encoding is valid as a single-byte character and as the low-order byte of a double-byte character. Thus, the return value for TxtByteAttr(0x40) on a Shift JIS system has both the byteAttrSingle and byteAttrLast bits set.

Text manager functions that need to determine the byte positioning of a character use TxtByteAttr to do so. You rarely need to use this function yourself.

Compatibility

Implemented only if International Feature Set is present.



TxtCaselessCompare

Purpose

Perform a case-insensitive comparison of two text buffers.

Prototype

Int16 TxtCaselessCompare (const Char* s1, UInt16 s1Len, UInt16* s1MatchLen, const Char* s2, UInt16 s2Len, UInt16* s2MatchLen)

Parameters

  -> s1
Pointer to the first text buffer to compare. Must not be NULL.
  -> s1Len
Length in bytes of the text pointed to by s1.
  <- s1MatchLen
Points to the length in bytes of the text in s1 that matched text in s2. Pass NULL for this parameter if you don't need to know this number.
  -> s2
Pointer to the second text buffer to compare. Must not be NULL.
  -> s2Len
Length in bytes of the text pointed to by s2.
  <- s2MatchLen
Points to the length in bytes of the text in s2 that matched text in s1. Pass NULL for this parameter if you don't need to know this number.

Result

Returns one of the following values:

< 0 If s1 occurs before s2 in alphabetical order.
> 0 If s1 occurs after s2 in alphabetical order.
0 If the two substrings that were compared are equal.

Comments

In certain character encodings (such as Shift JIS), one character may be accurately represented as either a single-byte character or a multi-byte character. TxtCaselessCompare accurately matches a single-byte character with its multi-byte equivalent. For this reason, the values returned in s1MatchLen and s2MatchLen are not always equal.

You must make sure that the parameters s1 and s2 point to a the start of a valid character. That is, they must point to the first byte of a multi-byte character or they must point to a single-byte character. If they don't, results are unpredictable.

Compatibility

Implemented only if International Feature Set is present.

See Also

StrCaselessCompare, TxtCompare, StrCompare



TxtCharAttr

Purpose

Return a character's attributes.

Prototype

UInt16 TxtCharAttr (WChar inChar)

Parameters

  -> inChar
Any valid character.

Result

Returns a 16-bit unsigned value with any of the following bits set:

charAttrPrint

Printable

charAttrSpace

Blank space, tab, or newline

charAttrAlNum

Alphanumeric

charAttrAlpha

Alphabetic

charAttrCntrl

Control character

charAttrGraph

Character that appears on the screen; that is, is not whitespace, a control character, or a virtual character.

charAttrDelim

Word delimiter (whitespace or punctuation).

Comments

The character passed to this function must be a valid character given the system encoding.

This function is used in the text manager's character attribute macros (TxtCharIsAlNum, TxtCharIsCntrl, and so on). The macros perform operations analogous to the standard C functions isPunct, isPrintable, and so on. Usually, you'd use one of these macros instead of calling TxtCharAttr directly.

To obtain attributes specific to a given character encoding, use TxtCharXAttr.

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtCharIsValid



TxtCharBounds

Purpose

Return the boundaries of a character containing the byte at a specified offset in a string.

Prototype

WChar TxtCharBounds (const Char* inText, UInt32 inOffset, UInt32* outStart, UInt32* outEnd)

Parameters

  -> inText
Pointer to the text buffer to search. Must not be NULL.
  -> inOffset
A valid offset into the buffer inText. This location may contain a byte in any position (start, middle, or end) of a multi-byte character.
  <- outStart
Points to the starting offset of the character containing the byte at inOffset.
  <- outEnd
Points to the ending offset of the character containing the byte at inOffset.

Result

Returns the character located between the offsets outStart and outEnd.

Comments

Use this function to determine the boundaries of a character in a string or text buffer.

If the byte at inOffset is valid in more than one location of a character, the function must search back toward the beginning of the text buffer until it finds an unambiguous byte to determine the appropriate boundaries. For this reason, TxtCharBounds is often slow and should be used only where needed.

You must make sure that the parameter inText points to the beginning of the string. That is, if the string begins with a multi-byte character, inText must point to the first byte of that character. If it doesn't, results are unpredictable.

Compatibility

Implemented only if International Feature Set is present.



TxtCharEncoding

Purpose

Return the minimum encoding required to represent a character.

Prototype

CharEncodingType TxtCharEncoding (WChar inChar)

Parameters

  -> inChar
A valid character.

Result

A CharEncodingType value that indicates the minimum encoding required to represent inChar. If the character isn't recognizable, charEncodingUnknown is returned.

Comments

The minimum encoding is the encoding that takes the lowest number of bytes to represent the character. For example, if the character is a blank or a tab character, the minimum encoding is charEncodingAscii because these characters can be represented in single-byte ASCII. If the character is a ü, the minimum encoding is charEncodingISO8859_1.

Because Palm OS® only supports a single character encoding at a time, the result of this function is always logically equal to or less than the encoding used on the current system. That is, you'll only receive a return value of charEncodingISO8859_1 if you're running on a US or European system and you pass a non-ASCII character.

Use this function for informational purposes only. Your code should not assume that the character encoding returned by this function is the Palm OS system character encoding. (Instead use FtrGet as shown in the TxtCharXAttr function description.)

Use TxtMaxEncoding to determine the order of encodings.

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtStrEncoding, TxtMaxEncoding



TxtCharIsAlNum

Purpose

Macro that indicates if the character is alphanumeric.

Prototype

TxtCharIsAlNum (ch)

Parameters

  -> ch
A valid character.

Result

Returns true if the character is a letter in an alphabet or a numeric digit, false otherwise.

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtCharIsDigit, TxtCharIsAlpha



TxtCharIsAlpha

Purpose

Macro that indicates if a character is a letter in an alphabet.

Prototype

TxtCharIsAlpha (ch)

Parameters

  -> ch
A valid character.

Result

Returns true if the character is a letter in an alphabet, false otherwise.

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtCharIsAlNum, TxtCharIsLower, TxtCharIsUpper



TxtCharIsCntrl

Purpose

Macro that indicates if a character is a control character.

Prototype

TxtCharIsCntrl (ch)

Parameters

  -> ch
A valid character.

Result

Returns true if the character is a non-printable character, such as the bell character or a carriage return; false otherwise.

Compatibility

Implemented only if International Feature Set is present.



TxtCharIsDelim

Purpose

Macro that indicates if a character is a delimiter.

Prototype

TxtCharIsDelim (ch)

Parameters

  -> ch
A valid character.

Result

Returns true if the character is a word delimiter (whitespace or punctuation), false otherwise.

Compatibility

Implemented only if International Feature Set is present.



TxtCharIsDigit

Purpose

Macro that indicates if the character is a decimal digit.

Prototype

TxtCharIsDigit (ch)

Parameters

  -> ch
A valid character.

Result

Returns true if the character is 0 through 9, false otherwise.

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtCharIsAlNum, TxtCharIsHex



TxtCharIsGraph

Purpose

Macro that indicates if a character is a graphic character.

Prototype

TxtCharIsGraph (ch)

Parameters

  -> ch
A valid character.

Result

Returns true if the character is a graphic character, false otherwise.

Comments

A graphic character is any character visible on the screen, in other words, letters, digits, and punctuation marks. A blank space is not a graphic character because it is not visible.

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtCharIsPrint



TxtCharIsHardKey

Purpose

Macro that returns true if the character is one of the hard keys on the device.

Prototype

TxtCharIsHardKey (m, ch)

Parameters

  -> m
The modifier keys from the keyDownEvent.
  -> ch
The character from the keyDownEvent.

Result

true if the character is one of the four built-in hard keys on the device, false otherwise.

Compatibility

Implemented only if International Feature Set is present.

See Also

ChrIsHardKey



TxtCharIsHex

Purpose

Macro that indicates if a character is a hexadecimal digit.

Prototype

TxtCharIsHex (ch)

Parameters

  -> ch
A valid character.

Result

Returns true if the character is a hexadecimal digit from 0 to F, false otherwise.

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtCharIsDigit



TxtCharIsLower

Purpose

Macro that indicates if a character is a lowercase letter.

Prototype

TxtCharIsLower (ch)

Parameters

  -> ch
A valid character.

Result

Returns true if the character is a lowercase letter, false otherwise.

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtCharIsAlpha, TxtCharIsUpper



TxtCharIsPrint

Purpose

Macro that indicates if a character is printable.

Prototype

TxtCharIsPrint (ch)

Parameters

  -> ch
A valid character.

Result

Returns true if the character is not a control or virtual character, false otherwise.

Comments

This function differs from TxtCharIsGraph in that it returns true if the character is whitespace. TxtCharIsGraph returns false if the character is whitespace.

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtCharIsValid



TxtCharIsPunct

Purpose

Macro that indicates if a character is a punctuation mark.

Prototype

TxtCharIsPunct (ch)

Parameters

  -> ch
A valid character.

Result

Returns true if the character is a punctuation mark, false otherwise.

Compatibility

Implemented only if International Feature Set is present.



TxtCharIsSpace

Purpose

Macro that indicates if a character is a whitespace character.

Prototype

TxtCharIsSpace (ch)

Parameters

  -> ch
A valid character.

Result

Returns true if the character is whitespace such as a blank space, tab, or newline; false otherwise.

Compatibility

Implemented only if International Feature Set is present.



TxtCharIsUpper

Purpose

Macro that indicates if a character is an uppercase letter.

Prototype

TxtCharIsUpper (ch)

Parameters

  -> ch
A valid character.

Result

Returns true if the character is an uppercase letter, false otherwise.

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtCharIsAlpha, TxtCharIsLower



TxtCharIsValid

Purpose

Determine whether a character is valid character given the Palm OS character encoding.

Prototype

Boolean TxtCharIsValid (WChar inChar)

Parameters

  -> inChar
A character.

Result

Returns true if inChar is a valid character; false if inChar is not a valid character.

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtCharAttr, TxtCharIsPrint



TxtCharSize

Purpose

Return the number of bytes required to store the character in a string.

Prototype

UInt16 TxtCharSize (WChar inChar)

Parameters

  -> inChar
A valid character.

Result

The the number of bytes required to store the character in a string.

Comments

Outside of strings, characters are always two-byte long WChar values; however, strings may store characters as a single-byte value. If the character can be represented by a single byte (its high-order byte is 0), it is stored in a string as a single-byte character.

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtCharBounds



TxtCharWidth

Purpose

Return the width required to display the specified character in the current font. If the specified character does not exist within the current font, the missing character symbol is substituted.

Prototype

Int16 TxtCharWidth (WChar inChar)

Parameters

  -> inChar
A valid character.

Result

Returns the width of the specified character (in pixels).

Comments

Use this function instead of FntCharWidth to determine the width of a single-byte or multi-byte character.

Compatibility

Implemented only if International Feature Set is present.



TxtCharXAttr

Purpose

Return the extended attribute bits for a character.

Prototype

UInt16 TxtCharXAttr (WChar inChar)

Parameters

  -> inChar
A valid character.

Result

Returns an unsigned 16-bit value with one or more extended attribute bits set. For specific return values, look in the header files that are specific to certain character encodings (CharLatin.h or CharShiftJIS.h).

Comments

To interpret the results, you must know the character encoding being used. Use FtrGet with sysFtrNumEncoding as the feature number to determine the character encoding. This returns one of the CharEncodingType values. For example:

WChar ch;
UInt16 encoding, attr;
...
attr = TxtCharXAttr(ch);
if (FtrGet(sysFtrCreator, sysFtrNumEncoding,
&encoding) != 0)
encoding = charEncodingCP1252;;
if (encoding == charEncodingUTF8) {
}

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtCharAttr



TxtCompare

Purpose

Performs a case-sensitive comparison of all or part of two text buffers.

Prototype

Int16 TxtCompare (const Char* s1, UInt16 s1Len, UInt16* s1MatchLen, const Char* s2, UInt16 s2Len, UInt16* s2MatchLen)

Parameters

  -> s1
Pointer to the first text buffer to compare. Must not be NULL.
  -> s1Len
The length in bytes of the text pointed to by s1.
  <- s1MatchLen
Points to the length in bytes of the text in s1 that matched text in s2. Pass NULL for this parameter if you don't need to know this number.
  -> s2
Pointer to the second text buffer to compare. Must not be NULL.
  -> s2Len
The length in bytes of the text pointed to by s2.
  <- s2MatchLen
Points to the length in bytes of the text in s2 that matched text in s1. Pass NULL for this parameter if you don't need to know this number.

Result

Returns one of the following values:

< 0 If s1 occurs before s2 in alphabetical order.
> 0 If s1 occurs after s2 in alphabetical order.
0 If the two substrings that were compared are equal.

Comments

In certain character encodings (such as Shift JIS), one character may be accurately represented as either a single-byte character or a multi-byte character. TxtCompare accurately matches a single-byte character with its multi-byte equivalent. For this reason, the values returned in s1MatchLen and s2MatchLen are not always equal.

This function performs a case-sensitive comparison. If you want to perform a case-insensitive comparison, use TxtCaselessCompare.

You must make sure that the parameters s1 and s2 point to the start of a a valid character. That is, they must point to the first byte of a multi-byte character or they must point to a single-byte character. If they don't, results are unpredictable.

Compatibility

Implemented only if International Feature Set is present.

See Also

StrCompare, TxtFindString



TxtEncodingName

Purpose

Obtain a character encoding's name.

Prototype

const Char* TxtEncodingName (CharEncodingType inEncoding)

Parameters

  -> inEncoding
One of the values from CharEncodingType, indicating a character encoding.

Result

A constant string containing the name of the encoding.

encodingNameAscii

us ascii

encodingNameISO8859_1

ISO-8859-1

encodingNameCP1252

ISO-8859-1-Windows-3.1-Latin-1

encodingNameShiftJIS

Shift_JIS

encodingNameCP932

Windows-31J

encodingNameUTF8

UTF-8

""

The encoding is not known

Comments

Use this function to obtain the official name of the character encoding, suitable to pass to an Internet application or any other application that requires the character encoding's name to be passed along with the data.

Compatibility

Implemented only if International Feature Set is present.

See Also

CharEncodingType



TxtFindString

Purpose

Perform a case-insensitive search for a string in another string.

Prototype

Boolean TxtFindString (const Char* inSourceStr, const Char* inTargetStr, UInt32* outPos, UInt16* outLength)

Parameters

  -> inSourceStr
Pointer to the string to be searched. Must not be NULL.
  -> inTargetStr
Prepared version of the string to be found.
  <- outPos
Pointer to the offset of the match in inSourceStr.
  <- outLength
Pointer to the length in bytes of the matching text.

Result

Returns true if the function finds inTargetStr within inSourceStr; false otherwise.

If found, the values pointed to by the outPos and outLength parameters are set to the starting offset and the length of the matching text. If not found, the values pointed to by outPos and outLength are set to 0.

Comments

Use this function instead of FindStrInStr to support the global system find facility. This function contains an extra parameter, outLength, to specify the length of the text that matched. Pass this value to FindSaveMatch in the appCustom parameter. Then when your application receives sysAppLaunchCmdGoTo, the matchCustom field contains the length of the matching text. You use the length of matching text to highlight the match within the selected record.

You must make sure that the parameters inSourceStr and inTargetStr point to the start of a valid character. That is, they must point to the first byte of a multi-byte character, or they must point to a single-byte character. If they don't, results are unpredictable.

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtCaselessCompare



TxtGetChar

Purpose

Retrieve the character starting at the specified offset within a text buffer.

Prototype

WChar TxtGetChar (const Char* inText, UInt32 inOffset)

Parameters

  -> inText
Pointer to the text buffer to be searched. Must not be NULL.
  -> inOffset
A valid offset into the buffer inText. This offset must point to an inter-character boundary.

Result

Returns the character at inOffset in inText.

Comments

You must make sure that the parameter inText points to the start of a valid character. That is, it must point to the first byte of a multi-byte character or it must point to a single-byte character. If it doesn't, results are unpredictable.

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtGetNextChar, TxtSetNextChar



TxtGetNextChar

Purpose

Retrieve the character starting at the specified offset within a text buffer.

Prototype

UInt16 TxtGetNextChar (const Char* inText, UInt32 inOffset, WChar* outChar)

Parameters

  -> inText
Pointer to the text buffer to be searched. Must not be NULL.
  -> inOffset
A valid offset into the buffer inText. This offset must point to an inter-character boundary.
  <- outChar
The character at inOffset in inText. Pass NULL for this parameter if you don't need the character returned.

Result

Returns the size in bytes of the character at inOffset. If outChar is not NULL upon entry, it points to the character at inOffset upon return.

Comments

You can use this function to iterate through a text buffer character-by-character in this way:

UInt16 i = 0;
while (i < bufferLength) {
i += TxtGetNextChar(buffer, i, &ch);
//do something with ch.
}

You must make sure that the parameter inText points to the start of a valid character. That is, it must point to the first byte of a multi-byte character or it must point to a single-byte character. If it doesn't, results are unpredictable.

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtGetChar, TxtGetPreviousChar, TxtSetNextChar



TxtGetPreviousChar

Purpose

Retrieve the character before the specified offset within a text buffer.

Prototype

UInt16 TxtGetPreviousChar (const Char* inText, UInt32 inOffset, WChar* outChar)

Parameters

  -> inText
Pointer to the text buffer to be searched. Must not be NULL.
  -> inOffset
A valid offset into the buffer inText. This offset must point to an inter-character boundary.
  <- outChar
The character immediately preceding inOffset in inText. Pass NULL for this parameter if you don't need the character returned.

Result

Returns the size in bytes of the character preceding inOffset in inText. If outChar is not NULL upon entry, then it points to the character preceding inOffset upon return. Returns 0 if inOffset is at the start of the buffer (that is, inOffset is 0).

Comments

You can use this function to iterate through a text buffer character-by-character in this way:

/* Find the start of the character containing the last byte. */
TxtCharBounds (buffer, bufferLength - 1, &start, &end);
i = start;
while (i > 0) {
    i -= TxtGetPreviousChar(buffer, i, &ch);
    //do something with ch.
}

This function is often slower to use than TxtGetNextChar because it must determine the appropriate character boundaries if the byte immediately before the offset is valid in more than one location (start, middle, or end) of a multi-byte character. To do this, it must work backwards toward the beginning of the string until it finds an unambiguous byte.

You must make sure that the parameter inText points to the start of a valid character. That is, it must point to the first byte of a multi-byte character or it must point to a single-byte character. If it doesn't, results are unpredictable.

Compatibility

Implemented only if International Feature Set is present.



TxtGetTruncationOffset

Purpose

Return the appropriate byte position for truncating a text buffer such that it is at most a specified number of bytes long.

Prototype

UInt32 TxtGetTruncationOffset (const Char* inText, UInt32 inOffset)

Parameters

  -> inText
Pointer to a text buffer. Must not be NULL.
  -> inOffset
A valid offset into the buffer inText.

Result

Returns the appropriate byte offset for truncating inText at a valid inter-character boundary. The return value may be less than or equal to inOffset.

Comments

You must make sure that the parameter inText points to the start of a valid character. That is, it must point to the first byte of a multi-byte character or it must point to a single-byte character. If it doesn't, results are unpredictable.

Compatibility

Implemented only if International Feature Set is present.



TxtMaxEncoding

Purpose

Return the higher of two encodings.

Prototype

CharEncodingType TxtMaxEncoding (CharEncodingType a, CharEncodingType b)

Parameters

  -> a
A character encoding to compare.
  -> b
Another character encoding to compare.

Result

Returns the higher of a or b. One character encoding is higher than another if it is more specific. For example code page 1252 is "higher" than ISO 8859-1 because it represents more characters than ISO 8859-1.

Comments

This function is used by TxtStrEncoding to determine the encoding required for a string.

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtCharEncoding, CharEncodingType



TxtNextCharSize

Purpose

Macro that returns the size of the character starting at the specified offset within a text buffer.

Prototype

TxtNextCharSize (inText, inOffset)

Parameters

  -> inText
Pointer to the text buffer to be searched. Must not be NULL.
  -> inOffset
A valid offset into the buffer inText. This offset must point to an inter-character boundary.

Result

Returns (as a UInt16) the size in bytes of the character at inOffset.

Comments

You must make sure that the parameter inText points to the start of a valid character. That is, it must point to the first byte of a multi-byte character or it must point to a single-byte character. If it doesn't, results are unpredictable.

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtGetNextChar



TxtParamString

Purpose

Replace substrings within a string with the specified values.

Prototype

Char* TxtParamString (const Char* inTemplate, const Char* param0, const Char* param1, const Char* param2, const Char* param3)

Parameters

  -> inTemplate
The string containing the substrings to replace.
  -> param0
String to replace ^0 with or NULL.
  -> param1
String to replace ^1 with or NULL.
  -> param2
String to replace ^2 with or NULL.
  -> param3
String to replace ^3 with or NULL.

Result

Returns a locked handle to a newly allocated string in the dynamic heap that contains the appropriate substitutions.

Comments

This function searches inTemplate for occurrences of the sequences ^0, ^1, ^2, and ^3. When it finds these, it replaces them with the corresponding string passed to this function. Multiple instances of each sequence will be replaced.

You must make sure that the parameter inTemplate points to the start of a valid character. That is, it must point to the first byte of a multi-byte character or it must point to a single-byte character. If it doesn't, results are unpredictable.

TxtParamString allocates space for the returned string in the dynamic heap. Your code is responsible for freeing this memory when it is no longer needed.

Compatibility

Implemented if 3.5 New Feature Set is present.

See Also

TxtReplaceStr, FrmCustomAlert



TxtPreviousCharSize

Purpose

Macro that returns the size of the character before the specified offset within a text buffer.

Prototype

TxtPreviousCharSize (inText, inOffset)

Parameters

  -> inText
Pointer to the text buffer. Must not be NULL.
  -> inOffset
A valid offset into the buffer inText. This offset must point to an inter-character boundary.

Result

Returns (as a UInt16) the size in bytes of the character preceding inOffset in inText. Returns 0 if inOffset is at the start of the buffer (that is, inOffset is 0).

Comments

You must make sure that the parameter inText points to the start of a valid character. That is, it must point to the first byte of a multi-byte character or it must point to a single-byte character. If it doesn't, results are unpredictable.

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtGetPreviousChar



TxtReplaceStr

Purpose

Replace a substring of a given format with another string.

Prototype

UInt16 TxtReplaceStr (Char* ioStr, UInt16 inMaxLen, const Char* inParamStr, UInt16 inParamNum)

Parameters

  <-> ioStr
The string in which to perform the replacing. Must not be NULL.
  -> inMaxLen
The maximum length in bytes that ioStr can become.
  -> inParamStr
The string that ^inParamNum should be replaced with. If NULL, no changes are made.
  -> inParamNum
A single-digit number (0 to 9).

Result

Returns the number of occurrences found and replaced.

Returns a fatal error message if inParamNum is greater than 9.

Comments

This function searches ioStr for occurrences of the string ^inParamNum, where inParamNum is any digit from 0 to 9. When it finds the string, it replaces it with inParamStr. Multiple instances will be replaced as long as the resulting string doesn't contain more than inMaxLen bytes, not counting the terminating null.

You can set the inParamStr parameter to NULL to determine the required length of ioStr before actually doing the replacing. TxtReplaceStr returns the number of occurrences it finds of ^inParamNum. Multiply this value by the length of the inParamStr you intend to use to determine the appropriate length of ioStr.

You must make sure that the parameter ioStr points to the start of a valid character. That is, it must point to the first byte of a multi-byte character or it must point to a single-byte character. If it doesn't, results are unpredictable.

Compatibility

Implemented only if International Feature Set is present.



TxtSetNextChar

Purpose

Set a character within a text buffer.

Prototype

UInt16 TxtSetNextChar (Char* ioText, UInt32 inOffset, WChar inChar)

Parameters

  <-> ioText
Pointer to a text buffer. Must not be NULL.
  -> inOffset
A valid offset into the buffer inText. This offset must point to an inter-character boundary.
  -> inChar
The character to replace the character at inOffset with. Must not be a virtual character.

Result

Returns the size of inChar.

Comments

This function replaces the character in ioText at the location inOffset with the character inChar. Note that there must be enough space at inOffset to write the character.

You can use TxtCharSize to determine the size of inChar.

You must make sure that the parameter ioText points to the start of a valid character. That is, it must point to the first byte of a multi-byte character or it must point to a single-byte character. If it doesn't, results are unpredictable.

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtGetNextChar



TxtStrEncoding

Purpose

Return the encoding required to represent a string.

Prototype

CharEncodingType TxtStrEncoding (const Char* inStr)

Parameters

  -> inStr
A string. Must not be NULL.

Result

A CharEncodingType value that indicates the encoding required to represent inChar. If any character in the string isn't recognizable, then charEncodingUnknown is returned.

Comments

The encoding for the string is the maximum encoding of any character in that string. For example, if a two-character string contains a blank space and a ü, the appropriate encoding is charEncodingISO8859_1. The blank space's minimum encoding is ASCII. The minimum encoding for the ü is ISO 8859-1. The maximum of these two encodings is ISO 8859-1.

Because Palm OS only supports a single character encoding at a time, the results of this function is always logically equal to or less than the encoding used on the current system. That is, you'll only receive a return value of charEncodingISO8859_1 if you're running on a USA or European system.

Use this function for informational purposes only. Your code should not assume that the character encoding returned by this function is the Palm OS system's character encoding. (Instead use FtrGet as shown in the TxtCharXAttr function description.)

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtCharEncoding, TxtMaxEncoding



TxtTransliterate

Purpose

Converts the specified number of bytes in a text buffer using the specified operation.

Prototype

Err TxtTransliterate (const Char* inSrcText, UInt16 inSrcLength, Char* outDstText, UInt16* ioDstLength, TranslitOpType inOp)

Parameters

  -> inSrcText
Pointer to a text buffer. Must not be NULL.
  -> inSrcLength
The length in bytes of inSrcText.
  <- outDstText
The output buffer containing the converted characters.
  <->ioDstLength
Upon entry, the maximum length of outDstText. Upon return, the actual length of outDstText.
  -> inOp
A 16-bit unsigned value that specifies which transliteration operation is to be performed. The values possible for this field are specific to the character encoding used on a particular device. These operations are universally available:
  translitOpUpperCase
Converts the character to uppercase letters.
  translitOpLowerCase
Converts the characters to lowercase letters.
  translitOpPreprocess
Don't actually perform the operation. Instead, return in ioDstLength the amount of space required for the output text.

Result

Returns one of the following values:

0 Success
txtErrUnknownTranslitOp inOp's value is not recognized
txtErrTranslitOverrun If inSrcText and outDstText point to the same memory location and the operation has caused the function to overwrite unprocessed data in the input buffer.
txtErrTranslitOverflow If outDstText is not large enough to contain the converted string.

Comments

inSrcText and outDstText may point to the same location if you want to perform the operation in place. However, you should be careful that the space required for outDstText is not larger than inSrcText so that you don't generate a txtErrTranslitOverrun error.

For example, suppose on a Shift JIS encoded system, you want to convert a series of single-byte Japanese Katakana symbols to double-byte Katakana symbols. You cannot perform this operation in place because it replaces a single-byte character with a multi-byte character. When the first converted character is written to the buffer, it overwrites the second input character. Thus, a text overrun has occurred.

You can ensure that you have enough space for the output by ORing your chosen operation with translitOpPreprocess. For example, to convert a string to uppercase letters, do the following:

outSize = buf2Len;
error = TxtTransliterate(buf1, buf1len, &buf2, &outSize, translitOpUpperCase|translitOpPreprocess);

if (outSize > buf2len)
/* allocate more memory for buf2 */

error = TxtTransliterate(buf1, buf1Len, &buf2, &outSize, translitOpUpperCase);

You must make sure that the parameter inSrcText points to the start of a valid character. That is, it must point to the first byte of a multi-byte character or it must point to a single-byte character. If it doesn't, results are unpredictable.

Compatibility

Implemented only if International Feature Set is present.



TxtWordBounds

Purpose

Find the boundaries of a word of text that contains the character starting at the specified offset.

Prototype

Boolean TxtWordBounds (const Char* inText, UInt32 inLength, UInt32 inOffset, UInt32* outStart, UInt32* outEnd)

Parameters

  -> inText
Pointer to a text buffer. Must not be NULL.
  -> inLength
The length in bytes of the text pointed to by inText.
  -> inOffset
A valid offset into the text buffer inText. This offset must point to the beginning of a character.
  <- outStart
The starting offset of the text word.
  <- outEnd
The ending offset of the text word.

Result

Returns true if a word is found. Returns false if the word doesn't exist or is punctuation or whitespace.

Comments

Assuming the ASCII encoding, if the text buffer contains the string "Hi! How are you?" and you pass 5 as the offset, TxtWordBounds returns the start and end of the word containing the character at offset 5, which is the character "o". Thus, outStart and outEnd would point to the start and end of the word "How".

You must make sure that the parameter inText points to the start of a valid character. That is, it must point to the first byte of a multi-byte character or it must point to a single-byte character. If it doesn't, results are unpredictable.

Compatibility

Implemented only if International Feature Set is present.

See Also

TxtCharBounds, TxtCharIsDelim


Palm OS SDK Reference

  Previous Page Table of Contents Index Next Page  

This is page 49 of 85 in this book

Palm Computing Platform Development Zone
Copyright © 2000, Palm, Inc. All rights reserved.