PrevNextUpHome SophiaFramework UNIVERSE 5.3

11.3. Checking and Converting the Character

11.3.1. Checking and Converting the Character

The SFXAscii and SFXShiftJIS classes are used to check the character type and convert the character.

Example 11.25. Checking the Type of ASCII Character

AChar x('a'), y('7');

if (SFXAscii::IsAlpha(x)) {	

    // if x is an alphabet
    
}

if (SFXAscii::IsDigit(y)) {	

    // if y is a digit
	
}

Example 11.26. Checking the Type of Japanese(Shift_JIS) Character

SFXWideString wstr("あいうえおABCDE");

if (SFXShiftJIS::IsFullAlpha(wstr[6])) {	

    // if the 7th character of wstr is 2-byte alphabet
	
}

if (SFXShiftJIS::IsFullHiragana(wstr[3])) {	

    // if the 4th character of wstr is 2-byte Japanese Hiragana
	
}

Example 11.27. Converting ASCII Character

// convert character into lower-case
AChar character1 = SFXAscii::AsLower('A');

// convert character into upper-case
AChar character2 = SFXAscii::AsUpper('a');

Example 11.28. Converting Japanese(Shift_JIS) Character

SFXWideString wstr("あいうえおABCDE");

// convert wstr from Hiragana into Katakana
SFXShiftJIS::HiraganaToKatakana(&wstr);

// convert wstr from 1-byte alphabet into 2-byte alphabet
SFXShiftJIS::ToFullAlpha(&wstr);

11.3.2. Converting String Code

The SFXTextEncoding class is used to convert a string from one encoding into another.

Example 11.29. Converting String Code

SFXAnsiString shiftJIS_string("あいうえお"); // string before conversion(Shift_JIS)
SFXAnsiString utf8_string;                   // string after conversion(UTF-8)
SFXAnsiString utf16be_string;                // string after conversion(UTF-16BE)
SFCError error(SFERR_NO_ERROR);              // error value

// converting encoding from Shift_JIS to UTF-8
error = ShiftJISToUTF8(shiftJIS_string, &utf8_string);

// converting encoding from UTF-8 to UTF-16BE
error = UTF8ToUTF16BE(utf8_string, &utf16be_string);
[Note] Prerequisite

The above code is assumed to be encoded in Shift_JIS.

Table 11.3. Character Encoding Conversion Table

Before: After UTF-8 UTF-16BE UTF-16LE UTF-32BE UTF-32LE Shift_JIS EUC-JP EUC-CN
UTF-8   O O O O O O O
UTF-16BE O   X O O O O O
UTF-16LE O X   O O O O O
UTF-32BE O O O   X O O O
UTF-32LE O O O X   O O O
Shift_JIS O O O O O   O X
EUC-JP O O O O O O   X
EUC-CN O O O O O X X