mirror of https://github.com/OpenTTD/OpenTTD
Codechange: introduce string::iterator aware Utf8Decode, Utf8Encode and Utf8PrevChar
parent
672c5f0d98
commit
ad8f394835
|
@ -76,9 +76,11 @@ inline size_t ttd_strnlen(const char *str, size_t maxlen)
|
||||||
bool IsValidChar(char32_t key, CharSetFilter afilter);
|
bool IsValidChar(char32_t key, CharSetFilter afilter);
|
||||||
|
|
||||||
size_t Utf8Decode(char32_t *c, const char *s);
|
size_t Utf8Decode(char32_t *c, const char *s);
|
||||||
|
inline size_t Utf8Decode(char32_t *c, std::string::iterator &s) { return Utf8Decode(c, &*s); }
|
||||||
size_t Utf8Encode(char *buf, char32_t c);
|
size_t Utf8Encode(char *buf, char32_t c);
|
||||||
size_t Utf8Encode(std::ostreambuf_iterator<char> &buf, char32_t c);
|
size_t Utf8Encode(std::ostreambuf_iterator<char> &buf, char32_t c);
|
||||||
size_t Utf8Encode(std::back_insert_iterator<std::string> &buf, char32_t c);
|
size_t Utf8Encode(std::back_insert_iterator<std::string> &buf, char32_t c);
|
||||||
|
inline size_t Utf8Encode(std::string::iterator &s, char32_t c) { return Utf8Encode(&*s, c); }
|
||||||
size_t Utf8TrimString(char *s, size_t maxlen);
|
size_t Utf8TrimString(char *s, size_t maxlen);
|
||||||
|
|
||||||
|
|
||||||
|
@ -160,6 +162,13 @@ inline const char *Utf8PrevChar(const char *s)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline std::string::iterator Utf8PrevChar(std::string::iterator &s)
|
||||||
|
{
|
||||||
|
auto *cur = &*s;
|
||||||
|
auto *prev = Utf8PrevChar(cur);
|
||||||
|
return s - (cur - prev);
|
||||||
|
}
|
||||||
|
|
||||||
size_t Utf8StringLength(const char *s);
|
size_t Utf8StringLength(const char *s);
|
||||||
size_t Utf8StringLength(const std::string &str);
|
size_t Utf8StringLength(const std::string &str);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue