// 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; }
Directory::Directory(FS_Archive archive, const std::u16string& root) { load = false; err = 0; Handle handle; list.clear(); err = FSUSER_OpenDirectory(&handle, archive, fsMakePath(PATH_UTF16, root.c_str())); if (R_FAILED(err)) { return; } u32 result = 0; do { FS_DirectoryEntry item; err = FSDIR_Read(handle, &result, 1, &item); if (result == 1) { list.push_back(item); } } while(result); err = FSDIR_Close(handle); if (R_FAILED(err)) { list.clear(); return; } load = true; }
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); }
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); } }
bool HTMLElementImp::toUnsigned(std::u16string& value) { stripLeadingAndTrailingWhitespace(value); if (value.empty()) return false; const char16_t* s = value.c_str(); while (*s) { if (!isDigit(*s)) return false; ++s; } return true; }
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); }
bool mapToInteger(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) return false; value.erase(end - input); return true; }
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; }
void Text::findBreaksUtf16( const std::u16string &line, std::vector<size_t> *must, std::vector<size_t> *allow ) { std::vector<uint8_t> resultBreaks; calcLinebreaksUtf16( (uint16_t*)line.c_str(), &resultBreaks ); // must->clear(); allow->clear(); // for( size_t i = 0; i < resultBreaks.size(); ++i ) { if( resultBreaks[i] == ci::UNICODE_ALLOW_BREAK ) allow->push_back( i ); else if( resultBreaks[i] == ci::UNICODE_MUST_BREAK ) { must->push_back( i ); allow->push_back( i ); } } }
bool HTMLElementImp::toPxOrPercentage(std::u16string& value) { stripLeadingAndTrailingWhitespace(value); if (value.empty()) return false; const char16_t* s = value.c_str(); while (*s) { if (*s == '%') break; if (!isDigit(*s)) return false; ++s; } if (!*s) { value += u"px"; return true; } assert(*s == '%'); if (!s[1] && 1 < value.length()) return true; return false; }
void ItemTerminal::handleUIEvent(uint32 action,int32 element,std::u16string inputStr,UIWindow* window, std::shared_ptr<WindowAsyncContainerCommand> AsyncContainer) { cbt_->handleUIEvent(action, element, inputStr.c_str(), window, AsyncContainer); }
bool PlayerTaskWin::run() { if (!isIdle()) { CCLOG("PlayerTaskWin::run() - task is not idle"); return false; } //BOOL WINAPI CreateProcess( // _In_opt_ LPCTSTR lpApplicationName, // _Inout_opt_ LPTSTR lpCommandLine, // _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, // _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, // _In_ BOOL bInheritHandles, // _In_ DWORD dwCreationFlags, // _In_opt_ LPVOID lpEnvironment, // _In_opt_ LPCTSTR lpCurrentDirectory, // _In_ LPSTARTUPINFO lpStartupInfo, // _Out_ LPPROCESS_INFORMATION lpProcessInformation //); // http://msdn.microsoft.com/en-us/library/windows/desktop/ms682499(v=vs.85).aspx SECURITY_ATTRIBUTES sa = {0}; sa.nLength = sizeof(sa); sa.bInheritHandle = TRUE; // Create a pipe for the child process's STDOUT. if (!CreatePipe(&_childStdOutRead, &_childStdOutWrite, &sa, 0) || !SetHandleInformation(_childStdOutRead, HANDLE_FLAG_INHERIT, 0)) { CCLOG("PlayerTaskWin::run() - create stdout handle failed, for execute %s", _executePath.c_str()); cleanup(); return false; } // Create a pipe for the child process's STDIN. if (!CreatePipe(&_childStdInRead, &_childStdInWrite, &sa, 0) || !SetHandleInformation(_childStdInWrite, HANDLE_FLAG_INHERIT, 0)) { CCLOG("PlayerTaskWin::run() - create stdout handle failed, for execute %s", _executePath.c_str()); cleanup(); return false; } ZeroMemory(&_pi, sizeof(_pi)); STARTUPINFO si = {0}; si.cb = sizeof(STARTUPINFO); si.hStdError = _childStdOutWrite; si.hStdOutput = _childStdOutWrite; si.hStdInput = _childStdInRead; si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; si.wShowWindow = SW_HIDE; #define MAX_COMMAND 4096 //MAX_PATH const std::u16string u16command = makeCommandLine(); WCHAR command[MAX_COMMAND]; wcscpy_s(command, MAX_COMMAND, (WCHAR*)u16command.c_str()); BOOL success = CreateProcess(NULL, command, // command line NULL, // process security attributes NULL, // primary thread security attributes TRUE, // handles are inherited 0, // creation flags NULL, // use parent's environment NULL, // use parent's current directory &si, // STARTUPINFO pointer &_pi); // receives PROCESS_INFORMATION if (!success) { CCLOG("PlayerTaskWin::run() - create process failed, for execute %s", _executePath.c_str()); cleanup(); return false; } _outputBuff = new CHAR[BUFF_SIZE + 1]; _outputBuffWide = new WCHAR[BUFF_SIZE]; _state = STATE_RUNNING; cocos2d::Director::getInstance()->getScheduler()->scheduleUpdate(this, 0, false); return true; }
bool toInteger(const std::u16string& value, int& output) { const char16_t* input = value.c_str(); const char16_t* end = input + value.length(); return parseInt(input, end, output); // Do not care what follows after digits. }
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::
void ctr::news::add(std::u16string title, std::u16string message, void* image, u32 imageSize, bool jpeg) { if(!initialized) { ctr::err::set(initError); return; } ctr::err::parse(ctr::err::SOURCE_NEWS_ADD_NOTIFICATION, (u32) NEWS_AddNotification((const u16*) title.c_str(), title.length(), (const u16*) message.c_str(), message.length(), image, imageSize, jpeg)); }
void Tempest::FontElement::fetch(const std::u16string &str, Tempest::SpritesHolder &sp) const { fetch(str.c_str(),sp); }
Tempest::Size Tempest::FontElement::textSize(const std::u16string &str ) const { return textSize( str.c_str(), str.c_str()+str.size() ); }
void h1(const std::u16string &s) { h1(s.c_str()); // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to 'c_str' [readability-redundant-string-cstr] // CHECK-FIXES: {{^ }}h1(s);{{$}} }
void FontAtlas::conversionU16TOGB2312(const std::u16string& u16Text, std::unordered_map<unsigned short, unsigned short>& charCodeMap) { size_t strLen = u16Text.length(); auto gb2312StrSize = strLen * 2; auto gb2312Text = new (std::nothrow) char[gb2312StrSize]; memset(gb2312Text, 0, gb2312StrSize); switch (_fontFreeType->getEncoding()) { case FT_ENCODING_GB2312: { #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT WideCharToMultiByte(936, NULL, (LPCWCH)u16Text.c_str(), strLen, (LPSTR)gb2312Text, gb2312StrSize, NULL, NULL); #elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID conversionEncodingJNI((char*)u16Text.c_str(), gb2312StrSize, "UTF-16LE", gb2312Text, "GB2312"); #else if (_iconv == nullptr) { _iconv = iconv_open("gb2312", "utf-16le"); } if (_iconv == (iconv_t)-1) { CCLOG("conversion from utf16 to gb2312 not available"); } else { char* pin = (char*)u16Text.c_str(); char* pout = gb2312Text; size_t inLen = strLen * 2; size_t outLen = gb2312StrSize; iconv(_iconv, (char**)&pin, &inLen, &pout, &outLen); } #endif } break; default: CCLOG("Unsupported encoding:%d", _fontFreeType->getEncoding()); break; } unsigned short gb2312Code = 0; unsigned char* dst = (unsigned char*)&gb2312Code; unsigned short u16Code; for (size_t index = 0, gbIndex = 0; index < strLen; ++index) { u16Code = u16Text[index]; if (u16Code < 256) { charCodeMap[u16Code] = u16Code; gbIndex += 1; } else { dst[0] = gb2312Text[gbIndex + 1]; dst[1] = gb2312Text[gbIndex]; charCodeMap[u16Code] = gb2312Code; gbIndex += 2; } } delete[] gb2312Text; }
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; }
void FontAtlas::conversionU16TOGB2312(const std::u16string& u16Text, std::unordered_map<unsigned short, unsigned short>& charCodeMap) { size_t strLen = u16Text.length(); auto gb2312StrSize = strLen * 2; auto gb2312Text = new (std::nothrow) char[gb2312StrSize]; memset(gb2312Text, 0, gb2312StrSize); switch (_fontFreeType->getEncoding()) { case FT_ENCODING_GB2312: { if (_iconv == nullptr) { _iconv = iconv_open("gb2312", "utf-16le"); } if (_iconv == (iconv_t)-1) { OUTPUT_LOG("conversion from utf16 to gb2312 not available"); } else { char* pout = gb2312Text; size_t inLen = strLen * 2; size_t outLen = gb2312StrSize; #if _LIBICONV_VERSION == 0x109 || _LIBICONV_VERSION == 0x010F const char* pin = (char*)u16Text.c_str(); iconv(_iconv, &pin, &inLen, &pout, &outLen); #else char* pin = (char*)u16Text.c_str(); iconv(_iconv, &pin, &inLen, &pout, &outLen); #endif } } break; default: OUTPUT_LOG("Unsupported encoding:%d", _fontFreeType->getEncoding()); break; } unsigned short gb2312Code = 0; unsigned char* dst = (unsigned char*)&gb2312Code; unsigned short u16Code; for (size_t index = 0, gbIndex = 0; index < strLen; ++index) { u16Code = u16Text[index]; if (u16Code < 256) { charCodeMap[u16Code] = u16Code; gbIndex += 1; } else { dst[0] = gb2312Text[gbIndex + 1]; dst[1] = gb2312Text[gbIndex]; charCodeMap[u16Code] = gb2312Code; gbIndex += 2; } } delete[] gb2312Text; }