104 static inline bool IsUtf8Part(char c) |
104 static inline bool IsUtf8Part(char c) |
105 { |
105 { |
106 return GB(c, 6, 2) == 2; |
106 return GB(c, 6, 2) == 2; |
107 } |
107 } |
108 |
108 |
|
109 /** |
|
110 * Retrieve the (partial) length of the previous UNICODE character |
|
111 * in an UTF-8 encoded string. |
|
112 * @param s char pointer pointing to the first char of the next character |
|
113 * @returns the decoded length in bytes (size) of the UNICODE character |
|
114 * that was just before the one where 's' is pointing to |
|
115 * @note If 's' is not pointing to the first byte of the next UNICODE character |
|
116 * only a partial length of the sequence will be returned. |
|
117 * For example given this sequence: 0xE3 0x85 0x80, 0xE3 0x81 0x9E |
|
118 * 1. 's' is pointing to the second 0xE3, return value is 3 |
|
119 * 2. 's' is pointing to 0x80, return value is 2. |
|
120 * So take care with the return values of this function. To get the real length |
|
121 * for an (invalid) sequence, pass the string offset of this function's return |
|
122 * value to Utf8EncodedCharLen() or Utf8Decode() |
|
123 */ |
|
124 static inline size_t Utf8PrevCharLen(const char *s) |
|
125 { |
|
126 size_t len = 1; |
|
127 while (IsUtf8Part(*--s)) len++; |
|
128 return len; |
|
129 } |
|
130 |
109 |
131 |
110 static inline bool IsPrintable(WChar c) |
132 static inline bool IsPrintable(WChar c) |
111 { |
133 { |
112 if (c < 0x20) return false; |
134 if (c < 0x20) return false; |
113 if (c < 0xE000) return true; |
135 if (c < 0xE000) return true; |