INFORMIX
INFORMIX-GLS Programmer's Guide
Chapter 2: Character Processing
Home Contents Index Master Index New Book

String Operations

The INFORMIX-GLS library supports the following string operations on multibyte-character and wide-character strings:

For more information about any of the INFORMIX-GLS functions that this section describes, see the function descriptions in Chapter 4, "INFORMIX-GLS Function Descriptions."

String Traversal

Because a single-byte character occupies only one byte, string traversal of a single-byte character string can use the C compiler built-in scaling. However, you must take special steps to handle string traversal of multibyte-character and wide-character strings.

Multibyte-Character-String Traversal

Because a multibyte-character string might contain multibyte characters of different sizes, you cannot automatically traverse the string with any built-in scaling. Instead, use the following functions in INFORMIX-GLS to traverse a multibyte string:

These functions support string traversal in the following directions:

Wide-Character-String Traversal

A wide-character string consists of fixed-length characters. The INFORMIX-GLS library does not need to provide traversal functions for wide-character strings because you can traverse the string with C compiler built-in scaling. However, the library does provide the ifx_gl_wcslen() function, which determines the number of bytes in a wide-character string.

The INFORMIX-GLS library supports wide-character string traversal in the following directions:

String Processing

The INFORMIX-GLS library provides functions for the following string-processing tasks:

The INFORMIX-GLS library provides both multibyte and wide-character functions for these string-processing tasks.

Concatenation

Concatenation is the process of appending one string to the end of another string. The following table lists the INFORMIX-GLS multibyte functions and their wide-character equivalents that perform string concatenation.
Concatenation Operation Multibyte-Character
Function
Wide-Character
Function

Append a copy of one character string to the end of another character string. If the two strings overlap, the result of the operation is undefined.

ifx_gl_mbscat()

ifx_gl_wcscat()

Append a specified number of characters from one character string to the end of a second character string. If the two strings overlap, the result of this operation is undefined.

ifx_gl_mbsncat()

ifx_gl_wcsncat()

String Copying

The following table lists the INFORMIX-GLS multibyte functions and their wide-character equivalents that perform string copying.
String-Processing Task Multibyte-Character
Function
Wide-Character
Function

Copy one character string to a specified location in a second character string. If the two strings overlap, the result of this operation is undefined.

ifx_gl_mbscpy()

ifx_gl_wcscpy()

Copy a specified number of characters from one character string to a second character string. If the two strings overlap, the result of this operation is undefined.

ifx_gl_mbsncpy()

ifx_gl_wcsncpy()

String-Length Determination

The following table lists the INFORMIX-GLS multibyte functions and their wide-character equivalents that determine string length or number of characters.

(1 of 2)

String-Length Task Multibyte-Character
Function
Wide-Character
Function

Determine the number of characters in the string, not including any terminating null characters.

ifx_gl_mbslen()

ifx_gl_wcslen()

Determine the number of bytes in a multibyte string, not including any trailing space characters.

ifx_gl_mbsntsbytes()

None

Determine the number of characters in a string, not including the trailing space characters.

ifx_gl_mbsntslen()

ifx_gl_wcsntslen()

Determine the number of characters in the initial substring of one string that consists entirely of characters in a second specified character string.

ifx_gl_mbsspn()

ifx_gl_wcsspn()

Determine the number of characters in the initial substring of one string that consists entirely of characters not in a specified second character string.

ifx_gl_mbscspn()

ifx_gl_wcscspn()

Character Searching

The following table lists the INFORMIX-GLS multibyte functions and their wide-character equivalents that perform character searching.
Character-Searching Task Multibyte-Character
Function
Wide-Character
Function

Search for the first occurrence of a character in the character string.

ifx_gl_mbschr()

ifx_gl_wcschr()

Search for the last occurrence of a character in the character string.

ifx_gl_mbsrchr()

ifx_gl_wcsrchr()

Search for a substring in another string.

ifx_gl_mbsmbs()

ifx_gl_wcswcs()

Search for the first occurrence in the character string of any character from a second specified character string.

ifx_gl_mbspbrk()

ifx_gl_wcspbrk()

Character/String Comparison and Sorting

Collation involves the sorting of character data that is either stored in a database or manipulated in a client application. Informix database servers support the following methods of collation for character data:

    The order of the code points in the code set determines the sort order.

    The LC_COLLATE category of a GLS locale file defines the order of the characters in the localized order.

Tip: For more information on code-set and localized collation order, see the "Informix Guide to GLS Functionality."
To perform code-set collation, you compare only the integer values of two multibyte or two wide characters. For example, suppose one multibyte character, mbs1, contains the value A1A2A3 and a second multibyte character, mbs2, contains the value B1B2B3. If the integer value of A1A2A3 is less than the integer value of B1B2B3, then mbs1 is less than mbs2 in code-set collation order.

However, sometimes you want to sort character data according to the language usage of the characters. In code-set order, the character a is greater than the character A. In many contexts, you would probably not want the string Apple to sort before the string apple. The localized order could list the character A after the character a. Similarly, even though the character À might have a code point of 133, the localized order could list this character after A and before B (A=65, À=133, B=66). In this case, the string ÀB sorts after AC but before BD.

The following table lists the INFORMIX-GLS functions that use localized collation order to compare two multibyte-character or wide-character strings.
String-Comparison Task Multibyte-Character
Function
Wide-Character
Function

Compare two character strings by localized collation order.

ifx_gl_mbscoll()

ifx_gl_wcscoll()

These functions access the LC_COLLATE category of a locale file to obtain localized collating information when they compare character strings. They return an integer value that indicates the results of the comparison between two string arguments. The following table shows the comparison between the first string argument (Arg 1) and the second string argument (Arg 2), as well as the return values.
Argument Comparison Return Value

Arg 1 < Arg 2

<0

Arg 1 = Arg 2

0

Arg 1 > Arg 2

>0

The ifx_gl_mbscoll() and ifx_gl_wcscoll() functions do not return a special value if an error has occurred. Therefore, to detect an error condition, you must initialize the ifx_gl_lc_errno() error number to zero before you call one of these functions and check ifx_gl_lc_errno() after you call the function. The following code fragment performs error checking for a call to the ifx_gl_wcscoll() function:




INFORMIX-GLS Programmer's Guide, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.