Guardian Programmer's Guide

Table Of Contents
Formatting and Manipulating Character Data
Guardian Programmer’s Guide 421922-014
19 - 55
Case Shifting With Multibyte Characters
character size. To find the character size of a multibyte character set, use the
MBCS_CHARSIZE_ procedure.
To use the MBCS_CHARSIZE_ procedure, you must supply it with the number of the
character set (as returned by the MBCS_CODESETS_SUPPORTED_ procedure).
You receive the number of bytes per character in the return value:
RESULT := MBCS_CHARSIZE_(CHARACTER^SET);
Case Shifting With Multibyte Characters
Usually you can use the SHIFTSTRING procedure (or CASECHANGE or
STRING_UPSHIFT_) to upshift or downshift a string of multibyte characters or
multibyte characters mixed with single-byte (ASCII) characters. The following example
upshifts a string provided in the TEXT^STRING buffer:
CASE^BIT := 0; !zero for upshifting
CALL SHIFTSTRING(TEXT^STRING,
BYTE^COUNT,
CASE^BIT);
As with all string-manipulation operations that involve multibyte characters, you must
start your upshift or downshift operation on the first byte of a character. You can arrive
at a first byte either by pointing to the first byte of a string or by using an
MBCS_CHAR_ procedure call.
The SHIFTSTRING, CASECHANGE, or STRING_UPSHIFT_ procedures will work with
multibyte characters, because your system is configured with versions of these
procedures that work for your default character set. If you need to apply a string-shift
operation to a string of text that does not belong to the default character set, you must
instead use the MBCS_SHIFTSTRING_ procedure. The following call does the same
thing as the SHIFTSTRING example above but for a different character set:
CASE^BIT := 0; !zero for upshifting
CHAR^SET := 9; !Tandem Hangul
CALL MBCS_SHIFTSTRING_(@TEXT^STRING, !string to upshift
BYTE^COUNT, !number of bytes
CASE^BIT,
CHAR^SET);
Testing for Special Symbols
It is possible that special symbols used in a single-byte character set may appear as
one byte of a multibyte character. It would be a mistake to interpret these bytes as
single-byte special symbols. You should therefore test such a byte to see if it is part of
a multibyte character.
To test for special symbols that are part of multibyte characters, you can use the
MBCS_TESTBYTE_ procedure. First, you would scan the string for the special
symbol, then call MBCS_TESTBYTE_ to check whether the byte is a single-byte
character or part of a multibyte character.