
Character Sorting
|
605
combines the rst two macros. Quite oen you won’t care whether a kanji is in JIS Level
1 or 2 kanji, but rather if it is a kanji at all. Again, it is sucient to use only the rst byte
as input to this macro.
e next three macros:
#define ISHIRAGANA(A) (A == 4)
#define ISKATAKANA(A) (A == 5)
#define ISKANA(A) (ISHIRAGANA(A) || ISKATAKANA(A))
do the same as the rst three macros, but with kana. e rst two detect whether a char-
acter is a hiragana or katakana, and the last one combines them. Like before, only the rst
byte is used for this.
e last macro:
#define ISKANAKANJI(A) (ISKANA(A) || ISKANJI(A))
checks for a larger set of characters, kana and kanji.
Similar macros can be written to accommodate other languages, such as Korean (KS X
1001:2004):
#define ISJAMO(A) (A == 4)
#define ISHANGUL(A) (A >= 16 && A <= 40)
#define ISHANJA(A) (A >= 42 && A <= 93)
#define ISHANGULHANJA(A) (ISHANGUL(A) || ISHANJA(A))
and Chinese (GB 2312-80):
#define ISLEVEL1(A) (A >= 16 && A <= 55)
#define ISLEVEL2(A) (A >= 56 && A <= 87)
#define ISHANZI(A) (ISLEVEL1(A) || ISLEVEL2(A))
Writing such macro denitions can be carried to almost any extreme, and represents a
very useful tool in the hands of a C or C++ programmer. Of course, these macros could
have been implemented as C functions or written in yet other programming languages.
Character Sorting
You can sort English text in a multitude of ...