MCPcopy Create free account
hub / github.com/DFHack/dfhack / fromLocaleMB

Function fromLocaleMB

library/Console-posix.cpp:166–182  ·  view source on GitHub ↗

Convert a locale defined multibyte coding to UTF-32 string for easier character processing.

Source from the content-addressed store, hash-verified

164//! Convert a locale defined multibyte coding to UTF-32 string for easier
165//! character processing.
166static u32string fromLocaleMB(const std::string& str)
167{
168 u32string rv;
169 u32string::value_type ch;
170 size_t pos = 0;
171 ssize_t sz;
172 std::mbstate_t state{};
173 while ((sz = mbrtoc32(&ch,&str[pos], str.size() - pos, &state)) != 0) {
174 if (sz == -1 || sz == -2)
175 break;
176 rv.push_back(ch);
177 if (sz == -3) /* multi value character */
178 continue;
179 pos += sz;
180 }
181 return rv;
182}
183
184//! Convert a UTF-32 string back to locale defined multibyte coding.
185static std::string toLocaleMB(const u32string& wstr)

Callers 1

prompt_loopMethod · 0.85

Calls 2

mbrtoc32Function · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected