blob: 2a77bbe7ed3db05bcbc91a60edbd01ae9b4a0abb [file] [log] [blame]
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include <algorithm>
#include "core/fxcrt/include/fx_ext.h"
#include "core/fxcrt/include/fx_xml.h"
#include "xfa/fgas/localization/fgas_localeimp.h"
#define FX_LOCALECATEGORY_DateHash 0xbde9abde
#define FX_LOCALECATEGORY_TimeHash 0x2d71b00f
#define FX_LOCALECATEGORY_DateTimeHash 0x158c72ed
#define FX_LOCALECATEGORY_NumHash 0x0b4ff870
#define FX_LOCALECATEGORY_TextHash 0x2d08af85
#define FX_LOCALECATEGORY_ZeroHash 0x568cb500
#define FX_LOCALECATEGORY_NullHash 0x052931bb
struct FX_LOCALESUBCATEGORYINFO {
uint32_t uHash;
const FX_WCHAR* pName;
int32_t eSubCategory;
};
static const FX_LOCALESUBCATEGORYINFO g_FXLocaleDateTimeSubCatData[] = {
{0x14da2125, L"default", FX_LOCALEDATETIMESUBCATEGORY_Default},
{0x9041d4b0, L"short", FX_LOCALEDATETIMESUBCATEGORY_Short},
{0xa084a381, L"medium", FX_LOCALEDATETIMESUBCATEGORY_Medium},
{0xcdce56b3, L"full", FX_LOCALEDATETIMESUBCATEGORY_Full},
{0xf6b4afb0, L"long", FX_LOCALEDATETIMESUBCATEGORY_Long},
};
static const int32_t g_iFXLocaleDateTimeSubCatCount =
sizeof(g_FXLocaleDateTimeSubCatData) / sizeof(FX_LOCALESUBCATEGORYINFO);
static const FX_LOCALESUBCATEGORYINFO g_FXLocaleNumSubCatData[] = {
{0x46f95531, L"percent", FX_LOCALENUMPATTERN_Percent},
{0x4c4e8acb, L"currency", FX_LOCALENUMPATTERN_Currency},
{0x54034c2f, L"decimal", FX_LOCALENUMPATTERN_Decimal},
{0x7568e6ae, L"integer", FX_LOCALENUMPATTERN_Integer},
};
static const int32_t g_iFXLocaleNumSubCatCount =
sizeof(g_FXLocaleNumSubCatData) / sizeof(FX_LOCALESUBCATEGORYINFO);
struct FX_LOCALETIMEZONEINFO {
uint32_t uHash;
int16_t iHour;
int16_t iMinute;
};
static const FX_LOCALETIMEZONEINFO g_FXLocaleTimeZoneData[] = {
{FXBSTR_ID(0, 'C', 'D', 'T'), -5, 0}, {FXBSTR_ID(0, 'C', 'S', 'T'), -6, 0},
{FXBSTR_ID(0, 'E', 'D', 'T'), -4, 0}, {FXBSTR_ID(0, 'E', 'S', 'T'), -5, 0},
{FXBSTR_ID(0, 'M', 'D', 'T'), -6, 0}, {FXBSTR_ID(0, 'M', 'S', 'T'), -7, 0},
{FXBSTR_ID(0, 'P', 'D', 'T'), -7, 0}, {FXBSTR_ID(0, 'P', 'S', 'T'), -8, 0},
};
static const FX_WCHAR gs_wsTimeSymbols[] = L"hHkKMSFAzZ";
static const FX_WCHAR gs_wsDateSymbols[] = L"DJMEeGgYwW";
static const FX_WCHAR gs_wsConstChars[] = L",-:/. ";
static int32_t FX_ParseTimeZone(const FX_WCHAR* pStr,
int32_t iLen,
FX_TIMEZONE& tz) {
tz.tzHour = 0;
tz.tzMinute = 0;
if (iLen < 0) {
return 0;
}
int32_t iStart = 1;
int32_t iEnd = iStart + 2;
while (iStart < iLen && iStart < iEnd) {
tz.tzHour = tz.tzHour * 10 + pStr[iStart++] - '0';
}
if (iStart < iLen && pStr[iStart] == ':') {
iStart++;
}
iEnd = iStart + 2;
while (iStart < iLen && iStart < iEnd) {
tz.tzMinute = tz.tzMinute * 10 + pStr[iStart++] - '0';
}
if (pStr[0] == '-') {
tz.tzHour = -tz.tzHour;
}
return iStart;
}
class CFX_LCNumeric {
public:
CFX_LCNumeric();
CFX_LCNumeric(int64_t integral,
uint32_t fractional = 0,
int32_t exponent = 0);
CFX_LCNumeric(FX_FLOAT dbRetValue);
CFX_LCNumeric(double dbvalue);
CFX_LCNumeric(CFX_WideString& wsNumeric);
FX_FLOAT GetFloat() const;
double GetDouble() const;
CFX_WideString ToString() const;
CFX_WideString ToString(int32_t nTreading, FX_BOOL bTrimTailZeros) const;
int64_t m_Integral;
uint32_t m_Fractional;
int32_t m_Exponent;
};
static FX_BOOL FX_WStringToNumeric(const CFX_WideString& wsValue,
CFX_LCNumeric& lcnum) {
lcnum.m_Integral = 0;
lcnum.m_Fractional = 0;
lcnum.m_Exponent = 0;
if (wsValue.IsEmpty())
return FALSE;
const int32_t nIntegralMaxLen = 17;
int32_t cc = 0;
bool bNegative = false;
bool bExpSign = false;
const FX_WCHAR* str = wsValue.c_str();
int32_t len = wsValue.GetLength();
while (cc < len && FXSYS_iswspace(str[cc]))
cc++;
if (cc >= len)
return FALSE;
if (str[cc] == '+') {
cc++;
} else if (str[cc] == '-') {
bNegative = true;
cc++;
}
int32_t nIntegralLen = 0;
while (cc < len) {
if (str[cc] == '.')
break;
if (!FXSYS_isDecimalDigit(str[cc])) {
if ((str[cc] == 'E' || str[cc] == 'e'))
break;
return FALSE;
}
if (nIntegralLen < nIntegralMaxLen) {
lcnum.m_Integral = lcnum.m_Integral * 10 + str[cc] - '0';
nIntegralLen++;
}
cc++;
}
lcnum.m_Integral = bNegative ? -lcnum.m_Integral : lcnum.m_Integral;
if (cc < len && str[cc] == '.') {
int scale = 0;
double fraction = 0.0;
cc++;
while (cc < len) {
if (scale >= FXSYS_FractionalScaleCount()) {
while (cc < len) {
if (!FXSYS_isDecimalDigit(str[cc]))
break;
cc++;
}
}
if (!FXSYS_isDecimalDigit(str[cc])) {
if ((str[cc] == 'E' || str[cc] == 'e'))
break;
return FALSE;
}
fraction += FXSYS_FractionalScale(scale, FXSYS_toDecimalDigit(str[cc]));
scale++;
cc++;
}
lcnum.m_Fractional = (uint32_t)(fraction * 4294967296.0);
}
if (cc < len && (str[cc] == 'E' || str[cc] == 'e')) {
cc++;
if (cc < len) {
if (str[cc] == '+') {
cc++;
} else if (str[cc] == '-') {
bExpSign = true;
cc++;
}
}
while (cc < len) {
if (FXSYS_isDecimalDigit(str[cc]))
return FALSE;
lcnum.m_Exponent = lcnum.m_Exponent * 10 + str[cc] - '0';
cc++;
}
lcnum.m_Exponent = bExpSign ? -lcnum.m_Exponent : lcnum.m_Exponent;
}
return TRUE;
}
CFX_LCNumeric::CFX_LCNumeric() {
m_Integral = 0;
m_Fractional = 0;
m_Exponent = 0;
}
CFX_LCNumeric::CFX_LCNumeric(int64_t integral,
uint32_t fractional,
int32_t exponent) {
m_Integral = integral;
m_Fractional = fractional;
m_Exponent = exponent;
}
CFX_LCNumeric::CFX_LCNumeric(FX_FLOAT dbRetValue) {
m_Integral = (int64_t)dbRetValue;
m_Fractional = (uint32_t)(((dbRetValue > 0) ? (dbRetValue - m_Integral)
: (m_Integral - dbRetValue)) *
4294967296);
m_Exponent = 0;
}
CFX_LCNumeric::CFX_LCNumeric(double dbvalue) {
m_Integral = (int64_t)dbvalue;
m_Fractional = (uint32_t)(
((dbvalue > 0) ? (dbvalue - m_Integral) : (m_Integral - dbvalue)) *
4294967296);
m_Exponent = 0;
}
CFX_LCNumeric::CFX_LCNumeric(CFX_WideString& wsNumeric) {
FX_WStringToNumeric(wsNumeric, *this);
}
FX_FLOAT CFX_LCNumeric::GetFloat() const {
FX_FLOAT dbRetValue = m_Fractional / 4294967296.0f;
dbRetValue = m_Integral + (m_Integral >= 0 ? dbRetValue : -dbRetValue);
if (m_Exponent != 0) {
dbRetValue *= FXSYS_pow(10, (FX_FLOAT)m_Exponent);
}
return dbRetValue;
}
double CFX_LCNumeric::GetDouble() const {
double value = m_Fractional / 4294967296.0;
value = m_Integral + (m_Integral >= 0 ? value : -value);
if (m_Exponent != 0) {
value *= FXSYS_pow(10, (FX_FLOAT)m_Exponent);
}
return value;
}
CFX_WideString CFX_LCNumeric::ToString() const {
return ToString(8, TRUE);
}
CFX_WideString CFX_LCNumeric::ToString(int32_t nTreading,
FX_BOOL bTrimTailZeros) const {
CFX_WideString wsFormat;
wsFormat.Format(L"%%.%df", nTreading);
CFX_WideString wsResult;
wsResult.Format(wsFormat.c_str(), GetDouble());
if (bTrimTailZeros && nTreading > 0) {
wsResult.TrimRight(L"0");
wsResult.TrimRight(L".");
}
return wsResult;
}
CFX_FormatString::CFX_FormatString(IFX_LocaleMgr* pLocaleMgr, FX_BOOL bUseLCID)
: m_pLocaleMgr(pLocaleMgr), m_bUseLCID(bUseLCID) {}
CFX_FormatString::~CFX_FormatString() {}
void CFX_FormatString::SplitFormatString(const CFX_WideString& wsFormatString,
CFX_WideStringArray& wsPatterns) {
int32_t iStrLen = wsFormatString.GetLength();
const FX_WCHAR* pStr = wsFormatString.c_str();
const FX_WCHAR* pToken = pStr;
const FX_WCHAR* pEnd = pStr + iStrLen;
FX_BOOL iQuote = FALSE;
while (TRUE) {
if (pStr >= pEnd) {
CFX_WideString sub(pToken, pStr - pToken);
wsPatterns.Add(sub);
return;
}
if (*pStr == '\'') {
iQuote = !iQuote;
} else if (*pStr == L'|' && !iQuote) {
CFX_WideString sub(pToken, pStr - pToken);
wsPatterns.Add(sub);
pToken = pStr + 1;
}
pStr++;
}
}
static CFX_WideString FX_GetLiteralText(const FX_WCHAR* pStrPattern,
int32_t& iPattern,
int32_t iLenPattern) {
CFX_WideString wsOutput;
if (pStrPattern[iPattern] != '\'') {
return wsOutput;
}
iPattern++;
int32_t iQuote = 1;
while (iPattern < iLenPattern) {
if (pStrPattern[iPattern] == '\'') {
iQuote++;
if ((iPattern + 1 >= iLenPattern) ||
((pStrPattern[iPattern + 1] != '\'') && (iQuote % 2 == 0))) {
break;
} else {
iQuote++;
}
iPattern++;
} else if (pStrPattern[iPattern] == '\\' && (iPattern + 1 < iLenPattern) &&
pStrPattern[iPattern + 1] == 'u') {
int32_t iKeyValue = 0;
iPattern += 2;
int32_t i = 0;
while (iPattern < iLenPattern && i++ < 4) {
FX_WCHAR ch = pStrPattern[iPattern++];
if ((ch >= '0' && ch <= '9')) {
iKeyValue = iKeyValue * 16 + ch - '0';
} else if ((ch >= 'a' && ch <= 'f')) {
iKeyValue = iKeyValue * 16 + ch - 'a' + 10;
} else if ((ch >= 'A' && ch <= 'F')) {
iKeyValue = iKeyValue * 16 + ch - 'A' + 10;
}
}
if (iKeyValue != 0) {
wsOutput += (FX_WCHAR)(iKeyValue & 0x0000FFFF);
}
continue;
}
wsOutput += pStrPattern[iPattern++];
}
return wsOutput;
}
static CFX_WideString FX_GetLiteralTextReverse(const FX_WCHAR* pStrPattern,
int32_t& iPattern) {
CFX_WideString wsOutput;
if (pStrPattern[iPattern] != '\'') {
return wsOutput;
}
iPattern--;
int32_t iQuote = 1;
while (iPattern >= 0) {
if (pStrPattern[iPattern] == '\'') {
iQuote++;
if (iPattern - 1 >= 0 ||
((pStrPattern[iPattern - 1] != '\'') && (iQuote % 2 == 0))) {
break;
}
iQuote++;
iPattern--;
} else if (pStrPattern[iPattern] == '\\' &&
pStrPattern[iPattern + 1] == 'u') {
iPattern--;
int32_t iKeyValue = 0;
int32_t iLen = wsOutput.GetLength();
int32_t i = 1;
for (; i < iLen && i < 5; i++) {
FX_WCHAR ch = wsOutput[i];
if ((ch >= '0' && ch <= '9')) {
iKeyValue = iKeyValue * 16 + ch - '0';
} else if ((ch >= 'a' && ch <= 'f')) {
iKeyValue = iKeyValue * 16 + ch - 'a' + 10;
} else if ((ch >= 'A' && ch <= 'F')) {
iKeyValue = iKeyValue * 16 + ch - 'A' + 10;
}
}
if (iKeyValue != 0) {
wsOutput.Delete(0, i);
wsOutput = (FX_WCHAR)(iKeyValue & 0x0000FFFF) + wsOutput;
}
continue;
}
wsOutput = pStrPattern[iPattern--] + wsOutput;
}
return wsOutput;
}
FX_LOCALECATEGORY CFX_FormatString::GetCategory(
const CFX_WideString& wsPattern) {
FX_LOCALECATEGORY eCategory = FX_LOCALECATEGORY_Unknown;
int32_t ccf = 0;
int32_t iLenf = wsPattern.GetLength();
const FX_WCHAR* pStr = wsPattern.c_str();
FX_BOOL bBraceOpen = FALSE;
CFX_WideStringC wsConstChars(gs_wsConstChars);
while (ccf < iLenf) {
if (pStr[ccf] == '\'') {
FX_GetLiteralText(pStr, ccf, iLenf);
} else if (!bBraceOpen && wsConstChars.Find(pStr[ccf]) == -1) {
CFX_WideString wsCategory(pStr[ccf]);
ccf++;
while (TRUE) {
if (ccf == iLenf) {
return eCategory;
}
if (pStr[ccf] == '.' || pStr[ccf] == '(') {
break;
}
if (pStr[ccf] == '{') {
bBraceOpen = TRUE;
break;
}
wsCategory += pStr[ccf];
ccf++;
}
uint32_t dwHash = FX_HashCode_GetW(wsCategory.AsStringC(), false);
if (dwHash == FX_LOCALECATEGORY_DateHash) {
if (eCategory == FX_LOCALECATEGORY_Time) {
return FX_LOCALECATEGORY_DateTime;
}
eCategory = FX_LOCALECATEGORY_Date;
} else if (dwHash == FX_LOCALECATEGORY_TimeHash) {
if (eCategory == FX_LOCALECATEGORY_Date) {
return FX_LOCALECATEGORY_DateTime;
}
eCategory = FX_LOCALECATEGORY_Time;
} else if (dwHash == FX_LOCALECATEGORY_DateTimeHash) {
return FX_LOCALECATEGORY_DateTime;
} else if (dwHash == FX_LOCALECATEGORY_TextHash) {
return FX_LOCALECATEGORY_Text;
} else if (dwHash == FX_LOCALECATEGORY_NumHash) {
return FX_LOCALECATEGORY_Num;
} else if (dwHash == FX_LOCALECATEGORY_ZeroHash) {
return FX_LOCALECATEGORY_Zero;
} else if (dwHash == FX_LOCALECATEGORY_NullHash) {
return FX_LOCALECATEGORY_Null;
}
} else if (pStr[ccf] == '}') {
bBraceOpen = FALSE;
}
ccf++;
}
return eCategory;
}
static uint16_t FX_WStringToLCID(const FX_WCHAR* pstrLCID) {
if (!pstrLCID) {
return 0;
}
wchar_t* pEnd;
return (uint16_t)wcstol((wchar_t*)pstrLCID, &pEnd, 16);
}
uint16_t CFX_FormatString::GetLCID(const CFX_WideString& wsPattern) {
return FX_WStringToLCID(GetLocaleName(wsPattern).c_str());
}
CFX_WideString CFX_FormatString::GetLocaleName(
const CFX_WideString& wsPattern) {
int32_t ccf = 0;
int32_t iLenf = wsPattern.GetLength();
const FX_WCHAR* pStr = wsPattern.c_str();
while (ccf < iLenf) {
if (pStr[ccf] == '\'') {
FX_GetLiteralText(pStr, ccf, iLenf);
} else if (pStr[ccf] == '(') {
ccf++;
CFX_WideString wsLCID;
while (ccf < iLenf && pStr[ccf] != ')') {
wsLCID += pStr[ccf++];
}
return wsLCID;
}
ccf++;
}
return CFX_WideString();
}
IFX_Locale* CFX_FormatString::GetTextFormat(const CFX_WideString& wsPattern,
const CFX_WideStringC& wsCategory,
CFX_WideString& wsPurgePattern) {
IFX_Locale* pLocale = nullptr;
int32_t ccf = 0;
int32_t iLenf = wsPattern.GetLength();
const FX_WCHAR* pStr = wsPattern.c_str();
FX_BOOL bBrackOpen = FALSE;
CFX_WideStringC wsConstChars(gs_wsConstChars);
while (ccf < iLenf) {
if (pStr[ccf] == '\'') {
int32_t iCurChar = ccf;
FX_GetLiteralText(pStr, ccf, iLenf);
wsPurgePattern += CFX_WideStringC(pStr + iCurChar, ccf - iCurChar + 1);
} else if (!bBrackOpen && wsConstChars.Find(pStr[ccf]) == -1) {
CFX_WideString wsSearchCategory(pStr[ccf]);
ccf++;
while (ccf < iLenf && pStr[ccf] != '{' && pStr[ccf] != '.' &&
pStr[ccf] != '(') {
wsSearchCategory += pStr[ccf];
ccf++;
}
if (wsSearchCategory != wsCategory) {
continue;
}
while (ccf < iLenf) {
if (pStr[ccf] == '(') {
ccf++;
CFX_WideString wsLCID;
while (ccf < iLenf && pStr[ccf] != ')') {
wsLCID += pStr[ccf++];
}
pLocale = GetPatternLocale(wsLCID);
} else if (pStr[ccf] == '{') {
bBrackOpen = TRUE;
break;
}
ccf++;
}
} else if (pStr[ccf] != '}') {
wsPurgePattern += pStr[ccf];
}
ccf++;
}
if (!bBrackOpen) {
wsPurgePattern = wsPattern;
}
if (!pLocale) {
pLocale = m_pLocaleMgr->GetDefLocale();
}
return pLocale;
}
#define FX_NUMSTYLE_Percent 0x01
#define FX_NUMSTYLE_Exponent 0x02
#define FX_NUMSTYLE_DotVorv 0x04
IFX_Locale* CFX_FormatString::GetNumericFormat(const CFX_WideString& wsPattern,
int32_t& iDotIndex,
uint32_t& dwStyle,
CFX_WideString& wsPurgePattern) {
dwStyle = 0;
IFX_Locale* pLocale = nullptr;
int32_t ccf = 0;
int32_t iLenf = wsPattern.GetLength();
const FX_WCHAR* pStr = wsPattern.c_str();
FX_BOOL bFindDot = FALSE;
FX_BOOL bBrackOpen = FALSE;
CFX_WideStringC wsConstChars(gs_wsConstChars);
while (ccf < iLenf) {
if (pStr[ccf] == '\'') {
int32_t iCurChar = ccf;
FX_GetLiteralText(pStr, ccf, iLenf);
wsPurgePattern += CFX_WideStringC(pStr + iCurChar, ccf - iCurChar + 1);
} else if (!bBrackOpen && wsConstChars.Find(pStr[ccf]) == -1) {
CFX_WideString wsCategory(pStr[ccf]);
ccf++;
while (ccf < iLenf && pStr[ccf] != '{' && pStr[ccf] != '.' &&
pStr[ccf] != '(') {
wsCategory += pStr[ccf];
ccf++;
}
if (wsCategory != FX_WSTRC(L"num")) {
bBrackOpen = TRUE;
ccf = 0;
continue;
}
while (ccf < iLenf) {
if (pStr[ccf] == '(') {
ccf++;
CFX_WideString wsLCID;
while (ccf < iLenf && pStr[ccf] != ')') {
wsLCID += pStr[ccf++];
}
pLocale = GetPatternLocale(wsLCID);
} else if (pStr[ccf] == '{') {
bBrackOpen = TRUE;
break;
} else if (pStr[ccf] == '.') {
CFX_WideString wsSubCategory;
ccf++;
while (ccf < iLenf && pStr[ccf] != '(' && pStr[ccf] != '{') {
wsSubCategory += pStr[ccf++];
}
uint32_t dwSubHash =
FX_HashCode_GetW(wsSubCategory.AsStringC(), false);
FX_LOCALENUMSUBCATEGORY eSubCategory = FX_LOCALENUMPATTERN_Decimal;
for (int32_t i = 0; i < g_iFXLocaleNumSubCatCount; i++) {
if (g_FXLocaleNumSubCatData[i].uHash == dwSubHash) {
eSubCategory = (FX_LOCALENUMSUBCATEGORY)g_FXLocaleNumSubCatData[i]
.eSubCategory;
break;
}
}
wsSubCategory.clear();
if (!pLocale) {
pLocale = m_pLocaleMgr->GetDefLocale();
}
ASSERT(pLocale);
pLocale->GetNumPattern(eSubCategory, wsSubCategory);
iDotIndex = wsSubCategory.Find('.');
if (iDotIndex > 0) {
iDotIndex += wsPurgePattern.GetLength();
bFindDot = TRUE;
dwStyle |= FX_NUMSTYLE_DotVorv;
}
wsPurgePattern += wsSubCategory;
if (eSubCategory == FX_LOCALENUMPATTERN_Percent) {
dwStyle |= FX_NUMSTYLE_Percent;
}
continue;
}
ccf++;
}
} else if (pStr[ccf] == 'E') {
dwStyle |= FX_NUMSTYLE_Exponent;
wsPurgePattern += pStr[ccf];
} else if (pStr[ccf] == '%') {
dwStyle |= FX_NUMSTYLE_Percent;
wsPurgePattern += pStr[ccf];
} else if (pStr[ccf] != '}') {
wsPurgePattern += pStr[ccf];
}
if (!bFindDot) {
if (pStr[ccf] == '.' || pStr[ccf] == 'V' || pStr[ccf] == 'v') {
bFindDot = TRUE;
iDotIndex = wsPurgePattern.GetLength() - 1;
dwStyle |= FX_NUMSTYLE_DotVorv;
}
}
ccf++;
}
if (!bFindDot) {
iDotIndex = wsPurgePattern.GetLength();
}
if (!pLocale) {
pLocale = m_pLocaleMgr->GetDefLocale();
}
return pLocale;
}
static FX_BOOL FX_GetNumericDotIndex(const CFX_WideString& wsNum,
const CFX_WideString& wsDotSymbol,
int32_t& iDotIndex) {
int32_t ccf = 0;
int32_t iLenf = wsNum.GetLength();
const FX_WCHAR* pStr = wsNum.c_str();
int32_t iLenDot = wsDotSymbol.GetLength();
while (ccf < iLenf) {
if (pStr[ccf] == '\'') {
FX_GetLiteralText(pStr, ccf, iLenf);
} else if (ccf + iLenDot <= iLenf &&
!FXSYS_wcsncmp(pStr + ccf, wsDotSymbol.c_str(), iLenDot)) {
iDotIndex = ccf;
return TRUE;
}
ccf++;
}
iDotIndex = wsNum.Find('.');
if (iDotIndex < 0) {
iDotIndex = iLenf;
return FALSE;
}
return TRUE;
}
FX_BOOL CFX_FormatString::ParseText(const CFX_WideString& wsSrcText,
const CFX_WideString& wsPattern,
CFX_WideString& wsValue) {
wsValue.clear();
if (wsSrcText.IsEmpty() || wsPattern.IsEmpty()) {
return FALSE;
}
CFX_WideString wsTextFormat;
GetTextFormat(wsPattern, FX_WSTRC(L"text"), wsTextFormat);
if (wsTextFormat.IsEmpty()) {
return FALSE;
}
int32_t iText = 0, iPattern = 0;
const FX_WCHAR* pStrText = wsSrcText.c_str();
int32_t iLenText = wsSrcText.GetLength();
const FX_WCHAR* pStrPattern = wsTextFormat.c_str();
int32_t iLenPattern = wsTextFormat.GetLength();
while (iPattern < iLenPattern && iText < iLenText) {
switch (pStrPattern[iPattern]) {
case '\'': {
CFX_WideString wsLiteral =
FX_GetLiteralText(pStrPattern, iPattern, iLenPattern);
int32_t iLiteralLen = wsLiteral.GetLength();
if (iText + iLiteralLen > iLenText ||
FXSYS_wcsncmp(pStrText + iText, wsLiteral.c_str(), iLiteralLen)) {
wsValue = wsSrcText;
return FALSE;
}
iText += iLiteralLen;
iPattern++;
break;
}
case 'A':
if (FXSYS_iswalpha(pStrText[iText])) {
wsValue += pStrText[iText];
iText++;
}
iPattern++;
break;
case 'X':
wsValue += pStrText[iText];
iText++;
iPattern++;
break;
case 'O':
case '0':
if (FXSYS_isDecimalDigit(pStrText[iText]) ||
FXSYS_iswalpha(pStrText[iText])) {
wsValue += pStrText[iText];
iText++;
}
iPattern++;
break;
case '9':
if (FXSYS_isDecimalDigit(pStrText[iText])) {
wsValue += pStrText[iText];
iText++;
}
iPattern++;
break;
default:
if (pStrPattern[iPattern] != pStrText[iText]) {
wsValue = wsSrcText;
return FALSE;
}
iPattern++;
iText++;
break;
}
}
return iPattern == iLenPattern && iText == iLenText;
}
FX_BOOL CFX_FormatString::ParseNum(const CFX_WideString& wsSrcNum,
const CFX_WideString& wsPattern,
FX_FLOAT& fValue) {
fValue = 0.0f;
if (wsSrcNum.IsEmpty() || wsPattern.IsEmpty()) {
return FALSE;
}
int32_t dot_index_f = -1;
uint32_t dwFormatStyle = 0;
CFX_WideString wsNumFormat;
IFX_Locale* pLocale =
GetNumericFormat(wsPattern, dot_index_f, dwFormatStyle, wsNumFormat);
if (!pLocale || wsNumFormat.IsEmpty()) {
return FALSE;
}
int32_t iExponent = 0;
CFX_WideString wsDotSymbol;
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal, wsDotSymbol);
CFX_WideString wsGroupSymbol;
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Grouping, wsGroupSymbol);
int32_t iGroupLen = wsGroupSymbol.GetLength();
CFX_WideString wsMinus;
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus, wsMinus);
int32_t iMinusLen = wsMinus.GetLength();
int cc = 0, ccf = 0;
const FX_WCHAR* str = wsSrcNum.c_str();
int len = wsSrcNum.GetLength();
const FX_WCHAR* strf = wsNumFormat.c_str();
int lenf = wsNumFormat.GetLength();
double dbRetValue = 0;
double coeff = 1;
FX_BOOL bHavePercentSymbol = FALSE;
FX_BOOL bNeg = FALSE;
FX_BOOL bReverseParse = FALSE;
int32_t dot_index = 0;
if (!FX_GetNumericDotIndex(wsSrcNum, wsDotSymbol, dot_index) &&
(dwFormatStyle & FX_NUMSTYLE_DotVorv)) {
bReverseParse = TRUE;
}
bReverseParse = FALSE;
if (bReverseParse) {
ccf = lenf - 1;
cc = len - 1;
while (ccf > dot_index_f && cc >= 0) {
switch (strf[ccf]) {
case '\'': {
CFX_WideString wsLiteral = FX_GetLiteralTextReverse(strf, ccf);
int32_t iLiteralLen = wsLiteral.GetLength();
cc -= iLiteralLen - 1;
if (cc < 0 ||
FXSYS_wcsncmp(str + cc, wsLiteral.c_str(), iLiteralLen)) {
return FALSE;
}
cc--;
ccf--;
break;
}
case '9':
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
dbRetValue = dbRetValue * coeff + (str[cc] - '0') * 0.1;
coeff *= 0.1;
cc--;
ccf--;
break;
case 'z':
if (cc >= 0) {
dbRetValue = dbRetValue * coeff + (str[cc] - '0') * 0.1;
coeff *= 0.1;
cc--;
}
ccf--;
break;
case 'Z':
if (str[cc] != ' ') {
dbRetValue = dbRetValue * coeff + (str[cc] - '0') * 0.1;
coeff *= 0.1;
}
cc--;
ccf--;
break;
case 'S':
if (str[cc] == '+' || str[cc] == ' ') {
cc--;
} else {
cc -= iMinusLen - 1;
if (cc < 0 || FXSYS_wcsncmp(str + cc, wsMinus.c_str(), iMinusLen)) {
return FALSE;
}
cc--;
bNeg = TRUE;
}
ccf--;
break;
case 's':
if (str[cc] == '+') {
cc--;
} else {
cc -= iMinusLen - 1;
if (cc < 0 || FXSYS_wcsncmp(str + cc, wsMinus.c_str(), iMinusLen)) {
return FALSE;
}
cc--;
bNeg = TRUE;
}
ccf--;
break;
case 'E': {
if (cc >= dot_index) {
return FALSE;
}
FX_BOOL bExpSign = FALSE;
while (cc >= 0) {
if (str[cc] == 'E' || str[cc] == 'e') {
break;
}
if (FXSYS_isDecimalDigit(str[cc])) {
iExponent = iExponent + (str[cc] - '0') * 10;
cc--;
continue;
} else if (str[cc] == '+') {
cc--;
continue;
} else if (cc - iMinusLen + 1 > 0 &&
!FXSYS_wcsncmp(str + (cc - iMinusLen + 1),
wsMinus.c_str(), iMinusLen)) {
bExpSign = TRUE;
cc -= iMinusLen;
} else {
return FALSE;
}
}
cc--;
iExponent = bExpSign ? -iExponent : iExponent;
ccf--;
} break;
case '$': {
CFX_WideString wsSymbol;
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencySymbol,
wsSymbol);
int32_t iSymbolLen = wsSymbol.GetLength();
cc -= iSymbolLen - 1;
if (cc < 0 || FXSYS_wcsncmp(str + cc, wsSymbol.c_str(), iSymbolLen)) {
return FALSE;
}
cc--;
ccf--;
} break;
case 'r':
if (ccf - 1 >= 0 && strf[ccf - 1] == 'c') {
if (str[cc] == 'R' && cc - 1 >= 0 && str[cc - 1] == 'C') {
bNeg = TRUE;
cc -= 2;
}
ccf -= 2;
} else {
ccf--;
}
break;
case 'R':
if (ccf - 1 >= 0 && strf[ccf - 1] == 'C') {
if (str[cc] == ' ') {
cc++;
} else if (str[cc] == 'R' && cc - 1 >= 0 && str[cc - 1] == 'C') {
bNeg = TRUE;
cc -= 2;
}
ccf -= 2;
} else {
ccf--;
}
break;
case 'b':
if (ccf - 1 >= 0 && strf[ccf - 1] == 'd') {
if (str[cc] == 'B' && cc - 1 >= 0 && str[cc - 1] == 'D') {
bNeg = TRUE;
cc -= 2;
}
ccf -= 2;
} else {
ccf--;
}
break;
case 'B':
if (ccf - 1 >= 0 && strf[ccf - 1] == 'D') {
if (str[cc] == ' ') {
cc++;
} else if (str[cc] == 'B' && cc - 1 >= 0 && str[cc - 1] == 'D') {
bNeg = TRUE;
cc -= 2;
}
ccf -= 2;
} else {
ccf--;
}
break;
case '.':
case 'V':
case 'v':
return FALSE;
case '%': {
CFX_WideString wsSymbol;
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Percent, wsSymbol);
int32_t iSysmbolLen = wsSymbol.GetLength();
cc -= iSysmbolLen - 1;
if (cc < 0 ||
FXSYS_wcsncmp(str + cc, wsSymbol.c_str(), iSysmbolLen)) {
return FALSE;
}
cc--;
ccf--;
bHavePercentSymbol = TRUE;
} break;
case '8':
while (ccf < lenf && strf[ccf] == '8') {
ccf++;
}
while (cc < len && FXSYS_isDecimalDigit(str[cc])) {
dbRetValue = (str[cc] - '0') * coeff + dbRetValue;
coeff *= 0.1;
cc++;
}
break;
case ',': {
if (cc >= 0) {
cc -= iGroupLen - 1;
if (cc >= 0 &&
FXSYS_wcsncmp(str + cc, wsGroupSymbol.c_str(), iGroupLen) ==
0) {
cc--;
} else {
cc += iGroupLen - 1;
}
}
ccf--;
} break;
case '(':
if (str[cc] == L'(') {
bNeg = TRUE;
} else if (str[cc] != L' ') {
return FALSE;
}
cc--;
ccf--;
break;
case ')':
if (str[cc] == L')') {
bNeg = TRUE;
} else if (str[cc] != L' ') {
return FALSE;
}
cc--;
ccf--;
break;
default:
if (strf[ccf] != str[cc]) {
return FALSE;
}
cc--;
ccf--;
}
}
dot_index = cc + 1;
}
ccf = dot_index_f - 1;
cc = dot_index - 1;
coeff = 1;
while (ccf >= 0 && cc >= 0) {
switch (strf[ccf]) {
case '\'': {
CFX_WideString wsLiteral = FX_GetLiteralTextReverse(strf, ccf);
int32_t iLiteralLen = wsLiteral.GetLength();
cc -= iLiteralLen - 1;
if (cc < 0 || FXSYS_wcsncmp(str + cc, wsLiteral.c_str(), iLiteralLen)) {
return FALSE;
}
cc--;
ccf--;
break;
}
case '9':
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
dbRetValue = dbRetValue + (str[cc] - '0') * coeff;
coeff *= 10;
cc--;
ccf--;
break;
case 'z':
if (FXSYS_isDecimalDigit(str[cc])) {
dbRetValue = dbRetValue + (str[cc] - '0') * coeff;
coeff *= 10;
cc--;
}
ccf--;
break;
case 'Z':
if (str[cc] != ' ') {
if (FXSYS_isDecimalDigit(str[cc])) {
dbRetValue = dbRetValue + (str[cc] - '0') * coeff;
coeff *= 10;
cc--;
}
} else {
cc--;
}
ccf--;
break;
case 'S':
if (str[cc] == '+' || str[cc] == ' ') {
cc--;
} else {
cc -= iMinusLen - 1;
if (cc < 0 || FXSYS_wcsncmp(str + cc, wsMinus.c_str(), iMinusLen)) {
return FALSE;
}
cc--;
bNeg = TRUE;
}
ccf--;
break;
case 's':
if (str[cc] == '+') {
cc--;
} else {
cc -= iMinusLen - 1;
if (cc < 0 || FXSYS_wcsncmp(str + cc, wsMinus.c_str(), iMinusLen)) {
return FALSE;
}
cc--;
bNeg = TRUE;
}
ccf--;
break;
case 'E': {
if (cc >= dot_index) {
return FALSE;
}
FX_BOOL bExpSign = FALSE;
while (cc >= 0) {
if (str[cc] == 'E' || str[cc] == 'e') {
break;
}
if (FXSYS_isDecimalDigit(str[cc])) {
iExponent = iExponent + (str[cc] - '0') * 10;
cc--;
continue;
} else if (str[cc] == '+') {
cc--;
continue;
} else if (cc - iMinusLen + 1 > 0 &&
!FXSYS_wcsncmp(str + (cc - iMinusLen + 1), wsMinus.c_str(),
iMinusLen)) {
bExpSign = TRUE;
cc -= iMinusLen;
} else {
return FALSE;
}
}
cc--;
iExponent = bExpSign ? -iExponent : iExponent;
ccf--;
} break;
case '$': {
CFX_WideString wsSymbol;
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencySymbol, wsSymbol);
int32_t iSymbolLen = wsSymbol.GetLength();
cc -= iSymbolLen - 1;
if (cc < 0 || FXSYS_wcsncmp(str + cc, wsSymbol.c_str(), iSymbolLen)) {
return FALSE;
}
cc--;
ccf--;
} break;
case 'r':
if (ccf - 1 >= 0 && strf[ccf - 1] == 'c') {
if (str[cc] == 'R' && cc - 1 >= 0 && str[cc - 1] == 'C') {
bNeg = TRUE;
cc -= 2;
}
ccf -= 2;
} else {
ccf--;
}
break;
case 'R':
if (ccf - 1 >= 0 && strf[ccf - 1] == 'C') {
if (str[cc] == ' ') {
cc++;
} else if (str[cc] == 'R' && cc - 1 >= 0 && str[cc - 1] == 'C') {
bNeg = TRUE;
cc -= 2;
}
ccf -= 2;
} else {
ccf--;
}
break;
case 'b':
if (ccf - 1 >= 0 && strf[ccf - 1] == 'd') {
if (str[cc] == 'B' && cc - 1 >= 0 && str[cc - 1] == 'D') {
bNeg = TRUE;
cc -= 2;
}
ccf -= 2;
} else {
ccf--;
}
break;
case 'B':
if (ccf - 1 >= 0 && strf[ccf - 1] == 'D') {
if (str[cc] == ' ') {
cc++;
} else if (str[cc] == 'B' && cc - 1 >= 0 && str[cc - 1] == 'D') {
bNeg = TRUE;
cc -= 2;
}
ccf -= 2;
} else {
ccf--;
}
break;
case '.':
case 'V':
case 'v':
return FALSE;
case '%': {
CFX_WideString wsSymbol;
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Percent, wsSymbol);
int32_t iSysmbolLen = wsSymbol.GetLength();
cc -= iSysmbolLen - 1;
if (cc < 0 || FXSYS_wcsncmp(str + cc, wsSymbol.c_str(), iSysmbolLen)) {
return FALSE;
}
cc--;
ccf--;
bHavePercentSymbol = TRUE;
} break;
case '8':
return FALSE;
case ',': {
if (cc >= 0) {
cc -= iGroupLen - 1;
if (cc >= 0 &&
FXSYS_wcsncmp(str + cc, wsGroupSymbol.c_str(), iGroupLen) == 0) {
cc--;
} else {
cc += iGroupLen - 1;
}
}
ccf--;
} break;
case '(':
if (str[cc] == L'(') {
bNeg = TRUE;
} else if (str[cc] != L' ') {
return FALSE;
}
cc--;
ccf--;
break;
case ')':
if (str[cc] == L')') {
bNeg = TRUE;
} else if (str[cc] != L' ') {
return FALSE;
}
cc--;
ccf--;
break;
default:
if (strf[ccf] != str[cc]) {
return FALSE;
}
cc--;
ccf--;
}
}
if (cc >= 0) {
return FALSE;
}
if (!bReverseParse) {
ccf = dot_index_f + 1;
cc = (dot_index == len) ? len : dot_index + 1;
coeff = 0.1;
while (cc < len && ccf < lenf) {
switch (strf[ccf]) {
case '\'': {
CFX_WideString wsLiteral = FX_GetLiteralText(strf, ccf, lenf);
int32_t iLiteralLen = wsLiteral.GetLength();
if (cc + iLiteralLen > len ||
FXSYS_wcsncmp(str + cc, wsLiteral.c_str(), iLiteralLen)) {
return FALSE;
}
cc += iLiteralLen;
ccf++;
break;
}
case '9':
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
{
dbRetValue = dbRetValue + (str[cc] - '0') * coeff;
coeff *= 0.1;
}
cc++;
ccf++;
break;
case 'z':
if (FXSYS_isDecimalDigit(str[cc])) {
dbRetValue = dbRetValue + (str[cc] - '0') * coeff;
coeff *= 0.1;
cc++;
}
ccf++;
break;
case 'Z':
if (str[cc] != ' ') {
if (FXSYS_isDecimalDigit(str[cc])) {
dbRetValue = dbRetValue + (str[cc] - '0') * coeff;
coeff *= 0.1;
cc++;
}
} else {
cc++;
}
ccf++;
break;
case 'S':
if (str[cc] == '+' || str[cc] == ' ') {
cc++;
} else {
if (cc + iMinusLen > len ||
FXSYS_wcsncmp(str + cc, wsMinus.c_str(), iMinusLen)) {
return FALSE;
}
bNeg = TRUE;
cc += iMinusLen;
}
ccf++;
break;
case 's':
if (str[cc] == '+') {
cc++;
} else {
if (cc + iMinusLen > len ||
FXSYS_wcsncmp(str + cc, wsMinus.c_str(), iMinusLen)) {
return FALSE;
}
bNeg = TRUE;
cc += iMinusLen;
}
ccf++;
break;
case 'E': {
if (cc >= len || (str[cc] != 'E' && str[cc] != 'e')) {
return FALSE;
}
FX_BOOL bExpSign = FALSE;
cc++;
if (cc < len) {
if (str[cc] == '+') {
cc++;
} else if (str[cc] == '-') {
bExpSign = TRUE;
cc++;
}
}
while (cc < len) {
if (!FXSYS_isDecimalDigit(str[cc])) {
break;
}
iExponent = iExponent * 10 + str[cc] - '0';
cc++;
}
iExponent = bExpSign ? -iExponent : iExponent;
ccf++;
} break;
case '$': {
CFX_WideString wsSymbol;
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencySymbol,
wsSymbol);
int32_t iSymbolLen = wsSymbol.GetLength();
if (cc + iSymbolLen > len ||
FXSYS_wcsncmp(str + cc, wsSymbol.c_str(), iSymbolLen)) {
return FALSE;
}
cc += iSymbolLen;
ccf++;
} break;
case 'c':
if (ccf + 1 < lenf && strf[ccf + 1] == 'r') {
if (str[cc] == 'C' && cc + 1 < len && str[cc + 1] == 'R') {
bNeg = TRUE;
cc += 2;
}
ccf += 2;
}
break;
case 'C':
if (ccf + 1 < lenf && strf[ccf + 1] == 'R') {
if (str[cc] == ' ') {
cc++;
} else if (str[cc] == 'C' && cc + 1 < len && str[cc + 1] == 'R') {
bNeg = TRUE;
cc += 2;
}
ccf += 2;
}
break;
case 'd':
if (ccf + 1 < lenf && strf[ccf + 1] == 'b') {
if (str[cc] == 'D' && cc + 1 < len && str[cc + 1] == 'B') {
bNeg = TRUE;
cc += 2;
}
ccf += 2;
}
break;
case 'D':
if (ccf + 1 < lenf && strf[ccf + 1] == 'B') {
if (str[cc] == ' ') {
cc++;
} else if (str[cc] == 'D' && cc + 1 < len && str[cc + 1] == 'B') {
bNeg = TRUE;
cc += 2;
}
ccf += 2;
}
break;
case '.':
case 'V':
case 'v':
return FALSE;
case '%': {
CFX_WideString wsSymbol;
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Percent, wsSymbol);
int32_t iSysmbolLen = wsSymbol.GetLength();
if (cc + iSysmbolLen <= len &&
!FXSYS_wcsncmp(str + cc, wsSymbol.c_str(), iSysmbolLen)) {
cc += iSysmbolLen;
}
ccf++;
bHavePercentSymbol = TRUE;
} break;
case '8': {
while (ccf < lenf && strf[ccf] == '8') {
ccf++;
}
while (cc < len && FXSYS_isDecimalDigit(str[cc])) {
dbRetValue = (str[cc] - '0') * coeff + dbRetValue;
coeff *= 0.1;
cc++;
}
} break;
case ',': {
if (cc + iGroupLen <= len &&
FXSYS_wcsncmp(str + cc, wsGroupSymbol.c_str(), iGroupLen) == 0) {
cc += iGroupLen;
}
ccf++;
} break;
case '(':
if (str[cc] == L'(') {
bNeg = TRUE;
} else if (str[cc] != L' ') {
return FALSE;
}
cc++;
ccf++;
break;
case ')':
if (str[cc] == L')') {
bNeg = TRUE;
} else if (str[cc] != L' ') {
return FALSE;
}
cc++;
ccf++;
break;
default:
if (strf[ccf] != str[cc]) {
return FALSE;
}
cc++;
ccf++;
}
}
if (cc != len) {
return FALSE;
}
}
if (iExponent) {
dbRetValue *= FXSYS_pow(10, (FX_FLOAT)iExponent);
}
if (bHavePercentSymbol) {
dbRetValue /= 100.0;
}
if (bNeg) {
dbRetValue = -dbRetValue;
}
fValue = (FX_FLOAT)dbRetValue;
return TRUE;
}
FX_BOOL CFX_FormatString::ParseNum(const CFX_WideString& wsSrcNum,
const CFX_WideString& wsPattern,
CFX_WideString& wsValue) {
wsValue.clear();
if (wsSrcNum.IsEmpty() || wsPattern.IsEmpty()) {
return FALSE;
}
int32_t dot_index_f = -1;
uint32_t dwFormatStyle = 0;
CFX_WideString wsNumFormat;
IFX_Locale* pLocale =
GetNumericFormat(wsPattern, dot_index_f, dwFormatStyle, wsNumFormat);
if (!pLocale || wsNumFormat.IsEmpty()) {
return FALSE;
}
int32_t iExponent = 0;
CFX_WideString wsDotSymbol;
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal, wsDotSymbol);
CFX_WideString wsGroupSymbol;
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Grouping, wsGroupSymbol);
int32_t iGroupLen = wsGroupSymbol.GetLength();
CFX_WideString wsMinus;
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus, wsMinus);
int32_t iMinusLen = wsMinus.GetLength();
int cc = 0, ccf = 0;
const FX_WCHAR* str = wsSrcNum.c_str();
int len = wsSrcNum.GetLength();
const FX_WCHAR* strf = wsNumFormat.c_str();
int lenf = wsNumFormat.GetLength();
FX_BOOL bHavePercentSymbol = FALSE;
FX_BOOL bNeg = FALSE;
FX_BOOL bReverseParse = FALSE;
int32_t dot_index = 0;
if (!FX_GetNumericDotIndex(wsSrcNum, wsDotSymbol, dot_index) &&
(dwFormatStyle & FX_NUMSTYLE_DotVorv)) {
bReverseParse = TRUE;
}
bReverseParse = FALSE;
ccf = dot_index_f - 1;
cc = dot_index - 1;
while (ccf >= 0 && cc >= 0) {
switch (strf[ccf]) {
case '\'': {
CFX_WideString wsLiteral = FX_GetLiteralTextReverse(strf, ccf);
int32_t iLiteralLen = wsLiteral.GetLength();
cc -= iLiteralLen - 1;
if (cc < 0 || FXSYS_wcsncmp(str + cc, wsLiteral.c_str(), iLiteralLen)) {
return FALSE;
}
cc--;
ccf--;
break;
}
case '9':
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
wsValue = str[cc] + wsValue;
cc--;
ccf--;
break;
case 'z':
if (FXSYS_isDecimalDigit(str[cc])) {
wsValue = str[cc] + wsValue;
cc--;
}
ccf--;
break;
case 'Z':
if (str[cc] != ' ') {
if (FXSYS_isDecimalDigit(str[cc])) {
wsValue = str[cc] + wsValue;
cc--;
}
} else {
cc--;
}
ccf--;
break;
case 'S':
if (str[cc] == '+' || str[cc] == ' ') {
cc--;
} else {
cc -= iMinusLen - 1;
if (cc < 0 || FXSYS_wcsncmp(str + cc, wsMinus.c_str(), iMinusLen)) {
return FALSE;
}
cc--;
bNeg = TRUE;
}
ccf--;
break;
case 's':
if (str[cc] == '+') {
cc--;
} else {
cc -= iMinusLen - 1;
if (cc < 0 || FXSYS_wcsncmp(str + cc, wsMinus.c_str(), iMinusLen)) {
return FALSE;
}
cc--;
bNeg = TRUE;
}
ccf--;
break;
case 'E': {
if (cc >= dot_index) {
return FALSE;
}
FX_BOOL bExpSign = FALSE;
while (cc >= 0) {
if (str[cc] == 'E' || str[cc] == 'e') {
break;
}
if (FXSYS_isDecimalDigit(str[cc])) {
iExponent = iExponent + (str[cc] - '0') * 10;
cc--;
continue;
} else if (str[cc] == '+') {
cc--;
continue;
} else if (cc - iMinusLen + 1 > 0 &&
!FXSYS_wcsncmp(str + (cc - iMinusLen + 1), wsMinus.c_str(),
iMinusLen)) {
bExpSign = TRUE;
cc -= iMinusLen;
} else {
return FALSE;
}
}
cc--;
iExponent = bExpSign ? -iExponent : iExponent;
ccf--;
} break;
case '$': {
CFX_WideString wsSymbol;
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencySymbol, wsSymbol);
int32_t iSymbolLen = wsSymbol.GetLength();
cc -= iSymbolLen - 1;
if (cc < 0 || FXSYS_wcsncmp(str + cc, wsSymbol.c_str(), iSymbolLen)) {
return FALSE;
}
cc--;
ccf--;
} break;
case 'r':
if (ccf - 1 >= 0 && strf[ccf - 1] == 'c') {
if (str[cc] == 'R' && cc - 1 >= 0 && str[cc - 1] == 'C') {
bNeg = TRUE;
cc -= 2;
}
ccf -= 2;
} else {
ccf--;
}
break;
case 'R':
if (ccf - 1 >= 0 && strf[ccf - 1] == 'C') {
if (str[cc] == ' ') {
cc++;
} else if (str[cc] == 'R' && cc - 1 >= 0 && str[cc - 1] == 'C') {
bNeg = TRUE;
cc -= 2;
}
ccf -= 2;
} else {
ccf--;
}
break;
case 'b':
if (ccf - 1 >= 0 && strf[ccf - 1] == 'd') {
if (str[cc] == 'B' && cc - 1 >= 0 && str[cc - 1] == 'D') {
bNeg = TRUE;
cc -= 2;
}
ccf -= 2;
} else {
ccf--;
}
break;
case 'B':
if (ccf - 1 >= 0 && strf[ccf - 1] == 'D') {
if (str[cc] == ' ') {
cc++;
} else if (str[cc] == 'B' && cc - 1 >= 0 && str[cc - 1] == 'D') {
bNeg = TRUE;
cc -= 2;
}
ccf -= 2;
} else {
ccf--;
}
break;
case '.':
case 'V':
case 'v':
return FALSE;
case '%': {
CFX_WideString wsSymbol;
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Percent, wsSymbol);
int32_t iSysmbolLen = wsSymbol.GetLength();
cc -= iSysmbolLen - 1;
if (cc < 0 || FXSYS_wcsncmp(str + cc, wsSymbol.c_str(), iSysmbolLen)) {
return FALSE;
}
cc--;
ccf--;
bHavePercentSymbol = TRUE;
} break;
case '8':
return FALSE;
case ',': {
if (cc >= 0) {
cc -= iGroupLen - 1;
if (cc >= 0 &&
FXSYS_wcsncmp(str + cc, wsGroupSymbol.c_str(), iGroupLen) == 0) {
cc--;
} else {
cc += iGroupLen - 1;
}
}
ccf--;
} break;
case '(':
if (str[cc] == L'(') {
bNeg = TRUE;
} else if (str[cc] != L' ') {
return FALSE;
}
cc--;
ccf--;
break;
case ')':
if (str[cc] == L')') {
bNeg = TRUE;
} else if (str[cc] != L' ') {
return FALSE;
}
cc--;
ccf--;
break;
default:
if (strf[ccf] != str[cc]) {
return FALSE;
}
cc--;
ccf--;
}
}
if (cc >= 0) {
if (str[cc] == '-') {
bNeg = TRUE;
cc--;
}
if (cc >= 0) {
return FALSE;
}
}
if (dot_index < len && (dwFormatStyle & FX_NUMSTYLE_DotVorv)) {
wsValue += '.';
}
if (!bReverseParse) {
ccf = dot_index_f + 1;
cc = (dot_index == len) ? len : dot_index + 1;
while (cc < len && ccf < lenf) {
switch (strf[ccf]) {
case '\'': {
CFX_WideString wsLiteral = FX_GetLiteralText(strf, ccf, lenf);
int32_t iLiteralLen = wsLiteral.GetLength();
if (cc + iLiteralLen > len ||
FXSYS_wcsncmp(str + cc, wsLiteral.c_str(), iLiteralLen)) {
return FALSE;
}
cc += iLiteralLen;
ccf++;
break;
}
case '9':
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
{ wsValue += str[cc]; }
cc++;
ccf++;
break;
case 'z':
if (FXSYS_isDecimalDigit(str[cc])) {
wsValue += str[cc];
cc++;
}
ccf++;
break;
case 'Z':
if (str[cc] != ' ') {
if (FXSYS_isDecimalDigit(str[cc])) {
wsValue += str[cc];
cc++;
}
} else {
cc++;
}
ccf++;
break;
case 'S':
if (str[cc] == '+' || str[cc] == ' ') {
cc++;
} else {
if (cc + iMinusLen > len ||
FXSYS_wcsncmp(str + cc, wsMinus.c_str(), iMinusLen)) {
return FALSE;
}
bNeg = TRUE;
cc += iMinusLen;
}
ccf++;
break;
case 's':
if (str[cc] == '+') {
cc++;
} else {
if (cc + iMinusLen > len ||
FXSYS_wcsncmp(str + cc, wsMinus.c_str(), iMinusLen)) {
return FALSE;
}
bNeg = TRUE;
cc += iMinusLen;
}
ccf++;
break;
case 'E': {
if (cc >= len || (str[cc] != 'E' && str[cc] != 'e')) {
return FALSE;
}
FX_BOOL bExpSign = FALSE;
cc++;
if (cc < len) {
if (str[cc] == '+') {
cc++;
} else if (str[cc] == '-') {
bExpSign = TRUE;
cc++;
}
}
while (cc < len) {
if (!FXSYS_isDecimalDigit(str[cc])) {
break;
}
iExponent = iExponent * 10 + str[cc] - '0';
cc++;
}
iExponent = bExpSign ? -iExponent : iExponent;
ccf++;
} break;
case '$': {
CFX_WideString wsSymbol;
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencySymbol,
wsSymbol);
int32_t iSymbolLen = wsSymbol.GetLength();
if (cc + iSymbolLen > len ||
FXSYS_wcsncmp(str + cc, wsSymbol.c_str(), iSymbolLen)) {
return FALSE;
}
cc += iSymbolLen;
ccf++;
} break;
case 'c':
if (ccf + 1 < lenf && strf[ccf + 1] == 'r') {
if (str[cc] == 'C' && cc + 1 < len && str[cc + 1] == 'R') {
bNeg = TRUE;
cc += 2;
}
ccf += 2;
}
break;
case 'C':
if (ccf + 1 < lenf && strf[ccf + 1] == 'R') {
if (str[cc] == ' ') {
cc++;
} else if (str[cc] == 'C' && cc + 1 < len && str[cc + 1] == 'R') {
bNeg = TRUE;
cc += 2;
}
ccf += 2;
}
break;
case 'd':
if (ccf + 1 < lenf && strf[ccf + 1] == 'b') {
if (str[cc] == 'D' && cc + 1 < len && str[cc + 1] == 'B') {
bNeg = TRUE;
cc += 2;
}
ccf += 2;
}
break;
case 'D':
if (ccf + 1 < lenf && strf[ccf + 1] == 'B') {
if (str[cc] == ' ') {
cc++;
} else if (str[cc] == 'D' && cc + 1 < len && str[cc + 1] == 'B') {
bNeg = TRUE;
cc += 2;
}
ccf += 2;
}
break;
case '.':
case 'V':
case 'v':
return FALSE;
case '%': {
CFX_WideString wsSymbol;
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Percent, wsSymbol);
int32_t iSysmbolLen = wsSymbol.GetLength();
if (cc + iSysmbolLen <= len &&
!FXSYS_wcsncmp(str + cc, wsSymbol.c_str(), iSysmbolLen)) {
cc += iSysmbolLen;
}
ccf++;
bHavePercentSymbol = TRUE;
} break;
case '8': {
while (ccf < lenf && strf[ccf] == '8') {
ccf++;
}
while (cc < len && FXSYS_isDecimalDigit(str[cc])) {
wsValue += str[cc];
cc++;
}
} break;
case ',': {
if (cc + iGroupLen <= len &&
FXSYS_wcsncmp(str + cc, wsGroupSymbol.c_str(), iGroupLen) == 0) {
cc += iGroupLen;
}
ccf++;
} break;
case '(':
if (str[cc] == L'(') {
bNeg = TRUE;
} else if (str[cc] != L' ') {
return FALSE;
}
cc++;
ccf++;
break;
case ')':
if (str[cc] == L')') {
bNeg = TRUE;
} else if (str[cc] != L' ') {
return FALSE;
}
cc++;
ccf++;
break;
default:
if (strf[ccf] != str[cc]) {
return FALSE;
}
cc++;
ccf++;
}
}
if (cc != len) {
return FALSE;
}
}
if (iExponent || bHavePercentSymbol) {
CFX_Decimal decimal = CFX_Decimal(wsValue.AsStringC());
if (iExponent) {
decimal = decimal * CFX_Decimal(FXSYS_pow(10, (FX_FLOAT)iExponent));
}
if (bHavePercentSymbol) {
decimal = decimal / CFX_Decimal(100);
}
wsValue = decimal;
}
if (bNeg) {
wsValue = L'-' + wsValue;
}
return TRUE;
}
FX_DATETIMETYPE CFX_FormatString::GetDateTimeFormat(
const CFX_WideString& wsPattern,
IFX_Locale*& pLocale,
CFX_WideString& wsDatePattern,
CFX_WideString& wsTimePattern) {
pLocale = nullptr;
CFX_WideString wsTempPattern;
FX_LOCALECATEGORY eCategory = FX_LOCALECATEGORY_Unknown;
int32_t ccf = 0;
int32_t iLenf = wsPattern.GetLength();
const FX_WCHAR* pStr = wsPattern.c_str();
int32_t iFindCategory = 0;
FX_BOOL bBraceOpen = FALSE;
CFX_WideStringC wsConstChars(gs_wsConstChars);
while (ccf < iLenf) {
if (pStr[ccf] == '\'') {
int32_t iCurChar = ccf;
FX_GetLiteralText(pStr, ccf, iLenf);
wsTempPattern += CFX_WideStringC(pStr + iCurChar, ccf - iCurChar + 1);
} else if (!bBraceOpen && iFindCategory != 3 &&
wsConstChars.Find(pStr[ccf]) == -1) {
CFX_WideString wsCategory(pStr[ccf]);
ccf++;
while (ccf < iLenf && pStr[ccf] != '{' && pStr[ccf] != '.' &&
pStr[ccf] != '(') {
if (pStr[ccf] == 'T') {
wsDatePattern = wsPattern.Left(ccf);
wsTimePattern = wsPattern.Right(wsPattern.GetLength() - ccf);
wsTimePattern.SetAt(0, ' ');
if (!pLocale) {
pLocale = m_pLocaleMgr->GetDefLocale();
}
return FX_DATETIMETYPE_DateTime;
}
wsCategory += pStr[ccf];
ccf++;
}
if (!(iFindCategory & 1) && wsCategory == FX_WSTRC(L"date")) {
iFindCategory |= 1;
eCategory = FX_LOCALECATEGORY_Date;
if (iFindCategory & 2) {
iFindCategory = 4;
}
} else if (!(iFindCategory & 2) && wsCategory == FX_WSTRC(L"time")) {
iFindCategory |= 2;
eCategory = FX_LOCALECATEGORY_Time;
} else if (wsCategory == FX_WSTRC(L"datetime")) {
iFindCategory = 3;
eCategory = FX_LOCALECATEGORY_DateTime;
} else {
continue;
}
while (ccf < iLenf) {
if (pStr[ccf] == '(') {
ccf++;
CFX_WideString wsLCID;
while (ccf < iLenf && pStr[ccf] != ')') {
wsLCID += pStr[ccf++];
}
pLocale = GetPatternLocale(wsLCID);
} else if (pStr[ccf] == '{') {
bBraceOpen = TRUE;
break;
} else if (pStr[ccf] == '.') {
CFX_WideString wsSubCategory;
ccf++;
while (ccf < iLenf && pStr[ccf] != '(' && pStr[ccf] != '{') {
wsSubCategory += pStr[ccf++];
}
uint32_t dwSubHash =
FX_HashCode_GetW(wsSubCategory.AsStringC(), false);
FX_LOCALEDATETIMESUBCATEGORY eSubCategory =
FX_LOCALEDATETIMESUBCATEGORY_Medium;
for (int32_t i = 0; i < g_iFXLocaleDateTimeSubCatCount; i++) {
if (g_FXLocaleDateTimeSubCatData[i].uHash == dwSubHash) {
eSubCategory =
(FX_LOCALEDATETIMESUBCATEGORY)g_FXLocaleDateTimeSubCatData[i]
.eSubCategory;
break;
}
}
if (!pLocale) {
pLocale = m_pLocaleMgr->GetDefLocale();
}
ASSERT(pLocale);
switch (eCategory) {
case FX_LOCALECATEGORY_Date:
pLocale->GetDatePattern(eSubCategory, wsDatePattern);
wsDatePattern = wsTempPattern + wsDatePattern;
break;
case FX_LOCALECATEGORY_Time:
pLocale->GetTimePattern(eSubCategory, wsTimePattern);
wsTimePattern = wsTempPattern + wsTimePattern;
break;
case FX_LOCALECATEGORY_DateTime:
pLocale->GetDatePattern(eSubCategory, wsDatePattern);
wsDatePattern = wsTempPattern + wsDatePattern;
pLocale->GetTimePattern(eSubCategory, wsTimePattern);
break;
default:
break;
}
wsTempPattern.clear();
continue;
}
ccf++;
}
} else if (pStr[ccf] == '}') {
bBraceOpen = FALSE;
if (!wsTempPattern.IsEmpty()) {
if (eCategory == FX_LOCALECATEGORY_Time) {
wsTimePattern = wsTempPattern;
} else if (eCategory == FX_LOCALECATEGORY_Date) {
wsDatePattern = wsTempPattern;
}
wsTempPattern.clear();
}
} else {
wsTempPattern += pStr[ccf];
}
ccf++;
}
if (!wsTempPattern.IsEmpty()) {
if (eCategory == FX_LOCALECATEGORY_Date) {
wsDatePattern += wsTempPattern;
} else {
wsTimePattern += wsTempPattern;
}
}
if (!pLocale) {
pLocale = m_pLocaleMgr->GetDefLocale();
}
if (!iFindCategory) {
wsTimePattern.clear();
wsDatePattern = wsPattern;
}
return (FX_DATETIMETYPE)iFindCategory;
}
static FX_BOOL FX_ParseLocaleDate(const CFX_WideString& wsDate,
const CFX_WideString& wsDatePattern,
IFX_Locale* pLocale,
CFX_Unitime& datetime,
int32_t& cc) {
int32_t year = 1900;
int32_t month = 1;
int32_t day = 1;
int32_t ccf = 0;
const FX_WCHAR* str = wsDate.c_str();
int32_t len = wsDate.GetLength();
const FX_WCHAR* strf = wsDatePattern.c_str();
int32_t lenf = wsDatePattern.GetLength();
CFX_WideStringC wsDateSymbols(gs_wsDateSymbols);
while (cc < len && ccf < lenf) {
if (strf[ccf] == '\'') {
CFX_WideString wsLiteral = FX_GetLiteralText(strf, ccf, lenf);
int32_t iLiteralLen = wsLiteral.GetLength();
if (cc + iLiteralLen > len ||
FXSYS_wcsncmp(str + cc, wsLiteral.c_str(), iLiteralLen)) {
return FALSE;
}
cc += iLiteralLen;
ccf++;
continue;
} else if (wsDateSymbols.Find(strf[ccf]) == -1) {
if (strf[ccf] != str[cc])
return FALSE;
cc++;
ccf++;
continue;
}
uint32_t dwSymbolNum = 1;
FX_WCHAR dwCharSymbol = strf[ccf++];
while (ccf < lenf && strf[ccf] == dwCharSymbol) {
ccf++;
dwSymbolNum++;
}
uint32_t dwSymbol = (dwCharSymbol << 8) | (dwSymbolNum + '0');
if (dwSymbol == FXBSTR_ID(0, 0, 'D', '1')) {
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
day = str[cc++] - '0';
if (cc < len && FXSYS_isDecimalDigit(str[cc])) {
day = day * 10 + str[cc++] - '0';
}
} else if (dwSymbol == FXBSTR_ID(0, 0, 'D', '2')) {
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
day = str[cc++] - '0';
if (cc < len) {
day = day * 10 + str[cc++] - '0';
}
} else if (dwSymbol == FXBSTR_ID(0, 0, 'J', '1')) {
int i = 0;
while (cc < len && i < 3 && FXSYS_isDecimalDigit(str[cc])) {
cc++;
i++;
}
} else if (dwSymbol == FXBSTR_ID(0, 0, 'J', '3')) {
cc += 3;
} else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '1')) {
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
month = str[cc++] - '0';
if (cc < len && FXSYS_isDecimalDigit(str[cc])) {
month = month * 10 + str[cc++] - '0';
}
} else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '2')) {
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
month = str[cc++] - '0';
if (cc < len) {
month = month * 10 + str[cc++] - '0';
}
} else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '3')) {
CFX_WideString wsMonthNameAbbr;
uint16_t i = 0;
for (; i < 12; i++) {
pLocale->GetMonthName(i, wsMonthNameAbbr, TRUE);
if (wsMonthNameAbbr.IsEmpty()) {
continue;
}
if (!FXSYS_wcsncmp(wsMonthNameAbbr.c_str(), str + cc,
wsMonthNameAbbr.GetLength())) {
break;
}
}
if (i < 12) {
cc += wsMonthNameAbbr.GetLength();
month = i + 1;
}
} else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '4')) {
CFX_WideString wsMonthName;
uint16_t i = 0;
for (; i < 12; i++) {
pLocale->GetMonthName(i, wsMonthName, FALSE);
if (wsMonthName.IsEmpty()) {
continue;
}
if (!FXSYS_wcsncmp(wsMonthName.c_str(), str + cc,
wsMonthName.GetLength())) {
break;
}
}
if (i < 12) {
cc += wsMonthName.GetLength();
month = i + 1;
}
} else if (dwSymbol == FXBSTR_ID(0, 0, 'E', '1')) {
cc += 1;
} else if (dwSymbol == FXBSTR_ID(0, 0, 'E', '3')) {
CFX_WideString wsDayNameAbbr;
uint16_t i = 0;
for (; i < 7; i++) {
pLocale->GetDayName(i, wsDayNameAbbr, TRUE);
if (wsDayNameAbbr.IsEmpty()) {
continue;
}
if (!FXSYS_wcsncmp(wsDayNameAbbr.c_str(), str + cc,
wsDayNameAbbr.GetLength())) {
break;
}
}
if (i < 12) {
cc += wsDayNameAbbr.GetLength();
}
} else if (dwSymbol == FXBSTR_ID(0, 0, 'E', '4')) {
CFX_WideString wsDayName;
int32_t i = 0;
for (; i < 7; i++) {
pLocale->GetDayName(i, wsDayName, FALSE);
if (wsDayName == L"") {
continue;
}
if (!FXSYS_wcsncmp(wsDayName.c_str(), str + cc,
wsDayName.GetLength())) {
break;
}
}
if (i < 12) {
cc += wsDayName.GetLength();
}
} else if (dwSymbol == FXBSTR_ID(0, 0, 'e', '1')) {
cc += 1;
} else if (dwSymbol == FXBSTR_ID(0, 0, 'G', '1')) {
cc += 2;
} else if (dwSymbol == FXBSTR_ID(0, 0, 'Y', '2')) {
if (cc + 2 > len) {
return FALSE;
}
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
year = str[cc++] - '0';
if (cc >= len || !FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
year = year * 10 + str[cc++] - '0';
if (year <= 29) {
year += 2000;
} else {
year += 1900;
}
} else if (dwSymbol == FXBSTR_ID(0, 0, 'Y', '4')) {
int i = 0;
year = 0;
if (cc + 4 > len) {
return FALSE;
}
while (i < 4) {
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
year = year * 10 + str[cc] - '0';
cc++;
i++;
}
} else if (dwSymbol == FXBSTR_ID(0, 0, 'w', '1')) {
cc += 1;
} else if (dwSymbol == FXBSTR_ID(0, 0, 'W', '2')) {
cc += 2;
}
}
if (cc < len) {
return FALSE;
}
CFX_Unitime ut;
ut.Set(year, month, day);
datetime = datetime + ut;
return cc;
}
static void FX_ResolveZone(uint8_t& wHour,
uint8_t& wMinute,
FX_TIMEZONE tzDiff,
IFX_Locale* pLocale) {
int32_t iMinuteDiff = wHour * 60 + wMinute;
FX_TIMEZONE tzLocale;
pLocale->GetTimeZone(tzLocale);
iMinuteDiff += tzLocale.tzHour * 60 +
(tzLocale.tzHour < 0 ? -tzLocale.tzMinute : tzLocale.tzMinute);
iMinuteDiff -= tzDiff.tzHour * 60 +
(tzDiff.tzHour < 0 ? -tzDiff.tzMinute : tzDiff.tzMinute);
while (iMinuteDiff > 1440) {
iMinuteDiff -= 1440;
}
while (iMinuteDiff < 0) {
iMinuteDiff += 1440;
}
wHour = iMinuteDiff / 60;
wMinute = iMinuteDiff % 60;
}
static FX_BOOL FX_ParseLocaleTime(const CFX_WideString& wsTime,
const CFX_WideString& wsTimePattern,
IFX_Locale* pLocale,
CFX_Unitime& datetime,
int32_t& cc) {
uint8_t hour = 0;
uint8_t minute = 0;
uint8_t second = 0;
uint16_t millisecond = 0;
int32_t ccf = 0;
const FX_WCHAR* str = wsTime.c_str();
int len = wsTime.GetLength();
const FX_WCHAR* strf = wsTimePattern.c_str();
int lenf = wsTimePattern.GetLength();
FX_BOOL bHasA = FALSE;
FX_BOOL bPM = FALSE;
CFX_WideStringC wsTimeSymbols(gs_wsTimeSymbols);
while (cc < len && ccf < lenf) {
if (strf[ccf] == '\'') {
CFX_WideString wsLiteral = FX_GetLiteralText(strf, ccf, lenf);
int32_t iLiteralLen = wsLiteral.GetLength();
if (cc + iLiteralLen > len ||
FXSYS_wcsncmp(str + cc, wsLiteral.c_str(), iLiteralLen)) {
return FALSE;
}
cc += iLiteralLen;
ccf++;
continue;
} else if (wsTimeSymbols.Find(strf[ccf]) == -1) {
if (strf[ccf] != str[cc])
return FALSE;
cc++;
ccf++;
continue;
}
uint32_t dwSymbolNum = 1;
FX_WCHAR dwCharSymbol = strf[ccf++];
while (ccf < lenf && strf[ccf] == dwCharSymbol) {
ccf++;
dwSymbolNum++;
}
uint32_t dwSymbol = (dwCharSymbol << 8) | (dwSymbolNum + '0');
if (dwSymbol == FXBSTR_ID(0, 0, 'k', '1') ||
dwSymbol == FXBSTR_ID(0, 0, 'H', '1') ||
dwSymbol == FXBSTR_ID(0, 0, 'h', '1') ||
dwSymbol == FXBSTR_ID(0, 0, 'K', '1')) {
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
hour = str[cc++] - '0';
if (cc < len && FXSYS_isDecimalDigit(str[cc])) {
hour = hour * 10 + str[cc++] - '0';
}
if (dwSymbol == FXBSTR_ID(0, 0, 'K', '1') && hour == 24) {
hour = 0;
}
} else if (dwSymbol == FXBSTR_ID(0, 0, 'k', '2') ||
dwSymbol == FXBSTR_ID(0, 0, 'H', '2') ||
dwSymbol == FXBSTR_ID(0, 0, 'h', '2') ||
dwSymbol == FXBSTR_ID(0, 0, 'K', '2')) {
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
hour = str[cc++] - '0';
if (cc >= len) {
return FALSE;
}
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
hour = hour * 10 + str[cc++] - '0';
if (dwSymbol == FXBSTR_ID(0, 0, 'K', '2') && hour == 24) {
hour = 0;
}
} else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '1')) {
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
minute = str[cc++] - '0';
if (cc < len && FXSYS_isDecimalDigit(str[cc])) {
minute = minute * 10 + str[cc++] - '0';
}
} else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '2')) {
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
minute = str[cc++] - '0';
if (cc >= len) {
return FALSE;
}
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
minute = minute * 10 + str[cc++] - '0';
} else if (dwSymbol == FXBSTR_ID(0, 0, 'S', '1')) {
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
second = str[cc++] - '0';
if (cc < len && FXSYS_isDecimalDigit(str[cc])) {
second = second * 10 + str[cc++] - '0';
}
} else if (dwSymbol == FXBSTR_ID(0, 0, 'S', '2')) {
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
second = str[cc++] - '0';
if (cc >= len) {
return FALSE;
}
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
second = second * 10 + str[cc++] - '0';
} else if (dwSymbol == FXBSTR_ID(0, 0, 'F', '3')) {
if (cc + 3 >= len) {
return FALSE;
}
int i = 0;
while (i < 3) {
if (!FXSYS_isDecimalDigit(str[cc])) {
return FALSE;
}
millisecond = millisecond * 10 + str[cc++] - '0';
i++;
}
} else if (dwSymbol == FXBSTR_ID(0, 0, 'A', '1')) {
CFX_WideString wsAM;
pLocale->GetMeridiemName(wsAM, TRUE);
CFX_WideString wsPM;
pLocale->GetMeridiemName(wsPM, FALSE);
if ((cc + wsAM.GetLength() <= len) &&
(CFX_WideStringC(str + cc, wsAM.GetLength()) == wsAM)) {
cc += wsAM.GetLength();
bHasA = TRUE;
} else if ((cc + wsPM.GetLength() <= len) &&
(CFX_WideStringC(str + cc, wsPM.GetLength()) == wsPM)) {
cc += wsPM.GetLength();