There are two types of comparison function:
Alphanumeric and special character are contained in DBCS code pages as well as in SBCS code pages. Currently most products treat DBCS alphanumeric and special characters differently from those of SBCS. The treatment depends on the characteristics of your product.
For example, in a text retrieval function, an option to treat DBCS alphanumeric characters the same as SBCS is desired like SBCS users want an option to ignore upper or lowercase of alphabetic characters.
If you are going to support this option, see DBCS Alphanumeric Characters
When handling SBCS/DBCS mixed strings, care must be taken to find a matching string in a target. It is important to recognize characters, not just byte comparisons, because some byte values may occur as either an SBCS character or as the second byte of a DBCS character. This can be handled by doing character (one or two byte) comparisons aligned on character boundaries.
See also Comparison for handling of DBCS alphanumeric and special characters.
Suppose your program supports two global search characters, '*' and '?': to represent any number of SBCS characters, '?' to represent any single SBCS character. If an entry field accepts both DBCS and SBCS characters, use the '*' to represent a string of any SBCS or DBCS characters. Use the '?' to represent any single DBCS or SBCS character in that position. However, if users can only type DBCS characters into an entry field, the DBCS '*' represents any string of any DBCS character. The DBCS '?' represents any single DBCS character in that position.
Example search argument target result /D1*D2/ D1DjD2 matched D1ssD2 matched D1sD2 matched D1D2 matched /D1?D2/ D1DjD2 matched D1ssD2 unmatched D1sD2 matched D1D2 unmatched where '*' and '?' denotes SBCS wild card character.
Note:
A Parser scans a given string, performs syntax checks and decomposes the strings following a well-defined format or set of rules. The fundamental requirement is to ensure that character comparisons are done rather than byte comparisons. This requires that all checks for syntactically significant characters observe character boundaries and character sizes in all cases.
For example, when a parser searches for a single byte delimiter, it must be careful to ignore bytes which occur within two byte characters.
CHANGE |DjDiDj|DjDjDj| where | = 7CH Di = 817CH
The second byte of Di must not be considered as a delimiter. It is part of a character and must retain its identity as such.
A program sometimes needs to change portions of a text string at execution time. A changeable portion is defined in a string by a substitutable variable and replaced with a real value at execution time. A substitution operation can be considered as a combination of search, deletion and insertion operations. See Search and Insertion.
Messages are a good example of variable substitution. Messages often contain information regarding what data is wrong during execution. Variable substitution can also occur in the literal portion or the text portion of panels.
Example of Variable Substitution in a Message - Message Format = STRING &VAR FOUND ('&' is prefixed to substitution variables.) - IF &VAR = ABC THEN "STRING ABC FOUND" SBCS substitution - IF &VAR = D1D2 THEN "STRING D1D2 FOUND" DBCS substitution
CHANGE operation for SBCS/DBCS mixed strings requires no special consideration beyond that of searching for the original string and substituting the new string. Both these operations have already been covered.
Original Change Result abcde abcde to lmnop lmnop abcde bcd to D1 aD1e abcde abcde to D1D2 D1D2 D1D2D3 D1D2D3 to abcde abcde D1D2D3 D2 to DX D1DXD3 D1D2D3 D2 to a D1aD3