OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
gsStringUtil.h
1
3#ifndef __STRINGUTIL_H__
4#define __STRINGUTIL_H__
5
6
7// String utilities used by the SDKs
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13
16#ifdef _PS2
17#define ALIGNED __attribute__ ((aligned(16)))
18#else
19#define ALIGNED
20#endif
21
22#define UCS2Char unsigned short
23#define UCS2String unsigned short* // null terminated
24#define UTF8ByteType unsigned char // For type casting
25#define UTF8String char* // may not be NULL terminated when treated as a single character
26
29#define UTF8_FOLLOW_BYTE_TAG 0x80 //:1000 0000 // Identifies 2nd or 3rd byte of UTF8String
30#define UTF8_TWO_BYTE_TAG 0xC0 //:1100 0000 // Identifies start of Two-byte UTF8String
31#define UTF8_THREE_BYTE_TAG 0xE0 //:1110 0000 // Identifies start of Three-byte UTF8String
32#define UTF8_FOUR_BYTE_TAG 0xF0 //:1111 0000 // Unsupported tag, need USC4 to store this
33
34#define UTF8_FOLLOW_BYTE_MASK 0x3F //:0011 1111 // The value bits in a follow byte
35#define UTF8_TWO_BYTE_MASK 0x1F //:0001 1111 // The value bits in a two byte tag
36#define UTF8_THREE_BYTE_MASK 0x0F //:0000 1111 // The value bits in a three byte tag
37
38#define UTF8_IS_THREE_BYTE(a) (((UTF8ByteType)a & UTF8_FOUR_BYTE_TAG)==UTF8_THREE_BYTE_TAG)
39#define UTF8_IS_TWO_BYTE(a) (((UTF8ByteType)a & UTF8_THREE_BYTE_TAG)==UTF8_TWO_BYTE_TAG)
40#define UTF8_IS_FOLLOW_BYTE(a) (((UTF8ByteType)a & UTF8_TWO_BYTE_TAG)==UTF8_FOLLOW_BYTE_TAG)
41#define UTF8_IS_SINGLE_BYTE(a) ((UTF8ByteType)a <= 0x7F) // 0-127
42
43#define REPLACE_INVALID_CHAR '?' // Replace invalid UTF8 chars with this
44
47// Prototypes
48// '_' denotes internal use functions
49int _ReadUCS2CharFromUTF8String (const UTF8String theUTF8String, UCS2Char* theUnicodeChar, int theMaxLength);
50int _UCS2CharToUTF8String (UCS2Char theUCS2Char, UTF8String theUTF8String);
51int _UCS2ToUTF8ConversionLengthOnly (const UCS2String theUCS2String);
52int _UTF8ToUCS2ConversionLengthOnly (const UTF8String theUTF8String);
53
54// Convert string types
55int AsciiToUTF8String(const char* theAsciiString, UTF8String theUTF8String );
56int UTF8ToAsciiString(const UTF8String theUTF8String, char* theAsciiString);
57int UCS2ToUTF8String (const UCS2String theUCS2String, UTF8String theUTF8String );
58int UTF8ToUCS2String (const UTF8String theUTF8String, UCS2String theUCS2String );
59int UCS2ToAsciiString(const UCS2String theUCS2String, char* theAsciiString);
60int AsciiToUCS2String(const char* theAsciiString, UCS2String theUCS2String );
61
62// Convert with maximum buffer length
63// similar to strncpy
64//int UCS2ToUTF8StringLength(const UCS2String theUCS2String, UTF8String theUTF8String, int theMaxLength);
65int UTF8ToUCS2StringLen(const UTF8String theUTF8String, UCS2String theUCS2String, int theMaxLength);
66
67// Convert a string, allocate space for the new string
68UTF8String UCS2ToUTF8StringAlloc(const UCS2String theUCS2String);
69UCS2String UTF8ToUCS2StringAlloc(const UTF8String theUTF8String);
70
71// Convert an array of strings, allocate space for the new strings
72UTF8String* UCS2ToUTF8StringArrayAlloc(const UCS2String* theUCS2StringArray, int theNumStrings);
73UCS2String* UTF8ToUCS2StringArrayAlloc(const UTF8String* theUTF8StringArray, int theNumStrings);
74
75
78#ifdef __cplusplus
79} // extern "C"
80#endif
81
82#endif // __STRINGUTIL_H__
83