void CXFA_NodeHelper::GetNameExpression(CXFA_Node* refNode, CFX_WideString& wsName, FX_BOOL bIsAllPath, XFA_LOGIC_TYPE eLogicType) { wsName.clear(); if (bIsAllPath) { GetNameExpression(refNode, wsName, FALSE, eLogicType); CFX_WideString wsParent; CXFA_Node* parent = ResolveNodes_GetParent(refNode, XFA_LOGIC_NoTransparent); while (parent) { GetNameExpression(parent, wsParent, FALSE, eLogicType); wsParent += L"."; wsParent += wsName; wsName = wsParent; parent = ResolveNodes_GetParent(parent, XFA_LOGIC_NoTransparent); } return; } CFX_WideString ws; FX_BOOL bIsProperty = NodeIsProperty(refNode); if (refNode->IsUnnamed() || (bIsProperty && refNode->GetElementType() != XFA_Element::PageSet)) { ws = refNode->GetClassName(); wsName.Format(L"#%s[%d]", ws.c_str(), GetIndex(refNode, eLogicType, bIsProperty, TRUE)); return; } ws = refNode->GetCData(XFA_ATTRIBUTE_Name); ws.Replace(L".", L"\\."); wsName.Format(L"%s[%d]", ws.c_str(), GetIndex(refNode, eLogicType, bIsProperty, FALSE)); }
void IFWL_DateTimePicker::FormatDateString(int32_t iYear, int32_t iMonth, int32_t iDay, CFX_WideString& wsText) { if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_ShortDateFormat) == FWL_STYLEEXT_DTP_ShortDateFormat) { wsText.Format(L"%d-%d-%d", iYear, iMonth, iDay); } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_LongDateFormat) == FWL_STYLEEXT_DTP_LongDateFormat) { wsText.Format(L"%d Year %d Month %d Day", iYear, iMonth, iDay); } }
void CXFA_FFDocView::ShowNullTestMsg() { int32_t iCount = m_arrNullTestMsg.GetSize(); CXFA_FFApp* pApp = m_pDoc->GetApp(); IXFA_AppProvider* pAppProvider = pApp->GetAppProvider(); if (pAppProvider && iCount) { int32_t iRemain = iCount > 7 ? iCount - 7 : 0; iCount -= iRemain; CFX_WideString wsMsg; for (int32_t i = 0; i < iCount; i++) { wsMsg += m_arrNullTestMsg[i] + FX_WSTRC(L"\n"); } if (iRemain > 0) { CFX_WideString wsLimit; pAppProvider->LoadString(XFA_IDS_ValidateLimit, wsLimit); if (!wsLimit.IsEmpty()) { CFX_WideString wsTemp; wsTemp.Format((const FX_WCHAR*)wsLimit, iRemain); wsMsg += FX_WSTRC(L"\n") + wsTemp; } } CFX_WideString wsTitle; pAppProvider->LoadString(XFA_IDS_AppName, wsTitle); pAppProvider->MsgBox(wsMsg, wsTitle, XFA_MBICON_Status, XFA_MB_OK); } m_arrNullTestMsg.RemoveAll(); }
void CPWL_NoteItem::ResetSubjectName(FX_INT32 nItemIndex) { if (nItemIndex < 0) { if (CPWL_Wnd* pParent = this->GetParentWindow()) { ASSERT(pParent->GetClassName() == "CPWL_Note_Contents"); CPWL_Note_Contents* pContents = (CPWL_Note_Contents*)pParent; nItemIndex = pContents->GetItemIndex(this); } } const CPWL_Note* pNote = GetNote(); ASSERT(pNote != NULL); CFX_WideString sSubject; sSubject.Format(pNote->GetReplyString(), nItemIndex); if (!m_sAuthor.IsEmpty()) { sSubject += L" - "; sSubject += m_sAuthor; } this->SetSubjectName(sSubject); this->RePosChildWnd(); }
void CXFA_Fill::SetColor(FX_ARGB color) { CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_Element::Color); CFX_WideString wsColor; int a, r, g, b; ArgbDecode(color, a, r, g, b); wsColor.Format(L"%d,%d,%d", r, g, b); pNode->SetCData(XFA_ATTRIBUTE_Value, wsColor); }
FX_BOOL CJS_Context::DoJob(int nMode, const CFX_WideString& script, CFX_WideString& info) { if (m_bBusy) { info = JSGetStringFromID(this, IDS_STRING_JSBUSY); return FALSE; } m_bBusy = TRUE; ASSERT(m_pRuntime != NULL); ASSERT(m_pEventHandler != NULL); ASSERT(m_pEventHandler->IsValid()); if (!m_pRuntime->AddEventToLoop(m_pEventHandler->TargetName(), m_pEventHandler->EventType())) { info = JSGetStringFromID(this, IDS_STRING_JSEVENT); return FALSE; } FXJSErr error ={NULL,NULL, 0}; int nRet = 0; if (script.GetLength() > 0) { if (nMode == 0) { nRet = JS_Execute(*m_pRuntime, this, script.c_str(), script.GetLength(), &error); } else { nRet = JS_Parse(*m_pRuntime, this, script.c_str(), script.GetLength(), &error); } } if (nRet < 0) { CFX_WideString sLine; sLine.Format(L"[ Line: %05d { %s } ] : %s",error.linnum-1,error.srcline,error.message); // TRACE(L"/* -------------- JS Error -------------- */\n"); // TRACE(sLine); // TRACE(L"\n"); //CFX_ByteString sTemp = CFX_ByteString::FromUnicode(error.message); info += sLine; } else { info = JSGetStringFromID(this, IDS_STRING_RUN); } m_pRuntime->RemoveEventInLoop(m_pEventHandler->TargetName(), m_pEventHandler->EventType()); m_pEventHandler->Destroy(); m_bBusy = FALSE; return nRet >= 0; }
CFX_WideString CXFA_FFNotify::GetCurrentDateTime() { CFX_Unitime dataTime; dataTime.Now(); CFX_WideString wsDateTime; wsDateTime.Format(L"%d%02d%02dT%02d%02d%02d", dataTime.GetYear(), dataTime.GetMonth(), dataTime.GetDay(), dataTime.GetHour(), dataTime.GetMinute(), dataTime.GetSecond()); return wsDateTime; }
FX_BOOL CXFA_LocaleValue::SetTime(const CFX_Unitime& t) { m_dwType = XFA_VT_TIME; m_wsValue.Format(L"%02d:%02d:%02d", t.GetHour(), t.GetMinute(), t.GetSecond()); if (t.GetMillisecond() > 0) { CFX_WideString wsTemp; wsTemp.Format(L"%:03d", t.GetMillisecond()); m_wsValue += wsTemp; } return TRUE; }
FX_BOOL CXFA_LocaleValue::SetDateTime(const CFX_Unitime& dt) { m_dwType = XFA_VT_DATETIME; m_wsValue.Format(L"%04d-%02d-%02dT%02d:%02d:%02d", dt.GetYear(), dt.GetMonth(), dt.GetDay(), dt.GetHour(), dt.GetMinute(), dt.GetSecond()); if (dt.GetMillisecond() > 0) { CFX_WideString wsTemp; wsTemp.Format(L"%:03d", dt.GetMillisecond()); m_wsValue += wsTemp; } return TRUE; }
FX_BOOL util::byteToChar(OBJ_METHOD_PARAMS) { int iSize = params.size(); if (iSize == 0) return FALSE; int nByte = (int)params[0]; unsigned char cByte = (unsigned char)nByte; CFX_WideString csValue; csValue.Format((FX_LPCWSTR)L"%c", cByte); vRet = csValue; return TRUE; }
FX_BOOL util::byteToChar(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { int iSize = params.size(); if (iSize == 0) return FALSE; int nByte = params[0].ToInt(); unsigned char cByte = (unsigned char)nByte; CFX_WideString csValue; csValue.Format(L"%c", cByte); vRet = csValue.c_str(); return TRUE; }
void CXFA_Stroke::SetColor(FX_ARGB argb) { if (!m_pNode) return; CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_Element::Color); CFX_WideString wsColor; int a; int r; int g; int b; ArgbDecode(argb, a, r, g, b); wsColor.Format(L"%d,%d,%d", r, g, b); pNode->SetCData(XFA_ATTRIBUTE_Value, wsColor); }
void CXFA_NodeHelper::XFA_GetNameExpression(CXFA_Node* refNode, CFX_WideString& wsName, FX_BOOL bIsAllPath, XFA_LOGIC_TYPE eLogicType) { wsName.Empty(); if (bIsAllPath) { XFA_GetNameExpression(refNode, wsName, FALSE, eLogicType); CFX_WideString wsParent; CXFA_Node* parent = XFA_ResolveNodes_GetParent(refNode, XFA_LOGIC_NoTransparent); while (parent != NULL) { XFA_GetNameExpression(parent, wsParent, FALSE, eLogicType); wsParent += L"."; wsParent += wsName; wsName = wsParent; parent = XFA_ResolveNodes_GetParent(parent, XFA_LOGIC_NoTransparent); } return; } else { CFX_WideStringC wsTagName; CFX_WideString ws; FX_BOOL bIsProperty = XFA_NodeIsProperty(refNode); if (refNode->IsUnnamed() || (bIsProperty && refNode->GetClassID() != XFA_ELEMENT_PageSet)) { refNode->GetClassName(wsTagName); ws = wsTagName; wsName.Format(L"#%s[%d]", (const FX_WCHAR*)ws, XFA_GetIndex(refNode, eLogicType, bIsProperty, TRUE)); return; } ws = refNode->GetCData(XFA_ATTRIBUTE_Name); ws.Replace(L".", L"\\."); wsName.Format(L"%s[%d]", (const FX_WCHAR*)ws, XFA_GetIndex(refNode, eLogicType, bIsProperty, FALSE)); } }
void CXFA_FFTextEdit::ValidateNumberField(const CFX_WideString& wsText) { CXFA_WidgetAcc* pAcc = GetDataAcc(); if (pAcc && pAcc->GetUIType() == XFA_Element::NumericEdit) { IXFA_AppProvider* pAppProvider = GetApp()->GetAppProvider(); if (pAppProvider) { CFX_WideString wsTitle; pAppProvider->LoadString(XFA_IDS_AppName, wsTitle); CFX_WideString wsError; pAppProvider->LoadString(XFA_IDS_ValidateNumberError, wsError); CFX_WideString wsSomField; pAcc->GetNode()->GetSOMExpression(wsSomField); CFX_WideString wsMessage; wsMessage.Format(wsError.c_str(), wsText.c_str(), wsSomField.c_str()); pAppProvider->MsgBox(wsMessage, wsTitle, XFA_MBICON_Error, XFA_MB_OK); } } }
void CPWL_NoteItem::SetDateTime(FX_SYSTEMTIME time) { m_dtNote = time; CFX_WideString swTime; swTime.Format((FX_LPCWSTR)L"%04d-%02d-%02d %02d:%02d:%02d", time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond); if (m_pDateTime) { m_pDateTime->SetText(swTime); } this->RePosChildWnd(); if (IPWL_NoteNotify* pNotify = GetNoteNotify()) { pNotify->OnSetDateTime(this); } }
static CFX_WideString _GetLabelNumPortion(int num, const CFX_ByteString& bsStyle) { CFX_WideString wsNumPortion; if (bsStyle.IsEmpty()) { return wsNumPortion; } if (bsStyle == "D") { wsNumPortion.Format(L"%d", num); } else if (bsStyle == "R") { wsNumPortion = _MakeRoman(num); wsNumPortion.MakeUpper(); } else if (bsStyle == "r") { wsNumPortion = _MakeRoman(num); } else if (bsStyle == "A") { wsNumPortion = _MakeLetters(num); wsNumPortion.MakeUpper(); } else if (bsStyle == "a") { wsNumPortion = _MakeLetters(num); } return wsNumPortion; }
CFX_WideString CPDF_PageLabel::GetLabel(int nPage) const { CFX_WideString wsLabel; if (m_pDocument == NULL) { return wsLabel; } CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot(); if (pPDFRoot == NULL) { return wsLabel; } CPDF_Dictionary* pLabels = pPDFRoot->GetDict(FX_BSTRC("PageLabels")); CPDF_NumberTree numberTree(pLabels); CPDF_Object* pValue = NULL; int n = nPage; while (n >= 0) { pValue = numberTree.LookupValue(n); if (pValue != NULL) { break; } n--; } if (pValue != NULL) { pValue = pValue->GetDirect(); if (pValue->GetType() == PDFOBJ_DICTIONARY) { CPDF_Dictionary* pLabel = (CPDF_Dictionary*)pValue; if (pLabel->KeyExist(FX_BSTRC("P"))) { wsLabel += pLabel->GetUnicodeText(FX_BSTRC("P")); } CFX_ByteString bsNumberingStyle = pLabel->GetString(FX_BSTRC("S"), NULL); int nLabelNum = nPage - n + pLabel->GetInteger(FX_BSTRC("St"), 1); CFX_WideString wsNumPortion = _GetLabelNumPortion(nLabelNum, bsNumberingStyle); wsLabel += wsNumPortion; return wsLabel; } } wsLabel.Format(L"%d", nPage + 1); return wsLabel; }
CFX_WideString CPDF_PageLabel::GetLabel(int nPage) const { CFX_WideString wsLabel; if (!m_pDocument) { return wsLabel; } CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot(); if (!pPDFRoot) { return wsLabel; } CPDF_Dictionary* pLabels = pPDFRoot->GetDictBy("PageLabels"); CPDF_NumberTree numberTree(pLabels); CPDF_Object* pValue = NULL; int n = nPage; while (n >= 0) { pValue = numberTree.LookupValue(n); if (pValue) { break; } n--; } if (pValue) { pValue = pValue->GetDirect(); if (CPDF_Dictionary* pLabel = pValue->AsDictionary()) { if (pLabel->KeyExist("P")) { wsLabel += pLabel->GetUnicodeTextBy("P"); } CFX_ByteString bsNumberingStyle = pLabel->GetStringBy("S", NULL); int nLabelNum = nPage - n + pLabel->GetIntegerBy("St", 1); CFX_WideString wsNumPortion = _GetLabelNumPortion(nLabelNum, bsNumberingStyle); wsLabel += wsNumPortion; return wsLabel; } } wsLabel.Format(L"%d", nPage + 1); return wsLabel; }
TEST(fxcrt, WideStringFormatWidth) { { CFX_WideString str; str.Format(L"%5d", 1); EXPECT_EQ(L" 1", str); } { CFX_WideString str; str.Format(L"%d", 1); EXPECT_EQ(L"1", str); } { CFX_WideString str; str.Format(L"%*d", 5, 1); EXPECT_EQ(L" 1", str); } { CFX_WideString str; str.Format(L"%-1d", 1); EXPECT_EQ(L"1", str); } { CFX_WideString str; str.Format(L"%0d", 1); EXPECT_EQ(L"1", str); } { CFX_WideString str; str.Format(L"%1048576d", 1); EXPECT_EQ(L"Bad width", str); } }
TEST(fxcrt, WideStringFormatPrecision) { { CFX_WideString str; str.Format(L"%.2f", 1.12345); EXPECT_EQ(L"1.12", str); } { CFX_WideString str; str.Format(L"%.*f", 3, 1.12345); EXPECT_EQ(L"1.123", str); } { CFX_WideString str; str.Format(L"%f", 1.12345); EXPECT_EQ(L"1.123450", str); } { CFX_WideString str; str.Format(L"%-1f", 1.12345); EXPECT_EQ(L"1.123450", str); } { CFX_WideString str; str.Format(L"%0f", 1.12345); EXPECT_EQ(L"1.123450", str); } { CFX_WideString str; str.Format(L"%.1048576f", 1.2); EXPECT_EQ(L"Bad precision", str); } }
FX_BOOL util::printf(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { int iSize = params.size(); if (iSize < 1) return FALSE; std::wstring c_ConvChar(params[0].ToCFXWideString().c_str()); std::vector<std::wstring> c_strConvers; int iOffset = 0; int iOffend = 0; c_ConvChar.insert(c_ConvChar.begin(),L'S'); while(iOffset != -1) { iOffend = c_ConvChar.find(L"%",iOffset+1); std::wstring strSub; if (iOffend == -1) strSub = c_ConvChar.substr(iOffset); else strSub = c_ConvChar.substr(iOffset ,iOffend - iOffset); c_strConvers.push_back(strSub); iOffset = iOffend ; } std::wstring c_strResult; //for(int iIndex = 1;iIndex < params.size();iIndex++) std::wstring c_strFormat; for(int iIndex = 0;iIndex < (int)c_strConvers.size();iIndex++) { c_strFormat = c_strConvers[iIndex]; if (iIndex == 0) { c_strResult = c_strFormat; continue; } CFX_WideString strSegment; if (iIndex >= iSize) { c_strResult += c_strFormat; continue; } switch (ParstDataType(&c_strFormat)) { case UTIL_INT: strSegment.Format(c_strFormat.c_str(), params[iIndex].ToInt()); break; case UTIL_DOUBLE: strSegment.Format(c_strFormat.c_str(), params[iIndex].ToDouble()); break; case UTIL_STRING: strSegment.Format(c_strFormat.c_str(), params[iIndex].ToCFXWideString().c_str()); break; default: strSegment.Format(L"%S", c_strFormat.c_str()); break; } c_strResult += strSegment.GetBuffer(strSegment.GetLength()+1); } c_strResult.erase(c_strResult.begin()); vRet = c_strResult.c_str(); return TRUE; }
FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { v8::Isolate* isolate = GetIsolate(cc); int iSize = params.size(); if (iSize < 2) return FALSE; CJS_Value p1(isolate); p1 = params[0]; CJS_Value p2 = params[1]; CJS_Date jsDate(isolate); if (!p2.ConvertToDate(jsDate)) { sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT1); return FALSE; } if (!jsDate.IsValidDate()) { sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT2); return FALSE; } if (p1.GetType() == VT_number) { int nFormat = p1.ToInt(); CFX_WideString swResult; switch (nFormat) { case 0: swResult.Format(L"D:%04d%02d%02d%02d%02d%02d", jsDate.GetYear(), jsDate.GetMonth() + 1, jsDate.GetDay(), jsDate.GetHours(), jsDate.GetMinutes(), jsDate.GetSeconds()); break; case 1: swResult.Format(L"%04d.%02d.%02d %02d:%02d:%02d", jsDate.GetYear(), jsDate.GetMonth() + 1, jsDate.GetDay(), jsDate.GetHours(), jsDate.GetMinutes(), jsDate.GetSeconds()); break; case 2: swResult.Format(L"%04d/%02d/%02d %02d:%02d:%02d", jsDate.GetYear(), jsDate.GetMonth() + 1, jsDate.GetDay(), jsDate.GetHours(), jsDate.GetMinutes(), jsDate.GetSeconds()); break; default: return FALSE; } vRet = swResult.c_str(); return TRUE; } else if (p1.GetType() == VT_string) { std::basic_string<wchar_t> cFormat = p1.ToCFXWideString().c_str(); bool bXFAPicture = false; if (iSize > 2) { bXFAPicture = params[2].ToBool(); } if (bXFAPicture) { return FALSE; //currently, it doesn't support XFAPicture. } int iIndex; for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIndex++) { int iStart = 0; int iEnd; while((iEnd = cFormat.find(fcTable[iIndex].lpszJSMark, iStart)) != -1) { cFormat.replace(iEnd, FXSYS_wcslen(fcTable[iIndex].lpszJSMark), fcTable[iIndex].lpszCppMark); iStart = iEnd; } } int iYear,iMonth,iDay,iHour,iMin,iSec; iYear = jsDate.GetYear(); iMonth = jsDate.GetMonth(); iDay = jsDate.GetDay(); iHour = jsDate.GetHours(); iMin = jsDate.GetMinutes(); iSec = jsDate.GetSeconds(); struct tm time = {}; time.tm_year = iYear-1900; time.tm_mon = iMonth; time.tm_mday = iDay; time.tm_hour = iHour; time.tm_min = iMin; time.tm_sec = iSec; //COleDateTime cppTm(iYear,iMonth+1,iDay,iHour,iMin,iSec); //CString strFormat = cppTm.Format(cFormat.c_str()); struct stru_TbConvertAd { const FX_WCHAR* lpszJSMark; int iValue; }; stru_TbConvertAd cTableAd[] ={ { L"m", iMonth+1 }, { L"d", iDay }, { L"H", iHour }, { L"h", iHour>12?iHour-12:iHour }, { L"M", iMin }, { L"s", iSec }, }; //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1); for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd);iIndex++) { wchar_t tszValue[10]; //_itot(cTableAd[iIndex].iValue,tszValue,10); CFX_WideString sValue; sValue.Format(L"%d",cTableAd[iIndex].iValue); memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetLength()+1), (sValue.GetLength()+1)*sizeof(wchar_t)); //strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d"); //strFormat.Format(strFormat,cTableAd[iIndex].iValue); int iStart = 0; int iEnd; while((iEnd = cFormat.find(cTableAd[iIndex].lpszJSMark, iStart)) != -1) { if (iEnd > 0) { if (cFormat[iEnd-1] == L'%') { iStart = iEnd+1; continue; } } cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[iIndex].lpszJSMark), tszValue); iStart = iEnd; } } CFX_WideString strFormat; // strFormat.Format(L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour, iMin, iSec); // CString strFormat = cppTm.Format(cFormat.c_str()); wchar_t buf[64] = {}; strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); cFormat = buf; vRet = cFormat.c_str(); //rtRet = strFormat.GetBuffer(strFormat.GetLength()+1); return TRUE; } return FALSE; }
void util::printd(const std::wstring &cFormat2, CJS_Date jsDate, bool bXFAPicture, std::wstring &cPurpose) { std::wstring cFormat = cFormat2; if (bXFAPicture) { return ; //currently, it doesn't support XFAPicture. } int iIndex; for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIndex++) { int iStart = 0; int iEnd; while((iEnd = cFormat.find(fcTable[iIndex].lpszJSMark, iStart)) != -1) { cFormat.replace(iEnd,FXSYS_wcslen(fcTable[iIndex].lpszJSMark), fcTable[iIndex].lpszCppMark); iStart = iEnd; } } int iYear,iMonth,iDay,iHour,iMin,iSec; iYear = jsDate.GetYear(); iMonth = jsDate.GetMonth(); iDay = jsDate.GetDay(); iHour = jsDate.GetHours(); iMin = jsDate.GetMinutes(); iSec = jsDate.GetSeconds(); struct tm time = {}; time.tm_year = iYear-1900; time.tm_mon = iMonth; time.tm_mday = iDay; time.tm_hour = iHour; time.tm_min = iMin; time.tm_sec = iSec; // COleDateTime cppTm(iYear,iMonth+1,iDay,iHour,iMin,iSec); //CString strFormat = cppTm.Format(cFormat.c_str()); struct stru_TbConvertAd { const FX_WCHAR* lpszJSMark; int iValue; }; stru_TbConvertAd cTableAd[] ={ { L"m", iMonth+1 }, { L"d", iDay }, { L"H", iHour }, { L"h", iHour>12?iHour-12:iHour }, { L"M", iMin }, { L"s", iSec }, }; //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1); for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd);iIndex++) { wchar_t tszValue[10]; //_itot(cTableAd[iIndex].iValue,tszValue,10); CFX_WideString sValue; sValue.Format(L"%d",cTableAd[iIndex].iValue); memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetLength()+1),sValue.GetLength()*sizeof(wchar_t)); //strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d"); //strFormat.Format(strFormat,cTableAd[iIndex].iValue); int iStart = 0; int iEnd; while((iEnd = cFormat.find(cTableAd[iIndex].lpszJSMark, iStart)) != -1) { if (iEnd > 0) { if (cFormat[iEnd-1] == L'%') { iStart = iEnd+1; continue; } } cFormat.replace(iEnd,FXSYS_wcslen(cTableAd[iIndex].lpszJSMark),tszValue); iStart = iEnd; } } CFX_WideString strFormat; wchar_t buf[64] = {}; strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); cFormat = buf; cPurpose = cFormat; }
FX_BOOL util::printf(OBJ_METHOD_PARAMS) { int iSize = params.size(); if (iSize < 1) return FALSE; std::wstring c_ConvChar((const wchar_t*)(FX_LPCWSTR)params[0].operator CFX_WideString()); std::vector<std::wstring> c_strConvers; int iOffset = 0; int iOffend = 0; c_ConvChar.insert(c_ConvChar.begin(),L'S'); while(iOffset != -1) { iOffend = c_ConvChar.find(L"%",iOffset+1); std::wstring strSub; if (iOffend == -1) strSub = c_ConvChar.substr(iOffset); else strSub = c_ConvChar.substr(iOffset ,iOffend - iOffset); c_strConvers.push_back(strSub); iOffset = iOffend ; } std::wstring c_strResult; //for(int iIndex = 1;iIndex < params.size();iIndex++) std::wstring c_strFormat; for(int iIndex = 0;iIndex < (int)c_strConvers.size();iIndex++) { c_strFormat = c_strConvers[iIndex]; if (iIndex == 0) { c_strResult = c_strFormat; continue; } CFX_WideString strSegment; if (iIndex >= iSize) { c_strResult += c_strFormat; continue; } switch (ParstDataType(&c_strFormat)) { case UTIL_INT: strSegment.Format((FX_LPCWSTR)c_strFormat.c_str(),(int)params[iIndex]); break; case UTIL_DOUBLE: strSegment.Format((FX_LPCWSTR)c_strFormat.c_str(),(double)params[iIndex]); break; case UTIL_STRING: strSegment.Format((FX_LPCWSTR)c_strFormat.c_str(),(FX_LPCWSTR)params[iIndex].operator CFX_WideString()); break; default: strSegment.Format((FX_LPCWSTR)L"%S", (FX_LPCWSTR)c_strFormat.c_str()); break; } c_strResult += (wchar_t*)strSegment.GetBuffer(strSegment.GetLength()+1); } c_strResult.erase(c_strResult.begin()); vRet = (FX_LPCWSTR)c_strResult.c_str(); return TRUE; }