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; }
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 CJX_Field::defaultValue(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute) { CXFA_Node* xfaNode = GetXFANode(); if (!xfaNode->IsWidgetReady()) return; if (bSetting) { if (pValue) { xfaNode->SetPreNull(xfaNode->IsNull()); xfaNode->SetIsNull(pValue->IsNull()); } WideString wsNewText; if (pValue && !(pValue->IsNull() || pValue->IsUndefined())) wsNewText = pValue->ToWideString(); if (xfaNode->GetUIChildNode()->GetElementType() == XFA_Element::NumericEdit) wsNewText = xfaNode->NumericLimit(wsNewText); CXFA_Node* pContainerNode = xfaNode->GetContainerNode(); WideString wsFormatText(wsNewText); if (pContainerNode) wsFormatText = pContainerNode->GetFormatDataValue(wsNewText); SetContent(wsNewText, wsFormatText, true, true, true); return; } WideString content = GetContent(true); if (content.IsEmpty()) { pValue->SetNull(); return; } CXFA_Node* formValue = xfaNode->GetFormValueIfExists(); CXFA_Node* pNode = formValue ? formValue->GetFirstChild() : nullptr; if (pNode && pNode->GetElementType() == XFA_Element::Decimal) { if (xfaNode->GetUIChildNode()->GetElementType() == XFA_Element::NumericEdit && (pNode->JSObject()->GetInteger(XFA_Attribute::FracDigits) == -1)) { pValue->SetString(content.ToUTF8().AsStringView()); } else { CFX_Decimal decimal(content.AsStringView()); pValue->SetFloat((float)(double)decimal); } } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) { pValue->SetInteger(FXSYS_wtoi(content.c_str())); } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) { pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true); } else if (pNode && pNode->GetElementType() == XFA_Element::Float) { CFX_Decimal decimal(content.AsStringView()); pValue->SetFloat((float)(double)decimal); } else { pValue->SetString(content.ToUTF8().AsStringView()); } }
String StringUtils::wideString2utf8String( const WideString& wideString ) { size_t widesize = wideString.length(); String returnString; if ( sizeof( wchar_t ) == 2 ) { size_t utf8size = MAX_UTF8_CHAR_LENGTH * widesize + 1; returnString.resize( utf8size, '\0' ); const UTF16* sourcestart = reinterpret_cast<const UTF16*>( wideString.c_str() ); const UTF16* sourceend = sourcestart + widesize; UTF8* targetstart = reinterpret_cast<UTF8*>( &((returnString)[ 0 ]) ); UTF8* thisFirstWChar = targetstart; UTF8* targetend = targetstart + utf8size; ConversionResult res = ConvertUTF16toUTF8( &sourcestart, sourceend, &targetstart, targetend, strictConversion ); if ( res != conversionOK ) { throw Exception(Exception::ERROR_WIDE_2_UTF8, String("Could not convert from wide string to UTF8.")); } returnString.resize(targetstart - thisFirstWChar); } else if ( sizeof( wchar_t ) == 4 ) { size_t utf8size = MAX_UTF8_CHAR_LENGTH * widesize + 1; returnString.resize( utf8size, '\0' ); const UTF32* sourcestart = reinterpret_cast<const UTF32*>( wideString.c_str() ); const UTF32* sourceend = sourcestart + widesize; UTF8* targetstart = reinterpret_cast<UTF8*>( &((returnString)[ 0 ]) ); UTF8* thisFirstWChar = targetstart; UTF8* targetend = targetstart + utf8size; ConversionResult res = ConvertUTF32toUTF8( &sourcestart, sourceend, &targetstart, targetend, strictConversion ); if ( res != conversionOK ) { throw Exception(Exception::ERROR_WIDE_2_UTF8, String("Could not convert from wide string to UTF8.")); } returnString.resize(targetstart - thisFirstWChar); } else { throw Exception(Exception::ERROR_WIDE_2_UTF8, String("Could not convert from wide string to UTF8.")); } return returnString; }
Win32Stream::Win32Stream(const WideString& path, IO::Access access) : m_path(path) { DWORD wac = 0; if (access & IO::AccessRead) wac |= GENERIC_READ; if (access & IO::AccessWrite) wac |= GENERIC_WRITE; m_hFile = CreateFile(path.c_str(), wac, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0); if (m_hFile == INVALID_HANDLE_VALUE) Win32ThrowLastError("Win32Stream::Win32Stream '%S'", path.c_str()); Stats::IncrementCount(Stats::FileHandles); }
bool MailSender::SendEmail(const WideString& email, const WideString& subject, const WideString& messageText) { // Don't try to send email if recipient is not set if (email.empty() || email == L"") return false; WideString mailtoText = L""; // Create mailto text mailtoText = Format(L"mailto:?to=%s&subject=%s&body=%s", email.c_str(), subject.c_str(), messageText.c_str()); // Call default mail client int result = (int)ShellExecute(NULL, L"open", mailtoText.c_str(), NULL, NULL, SW_SHOWNORMAL); // If the function succeeds, it returns a value greater than 32. // If the function fails, it returns an error value that indicates the cause of the failure. return (result > 32); }
int ComboFrame::addString(WideString text, int data) { int id = SendMessage(hWnd, CB_ADDSTRING, 0, (uint32) text.c_str()); if (id != CB_ERR) SendMessage(hWnd, CB_SETITEMDATA, id, data); return id; }
//-------------------------------- bool Utils::directoryExists( const WideString &pathString ) { bool pathExists = false; #ifdef COLLADABU_OS_WIN SystemType type = getSystemType(); if( type != WINDOWS ) return false; const wchar_t* currentPath = _wgetcwd( 0, 0); const wchar_t* testPath = pathString.c_str(); pathExists = _wchdir( testPath ) == 0; _wchdir( currentPath ); return pathExists; #else SystemType type = getSystemType(); if( type != POSIX ) return false; //... #endif return pathExists; }
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()); }
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; } }
QString WideString2QStrint(const WideString& str) { #ifdef __DAVAENGINE_MACOS__ return QString::fromStdWString(str); #else return QString((const QChar*)str.c_str(), str.length()); #endif }
//===================================================================================== 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; }
String UTF8Utils::EncodeToUTF8(const WideString& wstring) { int32 bufSize = WideCharToMultiByte(CP_UTF8, 0, wstring.c_str(), -1, 0, 0, NULL, NULL); if (!bufSize) { return ""; } String resStr = ""; char* buf = new char[bufSize]; int32 res = WideCharToMultiByte(CP_UTF8, 0, wstring.c_str(), -1, buf, bufSize, NULL, NULL); if (res) { resStr = String(buf); } delete[] buf; return resStr; };
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; }
int ComboFrameEx::addString(WideString text, HICON hIcon, int data) { int id = items.length(); Item& item = items.push(); item.data = data; item.icon = hIcon; item.text = text; int pos = SendMessage(hWnd, CB_ADDSTRING, 0, (uint32) text.c_str()); if (pos != CB_ERR) SendMessage(hWnd, CB_SETITEMDATA, pos, id); return pos; }
Node* Win32Node::open(const FileName& child) { WideString wpath = m_path; wpath += '\\'; UTF8ToUCS2(wpath, child.str()); if (GetFileAttributesW(wpath.c_str()) == INVALID_FILE_ATTRIBUTES) Win32ThrowLastError("%s", child.c_str()); Win32Node* node = new Win32Node(child, wpath); return node; }
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 NativeString::fromWideString( const WideString& wideString ) { #ifdef COLLADABU_OS_WIN int multibyteLength = WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)wideString.c_str(), -1, 0, 0, 0, 0 ); char * dest = new char[ multibyteLength ]; WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)wideString.c_str(), -1, dest, multibyteLength, 0, 0 ); this->assign( dest ); delete[] dest; #elif defined (COLLADABU_OS_LINUX) || defined (COLLADABU_OS_MAC) //# error check if this really works on linux size_t maxStringLength = wcstombs( 0, wideString.c_str(), 0 ) + 1; // wideString.length()*MB_CUR_MAX + 1; char* dest = new char[ maxStringLength ]; wcstombs( dest, wideString.c_str(), maxStringLength ); this->assign( dest ); delete[] dest; #else # error "No StringUtil::toString defined for your platform" #endif }
WideString CPDF_FileSpec::DecodeFileName(const WideString& filepath) { if (filepath.GetLength() <= 1) return WideString(); #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ if (filepath.Left(sizeof("/Mac") - 1) == WideStringView(L"/Mac")) return ChangeSlashToPlatform(filepath.c_str() + 1); return ChangeSlashToPlatform(filepath.c_str()); #elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ if (filepath[0] != L'/') return ChangeSlashToPlatform(filepath.c_str()); if (filepath[1] == L'/') return ChangeSlashToPlatform(filepath.c_str() + 1); if (filepath[2] == L'/') { WideString result; result += filepath[1]; result += L':'; result += ChangeSlashToPlatform(filepath.c_str() + 2); return result; } WideString result; result += L'\\'; result += ChangeSlashToPlatform(filepath.c_str()); return result; #else return WideString(filepath); #endif }
WideString CPDF_FileSpec::EncodeFileName(const WideString& filepath) { if (filepath.GetLength() <= 1) return WideString(); #if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ if (filepath[1] == L':') { WideString result(L'/'); result += filepath[0]; if (filepath[2] != L'\\') result += L'/'; result += ChangeSlashToPDF(filepath.c_str() + 2); return result; } if (filepath[0] == L'\\' && filepath[1] == L'\\') return ChangeSlashToPDF(filepath.c_str() + 1); if (filepath[0] == L'\\') return L'/' + ChangeSlashToPDF(filepath.c_str()); return ChangeSlashToPDF(filepath.c_str()); #elif _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ if (filepath.Left(sizeof("Mac") - 1).EqualsASCII("Mac")) return L'/' + ChangeSlashToPDF(filepath.c_str()); return ChangeSlashToPDF(filepath.c_str()); #else return WideString(filepath); #endif }
TEST_F(CFGAS_FormatStringTest, NullFormat) { struct { const wchar_t* locale; const wchar_t* pattern; const wchar_t* output; } tests[] = {{L"en", L"null{'n/a'}", L"n/a"}, {L"en", L"null{}", L""}}; for (size_t i = 0; i < FX_ArraySize(tests); ++i) { WideString result; EXPECT_TRUE(fmt(tests[i].locale)->FormatNull(tests[i].pattern, &result)); EXPECT_STREQ(tests[i].output, result.c_str()) << " TEST: " << i; } }
TEST_F(CFGAS_FormatStringTest, TimeFormat) { struct { const wchar_t* locale; const wchar_t* input; const wchar_t* pattern; const wchar_t* output; } tests[] = {{L"en", L"01:01:11", L"h:M A", L"1:1 AM"}, {L"en", L"13:01:11", L"h:M A", L"1:1 PM"}, {L"en", L"01:01:11", L"hh:MM:SS A", L"01:01:11 AM"}, {L"en", L"13:01:11", L"hh:MM:SS A", L"01:01:11 PM"}, {L"en", L"01:01:11", L"hh:MM:SS A Z", L"01:01:11 AM GMT-02:00"}, {L"en", L"01:01:11", L"hh:MM:SS A z", L"01:01:11 AM -02:00"}, // {L"en", L"01:01:11", L"hh:MM:SS A zz", L"01:01:11 AM GMT"}, // Should change ?*+ into ' ' when formatting. // {L"en", L"01:01:11", L"hh:MM:SS?*+A", L"01:01:11 AM"}, {L"en", L"12:01:01", L"k:MM:SS", L"12:01:01"}, {L"en", L"14:01:01", L"k:MM:SS", L"2:01:01"}, {L"en", L"12:01:11", L"kk:MM", L"12:01"}, {L"en", L"14:01:11", L"kk:MM", L"02:01"}, {L"en", L"12:01:11 +04:30", L"kk:MM", L"05:31"}, {L"en", L"12:01:11", L"kk:MM A", L"12:01 PM"}, {L"en", L"00:01:01", L"H:M:S", L"0:1:1"}, {L"en", L"13:02:11", L"H:M:S", L"13:2:11"}, {L"en", L"00:01:11.001", L"HH:M:S.FFF", L"00:1:11.001"}, {L"en", L"13:02:11", L"HH:M", L"13:2"}, {L"en", L"00:01:11", L"K:M", L"24:1"}, {L"en", L"00:02:11", L"KK:M", L"24:2"}, {L"en", L"11:11:11", L"HH:MM:SS 'o''clock' A Z", L"11:11:11 o'clock AM GMT-02:00"}, {L"en", L"14:30:59", L"h:MM A", L"2:30 PM"}, {L"en", L"14:30:59", L"HH:MM:SS A Z", L"14:30:59 PM GMT-02:00"}}; // Note, none of the full width time symbols are listed here // as they are not supported. In theory there are the full // width versions of kkk, kkkk, HHH, HHHH, KKK, KKKK, MMM, MMMM, // SSS, SSSS plus 2 more that the spec apparently forgot to // list the symbol. // The z modifier only appends if the TZ is outside of +0 SetTZ("UTC+2"); 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_Time, &result)); EXPECT_STREQ(tests[i].output, result.c_str()) << " TEST: " << i; } SetTZ("UTC"); }
ImpNode* SceneGraphCreator::importInstance( const COLLADAFW::Node* node, INode* parentINode ) { const COLLADAFW::PointerArray<Instance>& instances = (node->*getInstances)(); if ( instances.getCount() != 1 ) return 0; ImpNode* newImportNode = getMaxImportInterface()->CreateNode(); setNodeProperties(node, newImportNode); INode* newNode = newImportNode->GetINode(); Instance* instance = instances[0]; const COLLADAFW::UniqueId& uniqueId = instance->getInstanciatedObjectId(); Object* object = getObjectByUniqueId(uniqueId); if ( object ) { newImportNode->Reference(object); const String& objectName = getObjectNameByObject(object); if ( node->getName().empty() && !objectName.empty() ) { #ifdef UNICODE WideString wideObjectName = COLLADABU::StringUtils::toWideString(objectName.c_str()); newImportNode->SetName( wideObjectName.c_str() ); #else newImportNode->SetName( objectName.c_str() ); #endif } } else { newImportNode->Reference( getDummyObject() ); } const COLLADAFW::UniqueId& instanceGeometryUniqueId = instance->getInstanciatedObjectId(); // Store mapping between unique ids and nodes referencing the corresponding object. // Used to clone nodes addObjectINodeUniqueIdPair(newNode, instanceGeometryUniqueId); // Used to resolve instancing of objects addUniqueIdObjectINodePair(instanceGeometryUniqueId, newNode); parentINode->AttachChild(newNode, FALSE); // post process the creation if ( postProcess ) (this->*postProcess)(newNode, instance); return newImportNode; }
//-------------------------------- bool Utils::directoryExists( const WideString &pathString ) { bool pathExists = false; SystemType type = getSystemType(); if( type != WINDOWS ) return false; const wchar_t* currentPath = _wgetcwd( 0, 0); const wchar_t* testPath = pathString.c_str(); pathExists = _wchdir( testPath ) == 0; _wchdir( currentPath ); return pathExists; }
int BaseFontTT::getTextWidth(const byte *text, int maxLength) { WideString textStr; if (_gameRef->_textEncoding == TEXT_UTF8) { textStr = StringUtil::utf8ToWide((const char *)text); } else { textStr = StringUtil::ansiToWide((const char *)text); } if (maxLength >= 0 && textStr.size() > (uint32)maxLength) { textStr = WideString(textStr.c_str(), (uint32)maxLength); } //text = text.substr(0, MaxLength); // TODO: Remove int textWidth, textHeight; measureText(textStr, -1, -1, textWidth, textHeight); return textWidth; }
//------------------------------ void SceneGraphCreator::setNodeProperties( const COLLADAFW::Node* node, ImpNode* importNode ) { const String& newNodeName = node->getName(); if ( !newNodeName.empty() ) { #ifdef UNICODE WideString wideNodeName = COLLADABU::StringUtils::toWideString(newNodeName.c_str()); importNode->SetName(wideNodeName.c_str()); #else importNode->SetName(newNodeName.c_str()); #endif } // set transform. we always do this. If there is an animation, the controller will be changed COLLADABU::Math::Matrix4 transformationMatrix; node->getTransformationMatrix(transformationMatrix); Matrix3 maxTransformationMatrix; Matrix4ToMaxMatrix3(maxTransformationMatrix, transformationMatrix); importNode->SetTransform(0, maxTransformationMatrix); }
retval_t ScimBridgeAgentClientListenerImpl::set_preedit_string (scim_bridge_imcontext_id_t imcontext_id, const WideString &wstring) { scim_bridge_pdebugln (6, "set_preedit_string ()"); ScimBridgeMessage *message = scim_bridge_alloc_message (SCIM_BRIDGE_MESSAGE_SET_PREEDIT_STRING, 2); char *imcontext_id_str; scim_bridge_string_from_uint (&imcontext_id_str, imcontext_id); scim_bridge_message_set_argument (message, 0, imcontext_id_str); free (imcontext_id_str); char *preedit_str; scim_bridge_wstring_to_string (&preedit_str, wstring.c_str ()); scim_bridge_message_set_argument (message, 1, preedit_str); free (preedit_str); scim_bridge_messenger_push_message (messenger, message); scim_bridge_free_message (message); return RETVAL_SUCCEEDED; }
TEST_F(CFGAS_FormatStringTest, ZeroFormat) { struct { const wchar_t* locale; const wchar_t* input; const wchar_t* pattern; const wchar_t* output; } tests[] = {// TODO(dsinclair): The zero format can take a number specifier // which we don't take into account. // {L"en", L"", L"zero {9}", L""}, // {L"en", L"0", L"zero {9}", L"0"}, // {L"en", L"0.0", L"zero{9}", L"0"}, {L"en", L"0", L"zero{}", L""}}; for (size_t i = 0; i < FX_ArraySize(tests); ++i) { WideString result; EXPECT_TRUE( fmt(tests[i].locale) ->FormatZero(/* tests[i].input,*/ tests[i].pattern, &result)); EXPECT_STREQ(tests[i].output, result.c_str()) << " TEST: " << i; } }
TEST_F(CFGAS_FormatStringTest, TextFormat) { struct { const wchar_t* locale; const wchar_t* input; const wchar_t* pattern; const wchar_t* output; } tests[] = { {L"en", L"K1S5K2", L"A9A 9A9", L"K1S 5K2"}, {L"en", L"K1S5K2", L"text(fr){A9A 9A9}", L"K1S 5K2"}, {L"en", L"6135551212", L"'+1 ('9\u002399') '999-9999", L"+1 (6#13) 555-1212"}, {L"en", L"6135551212", L"999.999.9999", L"613.555.1212"}, {L"en", L"6135551212", L"999\u0023999\u002A9999", L"613#555*1212"}, {L"en", L"K1#5K2", L"00X OO9", L"K1# 5K2"}, }; for (size_t i = 0; i < FX_ArraySize(tests); ++i) { WideString result; EXPECT_TRUE(fmt(tests[i].locale) ->FormatText(tests[i].input, tests[i].pattern, &result)); EXPECT_STREQ(tests[i].output, result.c_str()) << " TEST: " << i; } }