FX_STRSIZE CFX_WideString::Replace(const FX_WCHAR* lpszOld, const FX_WCHAR* lpszNew)
{
    if (GetLength() < 1) {
        return 0;
    }
    if (lpszOld == NULL) {
        return 0;
    }
    FX_STRSIZE nSourceLen = FXSYS_wcslen(lpszOld);
    if (nSourceLen == 0) {
        return 0;
    }
    FX_STRSIZE nReplacementLen = lpszNew ? FXSYS_wcslen(lpszNew) : 0;
    FX_STRSIZE nCount = 0;
    FX_WCHAR* lpszStart = m_pData->m_String;
    FX_WCHAR* lpszEnd = m_pData->m_String + m_pData->m_nDataLength;
    FX_WCHAR* lpszTarget;
    {
        while ((lpszTarget = (FX_WCHAR*)FXSYS_wcsstr(lpszStart, lpszOld)) != NULL && lpszStart < lpszEnd) {
            nCount++;
            lpszStart = lpszTarget + nSourceLen;
        }
    }
    if (nCount > 0) {
        CopyBeforeWrite();
        FX_STRSIZE nOldLength = m_pData->m_nDataLength;
        FX_STRSIZE nNewLength =  nOldLength + (nReplacementLen - nSourceLen) * nCount;
        if (m_pData->m_nAllocLength < nNewLength || m_pData->m_nRefs > 1) {
            StringData* pOldData = m_pData;
            const FX_WCHAR* pstr = m_pData->m_String;
            m_pData = StringData::Create(nNewLength);
            if (!m_pData) {
                return 0;
            }
            FXSYS_memcpy(m_pData->m_String, pstr, pOldData->m_nDataLength * sizeof(FX_WCHAR));
            pOldData->Release();
        }
        lpszStart = m_pData->m_String;
        lpszEnd = m_pData->m_String + FX_MAX(m_pData->m_nDataLength, nNewLength);
        {
            while ((lpszTarget = (FX_WCHAR*)FXSYS_wcsstr(lpszStart, lpszOld)) != NULL && lpszStart < lpszEnd) {
                FX_STRSIZE nBalance = nOldLength - (FX_STRSIZE)(lpszTarget - m_pData->m_String + nSourceLen);
                FXSYS_memmove(lpszTarget + nReplacementLen, lpszTarget + nSourceLen, nBalance * sizeof(FX_WCHAR));
                FXSYS_memcpy(lpszTarget, lpszNew, nReplacementLen * sizeof(FX_WCHAR));
                lpszStart = lpszTarget + nReplacementLen;
                lpszStart[nBalance] = 0;
                nOldLength += (nReplacementLen - nSourceLen);
            }
        }
        ASSERT(m_pData->m_String[nNewLength] == 0);
        m_pData->m_nDataLength = nNewLength;
    }
    return nCount;
}
const CFX_WideString& CFX_WideString::operator+=(const FX_WCHAR* lpsz)
{
    if (lpsz) {
        ConcatInPlace(FXSYS_wcslen(lpsz), lpsz);
    }
    return *this;
}
void CFX_WideString::FormatV(const FX_WCHAR* lpszFormat, va_list argList)
{
    va_list argListSave;
#if defined(__ARMCC_VERSION) || (!defined(_MSC_VER) && (_FX_CPU_ == _FX_X64_ || _FX_CPU_ == _FX_IA64_ || _FX_CPU_ == _FX_ARM64_)) || defined(__native_client__)
    va_copy(argListSave, argList);
#else
    argListSave = argList;
#endif
    int nMaxLen = 0;
    for (const FX_WCHAR* lpsz = lpszFormat; *lpsz != 0; lpsz ++) {
        if (*lpsz != '%' || *(lpsz = lpsz + 1) == '%') {
            nMaxLen += FXSYS_wcslen(lpsz);
            continue;
        }
        int nItemLen = 0;
        int nWidth = 0;
        for (; *lpsz != 0; lpsz ++) {
            if (*lpsz == '#') {
                nMaxLen += 2;
            } else if (*lpsz == '*') {
                nWidth = va_arg(argList, int);
            } else if (*lpsz == '-' || *lpsz == '+' || *lpsz == '0' ||
                       *lpsz == ' ')
                ;
            else {
                break;
            }
        }
TEST_F(CFDE_CSSStyleSheetTest, ParseChildSelectors) {
  const FX_WCHAR* buf = L"a b c { border: 10px; }";
  EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf)));
  EXPECT_EQ(1, sheet_->CountRules());

  CFDE_CSSStyleRule* style = sheet_->GetRule(0);
  EXPECT_EQ(1UL, style->CountSelectorLists());

  auto sel = style->GetSelectorList(0);
  EXPECT_TRUE(sel != nullptr);
  EXPECT_EQ(FX_HashCode_GetW(L"c", true), sel->GetNameHash());

  sel = sel->GetNextSelector();
  EXPECT_TRUE(sel != nullptr);
  EXPECT_EQ(FX_HashCode_GetW(L"b", true), sel->GetNameHash());

  sel = sel->GetNextSelector();
  EXPECT_TRUE(sel != nullptr);
  EXPECT_EQ(FX_HashCode_GetW(L"a", true), sel->GetNameHash());

  sel = sel->GetNextSelector();
  EXPECT_TRUE(sel == nullptr);

  decl_ = style->GetDeclaration();
  EXPECT_EQ(4UL, decl_->PropertyCountForTesting());

  VerifyFloat(FDE_CSSProperty::BorderLeftWidth, 10.0,
              FDE_CSSNumberType::Pixels);
  VerifyFloat(FDE_CSSProperty::BorderRightWidth, 10.0,
              FDE_CSSNumberType::Pixels);
  VerifyFloat(FDE_CSSProperty::BorderTopWidth, 10.0, FDE_CSSNumberType::Pixels);
  VerifyFloat(FDE_CSSProperty::BorderBottomWidth, 10.0,
              FDE_CSSNumberType::Pixels);
}
TEST(fxcrt, EmptyWideString) {
  CFX_WideString empty_str;
  EXPECT_TRUE(empty_str.IsEmpty());
  EXPECT_EQ(0, empty_str.GetLength());
  const FX_WCHAR* cstr = empty_str.c_str();
  EXPECT_EQ(0, FXSYS_wcslen(cstr));
}
Example #6
0
IFDE_CSSStyleSheet* IFDE_CSSStyleSheet::LoadHTMLStandardStyleSheet() {
  static const FX_WCHAR* s_pStyle =
      L"html,address,blockquote,body,dd,div,dl,dt,fieldset,form,frame,frameset,"
      L"h1,h2,h3,h4,h5,h6,noframes,ol,p,ul,center,dir,hr,menu,pre{display:"
      L"block}"
      L"li{display:list-item}head{display:none}table{display:table}tr{display:"
      L"table-row}thead{display:table-header-group}tbody{display:table-row-"
      L"group}tfoot{display:table-footer-group}"
      L"col{display:table-column}colgroup{display:table-column-group}td,th{"
      L"display:table-cell}caption{display:table-caption}th{font-weight:bolder;"
      L"text-align:center}caption{text-align:center}"
      L"body{margin:0}h1{font-size:2em;margin:.67em "
      L"0}h2{font-size:1.5em;margin:.75em 0}h3{font-size:1.17em;margin:.83em "
      L"0}h4,p,blockquote,ul,fieldset,form,ol,dl,dir,menu{margin:1.12em 0}"
      L"h5{font-size:.83em;margin:1.5em 0}h6{font-size:.75em;margin:1.67em "
      L"0}h1,h2,h3,h4,h5,h6,b,strong{font-weight:bolder}blockquote{margin-left:"
      L"40px;margin-right:40px}i,cite,em,var,address{font-style:italic}"
      L"pre,tt,code,kbd,samp{font-family:monospace}pre{white-space:pre}button,"
      L"textarea,input,select{display:inline-block}big{font-size:1.17em}small,"
      L"sub,sup{font-size:.83em}sub{vertical-align:sub}"
      L"sup{vertical-align:super}table{border-spacing:2px}thead,tbody,tfoot{"
      L"vertical-align:middle}td,th,tr{vertical-align:inherit}s,strike,del{"
      L"text-decoration:line-through}hr{border:1px inset silver}"
      L"ol,ul,dir,menu,dd{margin-left:40px}ol{list-style-type:decimal}ol ul,ul "
      L"ol,ul ul,ol "
      L"ol{margin-top:0;margin-bottom:0}u,ins{text-decoration:underline}center{"
      L"text-align:center}"
      L"ruby{display:ruby}rt{display:ruby-text;font-size:.5em}rb{display:ruby-"
      L"base}rbc{display:ruby-base-group}rtc{display:ruby-text-group}"
      L"q:before{content:open-quote}q:after{content:close-quote}"
      L"rp{display:none}";
  return IFDE_CSSStyleSheet::LoadFromBuffer(
      CFX_WideString(), s_pStyle, FXSYS_wcslen(s_pStyle), FX_CODEPAGE_UTF8);
}
Example #7
0
const CFX_WideString& CFX_WideString::operator+=(FX_LPCWSTR lpsz)
{
    if (lpsz) {
        ConcatInPlace((FX_STRSIZE)FXSYS_wcslen(lpsz), lpsz);
    }
    return *this;
}
Example #8
0
FX_BOOL CPDF_TextPageFind::ExtractSubString(CFX_WideString& rString,
                                            const FX_WCHAR* lpszFullString,
                                            int iSubString,
                                            FX_WCHAR chSep) {
  if (!lpszFullString)
    return FALSE;
  while (iSubString--) {
    lpszFullString = std::wcschr(lpszFullString, chSep);
    if (!lpszFullString) {
      rString.clear();
      return FALSE;
    }
    lpszFullString++;
    while (*lpszFullString == chSep)
      lpszFullString++;
  }
  const FX_WCHAR* lpchEnd = std::wcschr(lpszFullString, chSep);
  int nLen = lpchEnd ? (int)(lpchEnd - lpszFullString)
                     : (int)FXSYS_wcslen(lpszFullString);
  ASSERT(nLen >= 0);
  FXSYS_memcpy(rString.GetBuffer(nLen), lpszFullString,
               nLen * sizeof(FX_WCHAR));
  rString.ReleaseBuffer();
  return TRUE;
}
TEST(CFDE_XMLSyntaxParser, CommentTwoDash) {
  const FX_WCHAR* input =
      L"<script contentType=\"application/x-javascript\">\n"
      L"  <!-->\n"
      L"</script>";

  // We * sizeof(FX_WCHAR) because we pass in the uint8_t, not the FX_WCHAR.
  size_t len = FXSYS_wcslen(input) * sizeof(FX_WCHAR);
  std::unique_ptr<IFX_Stream> stream(IFX_Stream::CreateStream(
      reinterpret_cast<uint8_t*>(const_cast<FX_WCHAR*>(input)), len, 0));
  CFDE_XMLSyntaxParser parser;
  parser.Init(stream.get(), 256);

  CFX_WideString data;

  EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse());
  EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse());
  parser.GetTagName(data);
  EXPECT_EQ(L"script", data);

  EXPECT_EQ(FDE_XmlSyntaxResult::AttriName, parser.DoSyntaxParse());
  parser.GetAttributeName(data);
  EXPECT_EQ(L"contentType", data);
  EXPECT_EQ(FDE_XmlSyntaxResult::AttriValue, parser.DoSyntaxParse());
  parser.GetAttributeValue(data);
  EXPECT_EQ(L"application/x-javascript", data);

  EXPECT_EQ(FDE_XmlSyntaxResult::ElementBreak, parser.DoSyntaxParse());
  EXPECT_EQ(FDE_XmlSyntaxResult::Text, parser.DoSyntaxParse());
  parser.GetTextData(data);
  EXPECT_EQ(L"\n  ", data);

  EXPECT_EQ(FDE_XmlSyntaxResult::EndOfString, parser.DoSyntaxParse());
}
Example #10
0
const CFX_WideString& CFX_WideString::operator=(const FX_WCHAR* lpsz) {
  if (lpsz == NULL || lpsz[0] == 0) {
    Empty();
  } else {
    AssignCopy(FXSYS_wcslen(lpsz), lpsz);
  }
  return *this;
}
TEST_F(CFDE_CSSStyleSheetTest, ParseUnhandledSelectors) {
  const FX_WCHAR* buf = L"a > b { padding: 0; }";
  EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf)));
  EXPECT_EQ(0, sheet_->CountRules());

  buf = L"a[first] { padding: 0; }";
  EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf)));
  EXPECT_EQ(0, sheet_->CountRules());

  buf = L"a+b { padding: 0; }";
  EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf)));
  EXPECT_EQ(0, sheet_->CountRules());

  buf = L"a ^ b { padding: 0; }";
  EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf)));
  EXPECT_EQ(0, sheet_->CountRules());
}
Example #12
0
const CFX_WideString& CFX_WideString::operator=(FX_LPCWSTR lpsz)
{
    if (lpsz == NULL || lpsz[0] == 0) {
        Empty();
    } else {
        AssignCopy((FX_STRSIZE)FXSYS_wcslen(lpsz), lpsz);
    }
    return *this;
}
Example #13
0
CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(const FX_WCHAR* wstr) {
  FX_STRSIZE len = FXSYS_wcslen(wstr);
  if (m_pStream) {
    m_pStream->WriteBlock(&len, sizeof(int));
    m_pStream->WriteBlock(wstr, len);
  } else {
    m_SavingBuf.AppendBlock(&len, sizeof(int));
    m_SavingBuf.AppendBlock(wstr, len);
  }
  return *this;
}
CFX_WideString::CFX_WideString(const FX_WCHAR* lpsz, FX_STRSIZE nLen) {
    if (nLen < 0) {
        nLen = lpsz ? FXSYS_wcslen(lpsz) : 0;
    }
    if (nLen) {
        m_pData = StringData::Create(nLen);
        if (m_pData) {
            FXSYS_memcpy(m_pData->m_String, lpsz, nLen * sizeof(FX_WCHAR));
        }
    } else {
        m_pData = NULL;
    }
}
Example #15
0
void CFX_WideString::InitStr(FX_LPCWSTR lpsz, FX_STRSIZE nLen)
{
    if (nLen < 0) {
        nLen = lpsz ? (FX_STRSIZE)FXSYS_wcslen(lpsz) : 0;
    }
    if (nLen) {
        m_pData = FX_AllocStringW(nLen);
        if (!m_pData) {
            return;
        }
        FXSYS_memcpy32(m_pData->m_String, lpsz, nLen * sizeof(FX_WCHAR));
    } else {
        m_pData = NULL;
    }
}
Example #16
0
CXFA_Node* CXFA_NodeHelper::XFA_ResolveNodes_GetOneChild(
    CXFA_Node* parent,
    const FX_WCHAR* pwsName,
    FX_BOOL bIsClassName) {
  if (parent == NULL) {
    return NULL;
  }
  CXFA_NodeArray siblings;
  uint32_t uNameHash = FX_HashCode_String_GetW(pwsName, FXSYS_wcslen(pwsName));
  XFA_NodeAcc_TraverseAnySiblings(parent, uNameHash, &siblings, bIsClassName);
  if (siblings.GetSize() == 0) {
    return NULL;
  }
  return siblings[0];
}
Example #17
0
FX_WORD FX_GetCodePageFormStringW(const FX_WCHAR* pStr, int32_t iLength) {
  if (iLength < 0) {
    iLength = FXSYS_wcslen(pStr);
  }
  if (iLength == 0) {
    return 0xFFFF;
  }
  CFX_ByteString csStr;
  FX_CHAR* pBuf = csStr.GetBuffer(iLength + 1);
  for (int32_t i = 0; i < iLength; ++i) {
    *pBuf++ = (FX_CHAR)*pStr++;
  }
  csStr.ReleaseBuffer(iLength);
  return FX_GetCodePageFromStringA(csStr, iLength);
}
TEST_F(CFDE_CSSStyleSheetTest, ParseMultipleSelectors) {
  const FX_WCHAR* buf =
      L"a { border: 10px; }\nb { text-decoration: underline; }";
  EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf)));
  EXPECT_EQ(2, sheet_->CountRules());

  CFDE_CSSStyleRule* style = sheet_->GetRule(0);
  EXPECT_EQ(1UL, style->CountSelectorLists());

  bool found_selector = false;
  uint32_t hash = FX_HashCode_GetW(L"a", true);
  for (size_t i = 0; i < style->CountSelectorLists(); i++) {
    if (style->GetSelectorList(i)->GetNameHash() == hash) {
      found_selector = true;
      break;
    }
  }
  EXPECT_TRUE(found_selector);

  decl_ = style->GetDeclaration();
  EXPECT_EQ(4UL, decl_->PropertyCountForTesting());

  VerifyFloat(FDE_CSSProperty::BorderLeftWidth, 10.0,
              FDE_CSSNumberType::Pixels);
  VerifyFloat(FDE_CSSProperty::BorderRightWidth, 10.0,
              FDE_CSSNumberType::Pixels);
  VerifyFloat(FDE_CSSProperty::BorderTopWidth, 10.0, FDE_CSSNumberType::Pixels);
  VerifyFloat(FDE_CSSProperty::BorderBottomWidth, 10.0,
              FDE_CSSNumberType::Pixels);

  style = sheet_->GetRule(1);
  EXPECT_EQ(1UL, style->CountSelectorLists());

  found_selector = false;
  hash = FX_HashCode_GetW(L"b", true);
  for (size_t i = 0; i < style->CountSelectorLists(); i++) {
    if (style->GetSelectorList(i)->GetNameHash() == hash) {
      found_selector = true;
      break;
    }
  }
  EXPECT_TRUE(found_selector);

  decl_ = style->GetDeclaration();
  EXPECT_EQ(1UL, decl_->PropertyCountForTesting());
  VerifyList(FDE_CSSProperty::TextDecoration,
             {FDE_CSSPropertyValue::Underline});
}
Example #19
0
void CFX_WideString::ReleaseBuffer(FX_STRSIZE nNewLength) {
  if (m_pData == NULL) {
    return;
  }
  CopyBeforeWrite();
  if (nNewLength == -1) {
    nNewLength = m_pData ? FXSYS_wcslen(m_pData->m_String) : 0;
  }
  if (nNewLength == 0) {
    Empty();
    return;
  }
  FXSYS_assert(nNewLength <= m_pData->m_nAllocLength);
  m_pData->m_nDataLength = nNewLength;
  m_pData->m_String[nNewLength] = 0;
}
  void LoadAndVerifyDecl(const FX_WCHAR* buf,
                         const std::vector<CFX_WideString>& selectors,
                         size_t decl_count) {
    ASSERT(sheet_);

    EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf)));
    EXPECT_EQ(sheet_->CountRules(), 1);

    CFDE_CSSStyleRule* style = sheet_->GetRule(0);
    EXPECT_EQ(selectors.size(), style->CountSelectorLists());

    for (size_t i = 0; i < selectors.size(); i++) {
      uint32_t hash = FX_HashCode_GetW(selectors[i].AsStringC(), true);
      EXPECT_EQ(hash, style->GetSelectorList(i)->GetNameHash());
    }

    decl_ = style->GetDeclaration();
    EXPECT_EQ(decl_->PropertyCountForTesting(), decl_count);
  }
Example #21
0
CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const FX_WCHAR* lpsz) {
  AppendBlock(lpsz, FXSYS_wcslen(lpsz) * sizeof(FX_WCHAR));
  return *this;
}
Example #22
0
CFX_WideTextBuf& CFX_WideTextBuf::operator << (FX_LPCWSTR lpsz)
{
    AppendBlock(lpsz, (FX_STRSIZE)FXSYS_wcslen(lpsz)*sizeof(FX_WCHAR));
    return *this;
}
Example #23
0
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;
}
Example #24
0
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;
}
Example #25
0
unsigned JS_CalcHash(const wchar_t* main)
{
	return (unsigned)FX_HashCode_String_GetW(main, FXSYS_wcslen(main));
}