本文整理汇总了C++中std::u16string::size方法的典型用法代码示例。如果您正苦于以下问题:C++ u16string::size方法的具体用法?C++ u16string::size怎么用?C++ u16string::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::u16string
的用法示例。
在下文中一共展示了u16string::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operator
void operator()(const std::u16string& str) {
m_serializer->acquire(sizeof(std::uint32_t) + str.size());
write_int(m_serializer, static_cast<std::uint32_t>(str.size()));
for (char16_t c : str) {
// force writer to use exactly 16 bit
write_int(m_serializer, static_cast<std::uint16_t>(c));
}
}
示例2: data
TEST(InputU16StringBufferTest, CopiesValue)
{
std::u16string const data(u"dummy data");
cpp_odbc::level2::input_u16string_buffer buffer(data);
ASSERT_EQ(data.size(), buffer.size());
for (std::size_t i = 0; i < data.size(); ++i) {
EXPECT_EQ(data[i], buffer.data_pointer()[i]);
}
}
示例3: calculateWord
TextFlow::Word TextFlow::calculateWord(std::u16string content, float scale) const
{
// Empty word
Word word;
word.spVertices = std::shared_ptr<std::vector<glm::vec3> >(new std::vector<glm::vec3>);
word.spTextureCoordinates = std::shared_ptr<std::vector<glm::vec2> >(new std::vector<glm::vec2>);
// Fill word with data
float xPixelPen = 0;
for (uint i = 0; i < content.size(); i++)
{
Glyph const * pGlyph = mpFont->getGlyph(mFontSize, content[i]);
if (pGlyph == NULL)
{
throwWarning(
OperationNotifier::Operation::RUNTIME,
"TextFlow has character in content not covered by character set");
continue;
}
float yPixelPen = 0 - (scale * (float)(pGlyph->size.y - pGlyph->bearing.y));
// Vertices for this quad
glm::vec3 vertexA = glm::vec3(xPixelPen, yPixelPen, 0);
glm::vec3 vertexB = glm::vec3(xPixelPen + (scale * pGlyph->size.x), yPixelPen, 0);
glm::vec3 vertexC = glm::vec3(xPixelPen + (scale * pGlyph->size.x), yPixelPen + (scale * pGlyph->size.y), 0);
glm::vec3 vertexD = glm::vec3(xPixelPen, yPixelPen + (scale * pGlyph->size.y), 0);
// Texture coordinates for this quad
glm::vec2 textureCoordinateA = glm::vec2(pGlyph->atlasPosition.x, pGlyph->atlasPosition.y);
glm::vec2 textureCoordinateB = glm::vec2(pGlyph->atlasPosition.z, pGlyph->atlasPosition.y);
glm::vec2 textureCoordinateC = glm::vec2(pGlyph->atlasPosition.z, pGlyph->atlasPosition.w);
glm::vec2 textureCoordinateD = glm::vec2(pGlyph->atlasPosition.x, pGlyph->atlasPosition.w);
xPixelPen += scale * pGlyph->advance.x;
// Fill into data blocks
word.spVertices->push_back(vertexA);
word.spVertices->push_back(vertexB);
word.spVertices->push_back(vertexC);
word.spVertices->push_back(vertexC);
word.spVertices->push_back(vertexD);
word.spVertices->push_back(vertexA);
word.spTextureCoordinates->push_back(textureCoordinateA);
word.spTextureCoordinates->push_back(textureCoordinateB);
word.spTextureCoordinates->push_back(textureCoordinateC);
word.spTextureCoordinates->push_back(textureCoordinateC);
word.spTextureCoordinates->push_back(textureCoordinateD);
word.spTextureCoordinates->push_back(textureCoordinateA);
}
// Set width of whole word
word.pixelWidth = xPixelPen;
return word;
}
示例4: binding_string
inline binding_string::binding_string(handles* hnd, size_t order, const std::string& str, ub1 cs_form) : m_str(brig::unicode::transform<char16_t>(str))
{
const size_t size((m_str.size() + 1) * sizeof(char16_t));
if (size > SHRT_MAX) throw std::runtime_error("OCI type error");
m_ind = OCIInd(size);
OCIBind* bnd(0);
hnd->check(lib::singleton().p_OCIBindByPos(hnd->stmt, &bnd, hnd->err, ub4(order), (void*)m_str.c_str(), m_ind, SQLT_STR, &m_ind, 0, 0, 0, 0, OCI_DEFAULT));
hnd->check(lib::singleton().p_OCIAttrSet(bnd, OCI_HTYPE_BIND, (void*)&cs_form, 0, OCI_ATTR_CHARSET_FORM, hnd->err));
} // binding_string::
示例5:
void LineEdit::IntValidator::erase(std::u16string &string,
size_t &scursor,
size_t &ecursor) const {
Validator::erase(string,scursor,ecursor);
if(string.size()==1 && string[0]=='-')
string[0] = '0';
if(string.empty())
string.push_back('0');
}
示例6: while
Value::
Value(const std::u16string& s):
type(ConstCharType().make_array(s.size()+1)),
base_address(0),
size(sizeof(char16_t)*(s.size()+1))
{
data = new uint8_t[size];
auto dst = reinterpret_cast<char16_t*>(data);
auto src = s.cbegin();
while(*src)
{
*dst++ = *src++;
}
dst = 0;
}
示例7: if
std::vector<TextFlow::Word> TextFlow::calculateFitWord(std::u16string content, int maxPixelWidth, float scale) const
{
// Calculate word from content
Word word = calculateWord(content, scale);
// End of recursion
if ((content.size() == 1 && word.pixelWidth > maxPixelWidth) || content.empty())
{
// Return empty vector as signal of failure
return std::vector<Word>();
}
else if (word.pixelWidth <= maxPixelWidth)
{
// If word length is ok, just return it
return std::vector<Word>(1, word);
}
else
{
// Word is too wide and content longer than 1, split it!
int length = (int)content.size();
int left = length / 2;
int right = length - left;
// Combine results from recursive call
std::vector<Word> leftWord = calculateFitWord(content.substr(0, left), maxPixelWidth, scale);
std::vector<Word> rightWord = calculateFitWord(content.substr(left+1, right), maxPixelWidth, scale);
// If one or more of both are empty, forget it
if (leftWord.empty() || rightWord.empty())
{
return std::vector<Word>();
}
else
{
std::vector<Word> words(leftWord);
words.insert(words.end(), rightWord.begin(), rightWord.end());
return words;
}
}
}
示例8: render
float Font::render(const std::u16string &text, glm::vec2 position, HexColor color, int caretPosition){
empty[g_UILayer] = false;
LastTextHeight = 0;
LastTextLength = 0;
lastTextSize = text.size();
glm::vec2 currentPosition = position;
char16_t letter;
for (u32 i = 0; i < text.size(); i++){
letter = text[i];
auto &letterInfo = fontInfo->m_letters[letter];
if (letter == '\n'){ // new line
LastTextLength = std::max(LastTextLength, currentPosition[0] - position.x);
LastTextHeight += height;
currentPosition = position - glm::vec2(0, LastTextHeight);
continue;
}
if (letter > L'\u00ff'){
currentPosition.x += genSingleSymbol(letter, currentPosition, color);
continue;
}
else if (i > 0){ // kerning
currentPosition[0] += letterInfo.kerning[text[i - 1]];
}
renderedFonts[g_UILayer].m_size++;
renderedFonts[g_UILayer].positions.push_back(currentPosition + letterInfo.offset);
renderedFonts[g_UILayer].sizes.push_back(letterInfo.size);
renderedFonts[g_UILayer].uvs.push_back(letterInfo.uv);
renderedFonts[g_UILayer].colors.push_back(color);
currentPosition.x += letterInfo.advance;
}
if (lastTextSize > 0) // compute len
LastTextLength = currentPosition[0] - position.x;
// placeCaret(text, position, color, caretPosition);
renderedFonts[g_UILayer].m_size = renderedFonts[g_UILayer].uvs.size();
return LastTextLength + 1.f;
}
示例9: DetermineTokenWidths
void Label::DetermineTokenWidths(const std::u16string& text, double heuristicCharWidth, std::vector<double>& tokenWidths)
{
double tokenWidth = 0;
int textSize = text.size();
for(int i = 0; i < textSize; ++i)
{
if (text[i] != ' ')
{
tokenWidth += heuristicCharWidth;
}
else
{
tokenWidths.push_back(tokenWidth);
tokenWidth = 0;
}
}
tokenWidths.push_back(tokenWidth);
}
示例10: patternMatch
bool RegexStore::patternMatch(std::u16string& in_string) {
//No pattern matches when we don't have a valid pattern
if (not is_compiled) {
return false;
}
//Check for a match
regmatch_t pmatch;
std::string tmp_str(in_string.begin(), in_string.end());
int match = regexec(&exp, tmp_str.c_str(), 1, &pmatch, 0);
//Make sure that each character was matched and that the entire input string
//was consumed by the pattern
if (0 == match and 0 == pmatch.rm_so and in_string.size() == pmatch.rm_eo) {
return true;
}
else {
return false;
}
}
示例11: sys_loc
std::string CodeConvertU16(const std::u16string & s)
{
const int Max_In_Size = 4;
std::locale sys_loc("");
const char16_t * src_insrc = s.c_str();
const size_t BUFFER_SIZE = s.size() * Max_In_Size;
const size_t OUT_SIZE = sizeof(char);
// TODO:
// reasonable size , it may be too large the allocation to
// on the Out[BUFFER_SIZE]
char * extern_buffer = new char[BUFFER_SIZE];
memset(extern_buffer, 0, BUFFER_SIZE * OUT_SIZE);
const char16_t * intern_from = src_insrc;
const char16_t * intern_from_end = intern_from + s.size();
const char16_t * intern_from_next = 0;
char * extern_from = extern_buffer;
char * extern_from_end = extern_from + BUFFER_SIZE;
char * extern_from_next = 0;
typedef std::codecvt<char16_t, char, std::mbstate_t> CodeCvtFacet;
// TODO:
// it is required to have the typename in front of the
// CodeCvtFacet
// It is because of the CodeCvtFacet is a dependent scope, which means it required
// to explicitly tell the compiler that the CodeCvtFacet is a type
//
typename CodeCvtFacet::result cvt_rst = std::use_facet<CodeCvtFacet>(sys_loc).out(
out_cvt_state,
intern_from,
intern_from_end,
intern_from_next,
extern_from,
extern_from_end,
extern_from_next
);
if (cvt_rst != CodeCvtFacet::ok) {
switch (cvt_rst) {
case CodeCvtFacet::error:
std::cerr << "partial";
break;
case CodeCvtFacet::partial:
std::cerr << "partial";
break;
case CodeCvtFacet::noconv:
std::cerr << "noconv";
break;
default:
std::cerr << "unknown";
break;
}
std::cerr << ", please check out_cvt_state."
<< std::endl;
}
std::string result = extern_buffer;
delete[] extern_buffer;
return result;
}
示例12: applyArabicShaping
// Takes UTF16 input in logical order and applies Arabic shaping to the input while maintaining
// logical order. Output won't be intelligible until the bidirectional algorithm is applied
std::u16string applyArabicShaping(const std::u16string& input) {
UErrorCode errorCode = U_ZERO_ERROR;
const int32_t outputLength =
u_shapeArabic(mbgl::utf16char_cast<const UChar*>(input.c_str()), static_cast<int32_t>(input.size()), nullptr, 0,
(U_SHAPE_LETTERS_SHAPE & U_SHAPE_LETTERS_MASK) |
(U_SHAPE_TEXT_DIRECTION_LOGICAL & U_SHAPE_TEXT_DIRECTION_MASK),
&errorCode);
// Pre-flighting will always set U_BUFFER_OVERFLOW_ERROR
errorCode = U_ZERO_ERROR;
std::u16string outputText(outputLength, 0);
u_shapeArabic(mbgl::utf16char_cast<const UChar*>(input.c_str()), static_cast<int32_t>(input.size()), mbgl::utf16char_cast<UChar*>(&outputText[0]), outputLength,
(U_SHAPE_LETTERS_SHAPE & U_SHAPE_LETTERS_MASK) |
(U_SHAPE_TEXT_DIRECTION_LOGICAL & U_SHAPE_TEXT_DIRECTION_MASK),
&errorCode);
// If the algorithm fails for any reason, fall back to non-transformed text
if (U_FAILURE(errorCode))
return input;
return outputText;
}
示例13: runtime_error
std::vector<std::u16string> BiDi::processText(const std::u16string& input,
std::set<std::size_t> lineBreakPoints) {
UErrorCode errorCode = U_ZERO_ERROR;
ubidi_setPara(impl->bidiText, mbgl::utf16char_cast<const UChar*>(input.c_str()), static_cast<int32_t>(input.size()),
UBIDI_DEFAULT_LTR, nullptr, &errorCode);
if (U_FAILURE(errorCode)) {
throw std::runtime_error(std::string("BiDi::processText: ") + u_errorName(errorCode));
}
return applyLineBreaking(lineBreakPoints);
}
示例14: sizeof
input_u16string_buffer::input_u16string_buffer(std::u16string const & data) :
data_(data.size() + 1)
{
memcpy(data_.data(), data.data(), data_.size() * sizeof(char16_t));
}
示例15:
std::string to_utf8(const std::u16string &s)
{
std::wstring_convert<std::codecvt_utf8<int16_t>, int16_t> convert;
auto p = reinterpret_cast<const int16_t *>(s.data());
return convert.to_bytes(p, p + s.size());
}