31 |
33 |
32 /** Scans the string for colour codes and strips them */ |
34 /** Scans the string for colour codes and strips them */ |
33 void str_strip_colours(char *str); |
35 void str_strip_colours(char *str); |
34 |
36 |
35 /** |
37 /** |
36 * Valid filter types for IsValidAsciiChar. |
38 * Valid filter types for IsValidChar. |
37 */ |
39 */ |
38 typedef enum CharSetFilter { |
40 typedef enum CharSetFilter { |
39 CS_ALPHANUMERAL, //! Both numeric and alphabetic and spaces and stuff |
41 CS_ALPHANUMERAL, //! Both numeric and alphabetic and spaces and stuff |
40 CS_NUMERAL, //! Only numeric ones |
42 CS_NUMERAL, //! Only numeric ones |
41 CS_ALPHA, //! Only alphabetic values |
43 CS_ALPHA, //! Only alphabetic values |
42 } CharSetFilter; |
44 } CharSetFilter; |
|
45 |
|
46 /** Convert the given string to lowercase */ |
|
47 void strtolower(char *str); |
|
48 |
|
49 typedef uint32 WChar; |
43 |
50 |
44 /** |
51 /** |
45 * Only allow certain keys. You can define the filter to be used. This makes |
52 * Only allow certain keys. You can define the filter to be used. This makes |
46 * sure no invalid keys can get into an editbox, like BELL. |
53 * sure no invalid keys can get into an editbox, like BELL. |
47 * @param key character to be checked |
54 * @param key character to be checked |
48 * @param afilter the filter to use |
55 * @param afilter the filter to use |
49 * @return true or false depending if the character is printable/valid or not |
56 * @return true or false depending if the character is printable/valid or not |
50 */ |
57 */ |
51 bool IsValidAsciiChar(byte key, CharSetFilter afilter); |
58 bool IsValidChar(WChar key, CharSetFilter afilter); |
52 |
59 |
53 /** Convert the given string to lowercase */ |
60 size_t Utf8Decode(WChar *c, const char *s); |
54 void strtolower(char *str); |
61 size_t Utf8Encode(char *buf, WChar c); |
|
62 |
|
63 |
|
64 static inline WChar Utf8Consume(const char **s) |
|
65 { |
|
66 WChar c; |
|
67 *s += Utf8Decode(&c, *s); |
|
68 return c; |
|
69 } |
|
70 |
|
71 |
|
72 /** Return the length of a UTF-8 encoded character. |
|
73 * @param c Unicode character. |
|
74 * @return Length of UTF-8 encoding for character. |
|
75 */ |
|
76 static inline size_t Utf8CharLen(WChar c) |
|
77 { |
|
78 if (c < 0x80) return 1; |
|
79 if (c < 0x800) return 2; |
|
80 if (c < 0x10000) return 3; |
|
81 if (c < 0x110000) return 4; |
|
82 |
|
83 /* Invalid valid, we encode as a '?' */ |
|
84 return 1; |
|
85 } |
|
86 |
|
87 |
|
88 /* Check if the given character is part of a UTF8 sequence */ |
|
89 static inline bool IsUtf8Part(char c) |
|
90 { |
|
91 return GB(c, 6, 2) == 2; |
|
92 } |
|
93 |
|
94 |
|
95 static inline bool IsPrintable(WChar c) |
|
96 { |
|
97 if (c < 0x20) return false; |
|
98 if (c < 0xE000) return true; |
|
99 if (c < 0xE200) return false; |
|
100 return true; |
|
101 } |
|
102 |
55 |
103 |
56 #endif /* STRING_H */ |
104 #endif /* STRING_H */ |