本文整理汇总了C++中std::u16string类的典型用法代码示例。如果您正苦于以下问题:C++ u16string类的具体用法?C++ u16string怎么用?C++ u16string使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了u16string类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findNewCharacters
void FontAtlas::findNewCharacters(const std::u16string& u16Text, std::unordered_map<unsigned short, unsigned short>& charCodeMap)
{
std::u16string newChars;
FT_Encoding charEncoding = _fontFreeType->getEncoding();
//find new characters
if (_letterDefinitions.empty())
{
// fixed #16169: new android project crash in android 5.0.2 device (Nexus 7) when use 3.12.
// While using clang compiler with gnustl_static on android, the copy assignment operator of `std::u16string`
// will affect the memory validity, it means after `newChars` is destroyed, the memory of `u16Text` holds
// will be a dead region. `u16text` represents the variable in `Label::_utf16Text`, when somewhere
// allocates memory by `malloc, realloc, new, new[]`, the generated memory address may be the same
// as `Label::_utf16Text` holds. If doing a `memset` or other memory operations, the orignal `Label::_utf16Text`
// will be in an unknown state. Meanwhile, a bunch lots of logic which depends on `Label::_utf16Text`
// will be broken.
// newChars = u16Text;
// Using `append` method is a workaround for this issue. So please be carefuly while using the assignment operator
// of `std::u16string`.
newChars.append(u16Text);
}
else
{
auto length = u16Text.length();
newChars.reserve(length);
for (size_t i = 0; i < length; ++i)
{
auto outIterator = _letterDefinitions.find(u16Text[i]);
if (outIterator == _letterDefinitions.end())
{
newChars.push_back(u16Text[i]);
}
}
}
if (!newChars.empty())
{
switch (charEncoding)
{
case FT_ENCODING_UNICODE:
{
for (auto u16Code : newChars)
{
charCodeMap[u16Code] = u16Code;
}
break;
}
case FT_ENCODING_GB2312:
{
conversionU16TOGB2312(newChars, charCodeMap);
break;
}
default:
OUTPUT_LOG("FontAtlas::findNewCharacters: Unsupported encoding:%d", charEncoding);
break;
}
}
}
示例2: mapToPixelLength
bool mapToPixelLength(std::u16string& value)
{
if (stripLeadingWhitespace(value).empty())
return false;
const char16_t* input = value.c_str();
const char16_t* end = input + value.length();
int u;
end = parseInt(input, end, u);
if (!end || u < 0)
return false;
if (0 < u)
value.replace(end - input, std::u16string::npos, u"px");
else
value.erase(end - input);
return true;
}
示例3: UTF8ToUTF16
bool UTF8ToUTF16(const std::string& utf8, std::u16string& outUtf16)
{
if (utf8.empty())
{
outUtf16.clear();
return true;
}
bool ret = false;
const size_t utf16Bytes = (utf8.length()+1) * sizeof(char16_t);
char16_t* utf16 = (char16_t*)malloc(utf16Bytes);
memset(utf16, 0, utf16Bytes);
char* utf16ptr = reinterpret_cast<char*>(utf16);
const UTF8* error = NULL;
if (llvm::ConvertUTF8toWide(2, utf8, utf16ptr, error))
{
outUtf16 = utf16;
ret = true;
}
free(utf16);
return ret;
}
示例4: setMediaText
void MediaListImp::setMediaText(const std::u16string& mediaText)
{
clear();
if (!mediaText.empty()) {
CSSParser parser;
*this = *parser.parseMediaList(mediaText);
}
}
示例5: Load
void KMX_Environment::Load(std::u16string const & key, std::u16string const & value) {
assert(!key.empty());
if (!u16icmp(key.c_str(), KM_KBP_KMX_ENV_PLATFORM)) {
_platform = value;
}
else if (!u16icmp(key.c_str(), KM_KBP_KMX_ENV_BASELAYOUT)) {
_baseLayout = value;
}
else if (!u16icmp(key.c_str(), KM_KBP_KMX_ENV_BASELAYOUTALT)) {
_baseLayoutAlt = value;
}
else if (!u16icmp(key.c_str(), KM_KBP_KMX_ENV_SIMULATEALTGR)) {
_simulateAltGr = value == u"1";
}
else if (!u16icmp(key.c_str(), KM_KBP_KMX_ENV_CAPSLOCK)) {
_capsLock = value == u"1";
}
else if (!u16icmp(key.c_str(), KM_KBP_KMX_ENV_BASELAYOUTGIVESCTRLRALTFORRALT)) {
_baseLayoutGivesCtrlRAltForRAlt = value == u"1";
}
else {
// Unsupported key
assert(false);
}
}
示例6: 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;
}
示例7: UTF16ToUTF8
bool UTF16ToUTF8(const std::u16string& utf16, std::string& outUtf8)
{
if (utf16.empty())
{
outUtf8.clear();
return true;
}
return llvm::convertUTF16ToUTF8String(utf16, outUtf8);
}
示例8: Value
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;
}
示例9: renderString
void TextLabels::renderString( const std::u16string &str, vec2 *cursor, float stretch )
{
std::u16string::const_iterator itr;
for( itr = str.begin(); itr != str.end(); ++itr ) {
// retrieve character code
uint16_t id = (uint16_t)*itr;
if( mFont->contains( id ) ) {
// get metrics for this character to speed up measurements
Font::Metrics m = mFont->getMetrics( id );
// skip whitespace characters
if( !isWhitespaceUtf16( id ) ) {
size_t index = mVertices.size();
Rectf bounds = mFont->getBounds( m, mFontSize );
mVertices.push_back( vec3( *cursor + bounds.getUpperLeft(), 0 ) );
mVertices.push_back( vec3( *cursor + bounds.getUpperRight(), 0 ) );
mVertices.push_back( vec3( *cursor + bounds.getLowerRight(), 0 ) );
mVertices.push_back( vec3( *cursor + bounds.getLowerLeft(), 0 ) );
bounds = mFont->getTexCoords( m );
mTexcoords.push_back( bounds.getUpperLeft() );
mTexcoords.push_back( bounds.getUpperRight() );
mTexcoords.push_back( bounds.getLowerRight() );
mTexcoords.push_back( bounds.getLowerLeft() );
mIndices.push_back( index + 0 ); mIndices.push_back( index + 3 ); mIndices.push_back( index + 1 );
mIndices.push_back( index + 1 ); mIndices.push_back( index + 3 ); mIndices.push_back( index + 2 );
mOffsets.insert( mOffsets.end(), 4, mOffset );
}
if( id == 32 )
cursor->x += stretch * mFont->getAdvance( m, mFontSize );
else
cursor->x += mFont->getAdvance( m, mFontSize );
}
}
//
mBoundsInvalid = true;
}
示例10: DecodeHeading
void UserDictionaryDecoder::DecodeHeading(IBitStream *bstr, unsigned len, std::u16string &res) {
res.clear();
unsigned symIdx;
for (size_t i = 0; i < len; i++) {
_ltHeadings.Decode(*bstr, symIdx);
unsigned sym = _headingSymbols.at(symIdx);
assert(sym <= 0xffff);
res += (char16_t)sym;
}
}
示例11: 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;
}
}
示例12:
SimpleString::SimpleString(const std::u16string _str)
{
length = _str.size();
s_value = new char16_t[length + 1];
for (unsigned int i = 0; i < _str.size(); ++i)
s_value[i] = _str[i];
s_value[length] = u'\0';
// calculate hash;
_hash = 5381;
int c = 0;
char16_t * sptr = s_value;
while ((c = *sptr++))
_hash = ((_hash << 5) + _hash) + c;
}
示例13: getChar16VectorFromUTF16String
std::vector<char16_t> getChar16VectorFromUTF16String(const std::u16string& utf16)
{
std::vector<char16_t> ret;
size_t len = utf16.length();
ret.reserve(len);
for (size_t i = 0; i < len; ++i)
{
ret.push_back(utf16[i]);
}
return ret;
}
示例14: convertUTF16ToUTF8String
bool convertUTF16ToUTF8String(const std::u16string& utf16, std::string &Out) {
assert(Out.empty());
// Avoid OOB by returning early on empty input.
if (utf16.empty())
return true;
const UTF16 *Src = reinterpret_cast<const UTF16 *>(utf16.data());
const UTF16 *SrcEnd = reinterpret_cast<const UTF16 *>(utf16.data() + utf16.length());
// Byteswap if necessary.
std::vector<UTF16> ByteSwapped;
if (Src[0] == UNI_UTF16_BYTE_ORDER_MARK_SWAPPED) {
ByteSwapped.insert(ByteSwapped.end(), Src, SrcEnd);
for (size_t I = 0, E = ByteSwapped.size(); I != E; ++I)
ByteSwapped[I] = SwapByteOrder_16(ByteSwapped[I]);
Src = &ByteSwapped[0];
SrcEnd = &ByteSwapped[ByteSwapped.size() - 1] + 1;
}
// Skip the BOM for conversion.
if (Src[0] == UNI_UTF16_BYTE_ORDER_MARK_NATIVE)
Src++;
// Just allocate enough space up front. We'll shrink it later.
Out.resize(utf16.length() * UNI_MAX_UTF8_BYTES_PER_CODE_POINT + 1);
UTF8 *Dst = reinterpret_cast<UTF8 *>(&Out[0]);
UTF8 *DstEnd = Dst + Out.size();
ConversionResult CR =
ConvertUTF16toUTF8(&Src, SrcEnd, &Dst, DstEnd, strictConversion);
assert(CR != targetExhausted);
if (CR != conversionOK) {
Out.clear();
return false;
}
Out.resize(reinterpret_cast<char *>(Dst) - &Out[0]);
return true;
}
示例15: to_utf8
std::string to_utf8(const std::u16string& str)
{
icu_handle::get();
static_assert(sizeof(char16_t) == sizeof(UChar),
"Invalid UChar definition in ICU");
// looks dangerous, but isn't: UChar is guaranteed to be a 16-bit
// integer type, so all we're doing here is going between signed vs.
// unsigned
auto buf = reinterpret_cast<const UChar*>(str.c_str());
icu::UnicodeString u16str{buf};
return icu_to_u8str(u16str);
}