WideString CFX_BreakPiece::GetString() const { WideString ret; ret.Reserve(m_iChars); for (int32_t i = m_iStartChar; i < m_iStartChar + m_iChars; i++) ret += static_cast<wchar_t>((*m_pChars)[i].char_code()); return ret; }
WideString CPDF_TextPage::GetTextByPredicate( const std::function<bool(const PAGECHAR_INFO&)>& predicate) const { if (!m_bIsParsed) return WideString(); float posy = 0; bool IsContainPreChar = false; bool IsAddLineFeed = false; WideString strText; for (const auto& charinfo : m_CharList) { if (predicate(charinfo)) { if (fabs(posy - charinfo.m_Origin.y) > 0 && !IsContainPreChar && IsAddLineFeed) { posy = charinfo.m_Origin.y; if (!strText.IsEmpty()) strText += L"\r\n"; } IsContainPreChar = true; IsAddLineFeed = false; if (charinfo.m_Unicode) strText += charinfo.m_Unicode; } else if (charinfo.m_Unicode == L' ') { if (IsContainPreChar) { strText += L' '; IsContainPreChar = false; IsAddLineFeed = false; } } else { IsContainPreChar = false; IsAddLineFeed = true; } } return strText; }
PyObject * PyIMEngine::py_get_surrounding_text (PyIMEngineObject *self, PyObject *args) { PyObject *tuple; int maxlen_before = -1; int maxlen_after = -1; if (!PyArg_ParseTuple (args, "|ii:get_surrounding_text", &maxlen_before, &maxlen_after)) return NULL; WideString text; int cursor; int provided = self->engine.get_surrounding_text(text, cursor, maxlen_before, maxlen_after); tuple = PyTuple_New (2); if (!provided) { text = L""; cursor = 0; } #if Py_UNICODE_SIZE == 4 PyTuple_SET_ITEM (tuple, 0, PyUnicode_FromUnicode ((Py_UNICODE *)text.c_str(), text.length())); #else gunichar2 *utf16_str = g_ucs4_to_utf16 (text.c_str(), -1, NULL, NULL, NULL); PyTuple_SET_ITEM (tuple, 0, PyUnicode_FromUnicode ((Py_UNICODE *)utf16_str, text.length())); #endif PyTuple_SET_ITEM (tuple, 1, PyInt_FromLong ((long) cursor)); return tuple; }
ScValue *SXString::scGetProperty(const Common::String &name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// // Type (RO) ////////////////////////////////////////////////////////////////////////// if (name == "Type") { _scValue->setString("string"); return _scValue; } ////////////////////////////////////////////////////////////////////////// // Length (RO) ////////////////////////////////////////////////////////////////////////// else if (name == "Length") { if (_gameRef->_textEncoding == TEXT_UTF8) { WideString wstr = StringUtil::utf8ToWide(_string); _scValue->setInt(wstr.size()); } else { _scValue->setInt(strlen(_string)); } return _scValue; } ////////////////////////////////////////////////////////////////////////// // Capacity ////////////////////////////////////////////////////////////////////////// else if (name == "Capacity") { _scValue->setInt(_capacity); return _scValue; } else { return _scValue; } }
TEST_F(CFGAS_FormatStringTest, DateTimeFormat) { struct { const wchar_t* locale; const wchar_t* input; const wchar_t* pattern; const wchar_t* output; } tests[] = { {L"en", L"1999-07-16T10:30Z", L"'At' time{HH:MM Z} 'on' date{MMM DD, YYYY}", L"At 10:30 GMT on Jul 16, 1999"}, {L"en", L"1999-07-16T10:30", L"'At' time{HH:MM} 'on' date{MMM DD, YYYY}", L"At 10:30 on Jul 16, 1999"}, {L"en", L"1999-07-16T10:30Z", L"time{'At' HH:MM Z} date{'on' MMM DD, YYYY}", L"At 10:30 GMT on Jul 16, 1999"}, {L"en", L"1999-07-16T10:30Z", L"time{'At 'HH:MM Z}date{' on 'MMM DD, YYYY}", L"At 10:30 GMT on Jul 16, 1999"}}; for (size_t i = 0; i < FX_ArraySize(tests); ++i) { WideString result; EXPECT_TRUE(fmt(tests[i].locale) ->FormatDateTime(tests[i].input, tests[i].pattern, FX_DATETIMETYPE_TimeDate, &result)); EXPECT_STREQ(tests[i].output, result.c_str()) << " TEST: " << i; } }
void CRespawn::Render() { position2d<s32> pos; for ( int i = 0; i < points.size(); i++ ) { WideString wstr = "(S) "; wstr += points[i]->getActorName().c_str(); pos = IRR.smgr->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition( points[i]->getPosition(), IRR.smgr->getActiveCamera() ); IRR.gui->getBuiltInFont()->draw( wstr.c_str(), core::rect<s32>( pos.X, pos.Y, pos.X + 100, pos.Y + 50 ), irr::video::SColor( 255, 15, 85, 10 ), false, true ); } // draw 3d stuff IRR.video->setTransform( ETS_WORLD, matrix4() ); SMaterial m; m.Lighting = false; m.BackfaceCulling = false; IRR.video->setMaterial( m ); vector3df vP; for ( int i = 0; i < points.size(); i++ ) { vP = points[i]->getPosition(); IRR.video->draw3DBox( aabbox3df( vP - vector3df( points[i]->radius, points[i]->radius, points[i]->radius ), vP + vector3df( points[i]->radius, points[i]->radius, points[i]->radius ) ), SColor( 255, 105, 22, 90 ) ); } }
TEST(cpdf_nametree, GetUnicodeNameWithBOM) { // Set up the root dictionary with a Names array. auto pRootDict = pdfium::MakeUnique<CPDF_Dictionary>(); CPDF_Array* pNames = pRootDict->SetNewFor<CPDF_Array>("Names"); // Add the key "1" (with BOM) and value 100 into the array. std::ostringstream buf; constexpr char kData[] = "\xFE\xFF\x00\x31"; for (size_t i = 0; i < sizeof(kData); ++i) buf.put(kData[i]); pNames->AddNew<CPDF_String>(ByteString(buf), true); pNames->AddNew<CPDF_Number>(100); // Check that the key is as expected. CPDF_NameTree nameTree(pRootDict.get()); WideString storedName; nameTree.LookupValueAndName(0, &storedName); EXPECT_STREQ(L"1", storedName.c_str()); // Check that the correct value object can be obtained by looking up "1". WideString matchName = L"1"; CPDF_Object* pObj = nameTree.LookupValue(matchName); ASSERT_TRUE(pObj->IsNumber()); EXPECT_EQ(100, pObj->AsNumber()->GetInteger()); }
CScValue *CScValue::GetProp(char *Name) { if (m_Type == VAL_VARIABLE_REF) return m_ValRef->GetProp(Name); if (m_Type == VAL_STRING && strcmp(Name, "Length") == 0) { Game->m_ScValue->m_Type = VAL_INT; if (Game->m_TextEncoding == TEXT_ANSI) { Game->m_ScValue->SetInt(strlen(m_ValString)); } else { WideString wstr = StringUtil::Utf8ToWide(m_ValString); Game->m_ScValue->SetInt(wstr.length()); } return Game->m_ScValue; } CScValue *ret = NULL; if (m_Type == VAL_NATIVE && m_ValNative) ret = m_ValNative->ScGetProperty(Name); if (ret == NULL) { m_ValIter = m_ValObject.find(Name); if (m_ValIter != m_ValObject.end()) ret = m_ValIter->second; } return ret; }
WideString CPDF_FileSpec::GetFileName() const { WideString csFileName; if (const CPDF_Dictionary* pDict = m_pObj->AsDictionary()) { csFileName = pDict->GetUnicodeTextFor("UF"); if (csFileName.IsEmpty()) { csFileName = WideString::FromDefANSI( pDict->GetStringFor(pdfium::stream::kF).AsStringView()); } if (pDict->GetStringFor("FS") == "URL") return csFileName; if (csFileName.IsEmpty()) { constexpr const char* keys[] = {"DOS", "Mac", "Unix"}; for (const auto* key : keys) { if (pDict->KeyExist(key)) { csFileName = WideString::FromDefANSI(pDict->GetStringFor(key).AsStringView()); break; } } } } else if (m_pObj->IsString()) { csFileName = WideString::FromDefANSI(m_pObj->GetString().AsStringView()); } return DecodeFileName(csFileName); }
bool LodDistanceControl::TextFieldKeyPressed(UITextField * textField, int32 replacementLocation, int32 replacementLength, const WideString & replacementString) { if (replacementLength < 0) { return true; } WideString newText = textField->GetAppliedChanges(replacementLocation, replacementLength, replacementString); bool allOk; int pointsCount = 0; for (int i = 0; i < newText.length(); i++) { allOk = false; if (newText[i] == L'-' && i == 0) { allOk = true; } else if(newText[i] >= L'0' && newText[i] <= L'9') { allOk = true; } else if(newText[i] == L'.' && pointsCount == 0) { allOk = true; pointsCount++; } if (!allOk) { return false; } } return true; };
WideString CPDF_CIDFont::UnicodeFromCharCode(uint32_t charcode) const { WideString str = CPDF_Font::UnicodeFromCharCode(charcode); if (!str.IsEmpty()) return str; wchar_t ret = GetUnicodeFromCharCode(charcode); return ret ? ret : WideString(); }
void ButtonBuildStructure::onRender( RenderContext & context, const RectInt & window ) { WindowButton::onRender( context, window ); if ( enabled() && m_Build.valid() ) { DisplayDevice * pDisplay = context.display(); ASSERT( pDisplay ); // draw the eta to build this structure Font * pFont = windowStyle()->font(); if ( pFont != NULL ) { WideString eta; GameDocument * pDoc = (GameDocument *)document(); if ( pDoc != NULL ) { NounShip::Ref pShip = pDoc->ship(); if ( pShip.valid() ) { int buildTime = m_Build->buildTime()* pShip->calculateModifier(MT_BUILD_SPEED,true); eta.format( "%d:%2.2d", buildTime / 60, buildTime % 60); SizeInt etaSize( pFont->size( eta ) ); PointInt etaPos( window.right - etaSize.width, window.bottom - etaSize.height ); Font::push( context.display(), pFont, etaPos, eta, WHITE ); } } } } }
ScValue *ScValue::getProp(const char *name) { if (_type == VAL_VARIABLE_REF) { return _valRef->getProp(name); } if (_type == VAL_STRING && strcmp(name, "Length") == 0) { _gameRef->_scValue->_type = VAL_INT; if (_gameRef->_textEncoding == TEXT_ANSI) { _gameRef->_scValue->setInt(strlen(_valString)); } else { WideString wstr = StringUtil::utf8ToWide(_valString); _gameRef->_scValue->setInt(wstr.size()); } return _gameRef->_scValue; } ScValue *ret = nullptr; if (_type == VAL_NATIVE && _valNative) { ret = _valNative->scGetProperty(name); } if (ret == nullptr) { _valIter = _valObject.find(name); if (_valIter != _valObject.end()) { ret = _valIter->_value; } } return ret; }
QString WideString2QStrint(const WideString& str) { #ifdef __DAVAENGINE_MACOS__ return QString::fromStdWString(str); #else return QString((const QChar*)str.c_str(), str.length()); #endif }
bool CBC_Code39::RenderDevice(CFX_RenderDevice* device, const CFX_Matrix* matrix) { auto* pWriter = GetOnedCode39Writer(); WideString renderCon; if (!pWriter->encodedContents(m_renderContents.AsStringView(), &renderCon)) return false; return pWriter->RenderDeviceResult(device, matrix, renderCon.AsStringView()); }
int StringUtil::indexOf(const WideString &str, const WideString &toFind, size_t startFrom) { const char *index = strstr(str.c_str(), toFind.c_str()); if (index == nullptr) { return -1; } else { return index - str.c_str(); } }
void HangulInstance::update_candidates () { m_lookup_table.clear (); m_candidate_comments.clear (); HanjaList* list = NULL; // search for symbol character // key string for symbol character is like: // 'ㄱ', 'ㄴ', 'ㄷ', etc WideString preeditw = get_preedit_string(); if (preeditw.length() == 1) { String key = utf8_wcstombs(preeditw); list = hanja_table_match_suffix(m_factory->m_symbol_table, key.c_str()); } // search for hanja if (list == NULL) { String str = get_candidate_string(); SCIM_DEBUG_IMENGINE(1) << "candidate string: " << str << "\n"; if (str.length() > 0) { if (is_hanja_mode() || m_factory->m_commit_by_word) { list = hanja_table_match_prefix(m_factory->m_hanja_table, str.c_str()); } else { list = hanja_table_match_suffix(m_factory->m_hanja_table, str.c_str()); } } } if (list != NULL) { int n = hanja_list_get_size(list); for (int i = 0; i < n; ++i) { const char* value = hanja_list_get_nth_value(list, i); const char* comment = hanja_list_get_nth_comment(list, i); WideString candidate = utf8_mbstowcs(value, -1); m_lookup_table.append_candidate(candidate); m_candidate_comments.push_back(String(comment)); } m_lookup_table.set_page_size (9); m_lookup_table.show_cursor (); update_lookup_table (m_lookup_table); show_lookup_table (); hangul_update_aux_string (); hanja_list_delete(list); } if (m_lookup_table.number_of_candidates() <= 0) { delete_candidates(); } }
FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) { CPDF_TextObject* pTextObj = Obj.m_pTextObj.Get(); size_t nContentMarks = pTextObj->m_ContentMarks.CountItems(); if (nContentMarks == 0) return FPDFText_MarkedContent::Pass; WideString actText; bool bExist = false; const CPDF_Dictionary* pDict = nullptr; for (size_t i = 0; i < nContentMarks; ++i) { const CPDF_ContentMarkItem* item = pTextObj->m_ContentMarks.GetItem(i); pDict = item->GetParam(); if (!pDict) continue; const CPDF_String* temp = ToString(pDict->GetObjectFor("ActualText")); if (temp) { bExist = true; actText = temp->GetUnicodeText(); } } if (!bExist) return FPDFText_MarkedContent::Pass; if (m_pPreTextObj) { const CPDF_ContentMarks& marks = m_pPreTextObj->m_ContentMarks; if (marks.CountItems() == nContentMarks && marks.GetItem(nContentMarks - 1)->GetParam() == pDict) { return FPDFText_MarkedContent::Done; } } if (actText.IsEmpty()) return FPDFText_MarkedContent::Pass; CPDF_Font* pFont = pTextObj->GetFont(); bExist = false; for (size_t i = 0; i < actText.GetLength(); ++i) { if (pFont->CharCodeFromUnicode(actText[i]) != CPDF_Font::kInvalidCharCode) { bExist = true; break; } } if (!bExist) return FPDFText_MarkedContent::Pass; bExist = false; for (size_t i = 0; i < actText.GetLength(); ++i) { wchar_t wChar = actText[i]; if ((wChar > 0x80 && wChar < 0xFFFD) || (wChar <= 0x80 && isprint(wChar))) { bExist = true; break; } } if (!bExist) return FPDFText_MarkedContent::Done; return FPDFText_MarkedContent::Delay; }
//===================================================================================== String IC_StrConv::toString( const WideString str ) { int len = str.size() + 1; c8* buf = new c8[len]; ::wcstombs( buf, str.c_str(), len ); String wstr = buf; delete[] buf; return wstr; }
/*!\brief Formatierten Text ausgeben * * \desc * Mit dieser Funktion wird zunächst ein Text anhand des Formatstrings * \p fmt erstellt und dann auf der Grafik an den * Koordinaten \p x und \p y unter Verwendeung des Fonts \p font ausgegeben. * * @param font Zu verwendende Font-Parameter * @param x X-Koordinate * @param y Y-Koordinate * @param fmt Formatstring * @param ... optionale Parameter für den Formatstring */ void Drawable::printf(const Font &font, int x, int y, const char *fmt, ...) { WideString s; va_list args; va_start(args, fmt); s.vasprintf(fmt,args); va_end(args); print(font,x,y,s); }
static std::string WideStringToString(WideString const &str) { int size = WideCharToMultiByte(CP_UTF8, 0, str.data(), (int)str.size(), NULL, 0, NULL, NULL); std::string multi = std::string(); multi.resize(size); WideCharToMultiByte(CP_UTF8, 0, str.data(), (int)str.size(), &multi[0], size, NULL, NULL); return multi; }
static WideString StringToWideString(std::string const &str) { int size = MultiByteToWideChar(CP_UTF8, 0, str.data(), (int)str.size(), NULL, 0); WideString wide = WideString(); wide.resize(size); MultiByteToWideChar(CP_UTF8, 0, str.data(), (int)str.size(), &wide[0], size); return wide; }
void LinkFrame::resetSize() { HDC hDC = GetDC(hWnd); SelectObject(hDC, hFont); SIZE sz; WideString text = getText(); GetTextExtentPoint32(hDC, text, text.length(), &sz); ReleaseDC(hWnd, hDC); setSize(sz.cx, sz.cy); }
HGLOBAL CreateGlobalText(WideString text) { HGLOBAL data = GlobalAlloc(GMEM_MOVEABLE, (text.length() + 1) * 2); wchar_t* ptr = (wchar_t*) GlobalLock(data); if (ptr) { wcscpy(ptr, text.c_str()); GlobalUnlock(data); } return data; }
void ButtonUnit::onRender( RenderContext & context, const RectInt & window ) { WindowButton::onRender( context, window ); if ( enabled() && m_Unit.valid() ) { GameDocument * pDoc = (GameDocument *)document(); ASSERT( pDoc ); NounShip * pShip = pDoc->ship(); if (! pShip ) return; DisplayDevice * pDisplay = context.display(); ASSERT( pDisplay ); // draw the gadget icon if ( m_Icon.valid() ) { RectInt iconBox( PointInt( window.left, window.top ), SizeInt( 32, 16 ) ); RectFloat iconUV(0,0,1,1); Material::push( context, m_Icon ); PrimitiveWindow::push( pDisplay, iconBox, iconUV, pShip->isFriend( m_Unit ) ? GREEN : pShip->isEnemy( m_Unit ) ? RED : YELLOW ); } // draw the unit health on the button Font * pFont = windowStyle()->font(); ASSERT( pFont ); WideString sHealth; sHealth.format( STR("%d%%"), 100 - ((m_Unit->damage() * 100) / m_Unit->maxDamage()) ); SizeInt szHealth( pFont->size( sHealth ) ); PointInt ptHealth( window.right - szHealth.width, window.bottom - szHealth.height ); Font::push( context.display(), pFont, ptHealth, sHealth, WHITE ); // display damage bar if ( m_Unit->damage() > 0 ) { float damage = 1.0f - (m_Unit->damage() / m_Unit->maxDamage()); RectInt bar( window.m_Left, window.m_Bottom + 1, window.m_Right - (window.width() * (1.0f - damage)), window.m_Bottom + 3 ); RectFloat barUV(0,0,1,1); Color barColor( 255 * (1.0f - damage), 255 * damage,0,255 ); PrimitiveMaterial::push( pDisplay, PrimitiveMaterial::NONE ); PrimitiveWindow::push( pDisplay, bar, barUV, barColor ); } // display blinking border if this unit is the current target if ( pDoc->target() == m_Unit && (pDoc->tick() % 10) < 6) renderGlow( context ); } }
TEST(fxstring, FX_UTF8EncodeDecodeConsistency) { WideString wstr; wstr.Reserve(0x10000); for (int w = 0; w < 0x10000; ++w) wstr += static_cast<wchar_t>(w); ByteString bstr = FX_UTF8Encode(wstr.AsStringView()); WideString wstr2 = FX_UTF8Decode(bstr.AsStringView()); EXPECT_EQ(0x10000u, wstr2.GetLength()); EXPECT_EQ(wstr, wstr2); }
WideString UITextField::GetAppliedChanges(int32 replacementLocation, int32 replacementLength, const WideString & replacementString) {//TODO: fix this for copy/paste WideString txt = GetText(); if(replacementLocation >= 0) { txt.replace(replacementLocation, replacementLength, replacementString); } return txt; }
/// @copydoc Serializer::SerializeWideString() void BinarySerializer::SerializeWideString( WideString& rValue ) { if( ShouldSerializeCurrentProperty() ) { HELIUM_ASSERT( rValue.GetSize() <= UINT32_MAX ); uint32_t stringLength = static_cast< uint32_t >( rValue.GetSize() ); m_pPropertyStream->Write( &stringLength, sizeof( stringLength ), 1 ); m_pPropertyStream->Write( rValue.GetData(), sizeof( wchar_t ), stringLength ); } }
bool CScript::RunFile( WideString a_fileName ) { FILE* scriptFile = NULL; char* fileString = NULL; int fileSize = 0; bool result = true; //a_fileName = APP.useFile( wide2string(a_fileName).c_str() ).c_str(); a_fileName = wide2string( a_fileName ).c_str(); GM_ASSERT( this ); if ( APP.DebugMode ) { WideString winfo = "Loading script file "; winfo += a_fileName; CONSOLE.add( winfo ); } char* ResultChar = new char[1024]; wcstombs( ResultChar, a_fileName.c_str(), 1024 ); if ( !( scriptFile = fopen( ResultChar, "rb" ) ) ) { return false; } fseek( scriptFile, 0, SEEK_END ); fileSize = ftell( scriptFile ); fseek( scriptFile, 0, SEEK_SET ); fileString = new char[fileSize + 1]; fread( fileString, fileSize, 1, scriptFile ); fileString[fileSize] = 0; // Terminating null fclose( scriptFile ); int threadId = GM_INVALID_THREAD; errors = machine->ExecuteString( fileString, &threadId, true, ResultChar ); if ( errors ) { WideString a; a = "Script error: "; a.append( a_fileName ); LogErrors( a ); result = false; } deltaTime = 1; lastTime = getPreciseTime(); delete[] fileString; delete ResultChar; return result; }
void RichEditFrame::setRichText(WideString text) { EditStreamCookie cookie; cookie.str = text; cookie.pos = 0; EDITSTREAM es; es.dwCookie = (DWORD_PTR) &cookie; es.dwError = 0; es.pfnCallback = StreamCallback; SendMessage(hWnd, EM_EXLIMITTEXT, 0, (text.length() < 32768 ? 32768 : text.length() + 1)); SendMessage(hWnd, EM_STREAMIN, SF_RTF, (uint32) &es); }