Guardian Programmer's Guide

Table Of Contents
Formatting and Manipulating Character Data
Guardian Programmer’s Guide 421922-014
19 - 56
Sample Program
To use the MBCS_TESTBYTE_ procedure, you must supply it with the buffer
containing the string to be tested, the length of the buffer, and an index into the buffer
identifying the byte to be tested. The following example scans a text string searching
for a special character, then checks whether that byte is part of a multibyte character
set:
SCAN SBUFFER UNTIL SPECIAL -> @SPECIAL^CHARACTER;
TEST^INDEX := @SPECIAL^CHARACTER - @SBUFFER;
RESULT := MBCS_TESTBYTE_(BUFFER,
BUFFER^LENGTH,
TEST^INDEX);
The value returned in RESULT indicates what happened:
The testindex parameter contains the byte index to the first byte of the character.
Sample Program
The following program uses many of the system procedures that support multibyte
characters. The program is similar to the program shown earlier in this section to
illustrate the use of the FIXSTRING procedure. This example, however, implements
an FC command for an environment that uses multibyte characters.
The enhancements made to the program shown below are as follows:
The INITIALIZE^TERMINAL procedure uses the
MBCS_CODESETS_SUPPORTED_ procedure to check whether multibyte code
sets are supported. If not, then the program stops.
The COMMAND^INTERPRETER procedure uses the MBCS_TRIMFRAGMENT_
procedure to check that the last bytes of the entered command are not a fragment
of a multibyte character, and then uses the MBCS_REPLACEBLANK_ procedure
to convert any multibyte blanks into double ASCII blank characters.
The FC procedure also uses the MBCS_TRIMFRAGMENT_ and
MBCS_REPLACEBLANK_ procedures to process the string again after editing.
If RESULT is... Then the byte identified by the test-index parameter is...
0 A single-byte character
1 The first byte of a multibyte character
2 An intermediate byte (neither first or last byte) of a multibyte character
3 The last byte of a multibyte character