本文整理汇总了C++中utf8_string::size方法的典型用法代码示例。如果您正苦于以下问题:C++ utf8_string::size方法的具体用法?C++ utf8_string::size怎么用?C++ utf8_string::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utf8_string
的用法示例。
在下文中一共展示了utf8_string::size方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: slice_from
static utf8_string split_word(const TextInfo& info,
const utf8_string& string,
text_lines_t& result)
{
// Just break the word in half.
const utf8_string half(slice_up_to(string, string.size() / 2));
const coord width = info.GetWidth(half);
result.push_back(TextLine::SoftBreak(width, half));
return slice_from(string, string.size() / 2);
}
示例2: split_string
text_lines_t split_string(const TextInfo& info,
const utf8_string& string,
const max_width_t& maxWidth)
{
size_t lineEnd = 0;
size_t lineStart = 0;
text_lines_t result;
do {
lineEnd = string.find(chars::eol, lineStart);
bool softBreak = lineEnd == std::string::npos;
if (softBreak){
lineEnd = string.size();
}
const coord width = info.GetWidth(slice(string, lineStart, lineEnd));
if (maxWidth.NotSet() || width < maxWidth.Get()){
if (softBreak){
result.push_back(TextLine::SoftBreak(width,
slice(string, lineStart, lineEnd) + chars::space));
lineStart = lineEnd + 1;
}
else{
result.push_back(TextLine::HardBreak(width,
slice(string, lineStart, lineEnd) + chars::space));
lineStart = lineEnd + 1;
}
}
else{
split_line(info, slice(string, lineStart, lineEnd),
maxWidth.Get(), result);
lineStart = lineEnd;
}
} while (lineEnd != string.size());
if (!result.empty()){
// Remove trailing space from last line
auto& last = result.back().text;
last = slice_up_to(last, -1);
}
return result;
}
示例3: split_line
// Split a line at suitable positions to make it shorter than
// maxWidth. The line should not contain embedded line breaks.
static void split_line(const TextInfo& info,
const utf8_string& string,
coord maxWidth, text_lines_t& result)
{
size_t wordStart = 0;
size_t wordEnd = 0;
utf8_string line;
do {
wordEnd = string.find(chars::space, wordStart);
if (wordEnd == std::string::npos){
wordEnd = string.size();
}
utf8_string word = slice(string, wordStart, wordEnd);
const coord width = info.GetWidth(line + chars::space + word);
if (!line.empty() && width > maxWidth){
result.push_back(TextLine::SoftBreak(width, line + chars::space));
line.clear();
}
if (info.GetWidth(word) > maxWidth){
word = split_word(info, word, result);
}
if (!line.empty()){
line += chars::space;
}
line += word;
wordStart = wordEnd + 1;
} while (wordEnd != string.size());
if (line.size() > 1){
const utf8_string last(line + chars::space);
const coord width = info.GetWidth(last);
result.push_back(TextLine::SoftBreak(width, last));
}
}
示例4: prepare_frame
binary_string_ptr prepare_frame(frame::opcode::value opcode,
bool mask,
const utf8_string& payload) {
if (opcode != frame::opcode::TEXT) {
// TODO: hybi_legacy doesn't allow non-text frames.
throw;
}
// TODO: mask = ignore?
// TODO: utf8 validation on payload.
binary_string_ptr response(new binary_string(payload.size()+2));
(*response)[0] = 0x00;
std::copy(payload.begin(),payload.end(),response->begin()+1);
(*response)[response->size()-1] = 0xFF;
return response;
}
示例5: InputState
InputState(const utf8_string &text)
: text(text), cursor_position(text.size())
{}
示例6: utf
inline string_t utf(utf8_string const& str)
{
return aux::converter<char_t>::utf(str.c_str(), str.size());
}
示例7:
inline utf32_string utf32(utf8_string const& str)
{
return aux::converter<utf32_char>::utf(str.c_str(), str.size());
}
示例8: while
/// Convert UTF-8 to UTF-16.
utf16_string Halyard::utf16_from_utf8(const utf8_string &utf8) {
utf16_string result;
result.reserve(utf8.size());
// Suppress GCC warning about possibly undefined variable.
wchar_t wc = 0;
size_t i = 0;
while (i < utf8.size()) {
char init = utf8[i];
if ((init & 0x80) == 0x00) {
// Convert ASCII character to wide character.
wc = init;
i++;
} else {
// Look up the length of this UTF-8 sequence.
size_t length = utf8_seq_length[(unsigned char) init];
// Check to make sure we have enough bytes to convert.
CHECK(i + length <= utf8.size(), "Truncated UTF-8 sequence");
// Decode a multibyte UTF-8 sequence.
char con1;
char con2;
switch (length) {
case 0:
THROW("Invalid UTF-8 initial byte");
case 2:
// 110xxxxx 10xxxxxx
con1 = utf8[i+1];
CHECK(IS_CONTINUATION(con1), "UTF-8 sequence too short");
wc = ((((wchar_t) (init & 0x1F)) << 6) |
(((wchar_t) (con1 & 0x3F))));
break;
case 3:
// 1110xxxx 10xxxxxx 10xxxxxx
con1 = utf8[i+1];
con2 = utf8[i+2];
CHECK(IS_CONTINUATION(con1) && IS_CONTINUATION(con2),
"UTF-8 sequence too short");
wc = ((((wchar_t) (init & 0x0F)) << 12) |
(((wchar_t) (con1 & 0x3F)) << 6) |
(((wchar_t) (con2 & 0x3F))));
break;
case 4:
// 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
case 5:
// 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
case 6:
// 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
THROW("UCS-4 characters not supported");
default:
gLog.Fatal("halyard", "Error in UTF-8 decoder tables");
}
// Advance to the end of the sequence.
i += length;
// Check for illegal UCS-2 characters.
CHECK(wc <= UCS2_MAX_LEGAL_CHARACTER,
"UCS-2 characters > U+FFFD are illegal");
// Check for UTF-16 surrogates.
CHECK(wc < UTF16_FIRST_SURROGATE || UTF16_LAST_SURROGATE < wc,
"UTF-16 surrogates may not appear in UTF-8 data");
// Check for overlong sequences.
CHECK(wc >= utf8_min_char_for_length[length],
"Overlong UTF-8 sequence not allowed");
}
// Append the decoded character to our result.
result.push_back(wc);
}
return result;
}