Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: xfa/fxfa/fm2js/xfa_fm2jscontext.cpp

Issue 2043743002: xfa_fm2jscontext method cleanup - pt IV (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@execute_context
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fxfa/fm2js/xfa_fm2jscontext.h" 7 #include "xfa/fxfa/fm2js/xfa_fm2jscontext.h"
8 8
9 #include <time.h> 9 #include <time.h>
10 10
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 } 439 }
440 440
441 patternType = XFA_VT_NULL; 441 patternType = XFA_VT_NULL;
442 wsPattern.MakeLower(); 442 wsPattern.MakeLower();
443 const FX_WCHAR* pData = wsPattern.c_str(); 443 const FX_WCHAR* pData = wsPattern.c_str();
444 int32_t iLength = wsPattern.GetLength(); 444 int32_t iLength = wsPattern.GetLength();
445 int32_t iIndex = 0; 445 int32_t iIndex = 0;
446 FX_BOOL bSingleQuotation = FALSE; 446 FX_BOOL bSingleQuotation = FALSE;
447 FX_WCHAR patternChar; 447 FX_WCHAR patternChar;
448 while (iIndex < iLength) { 448 while (iIndex < iLength) {
449 patternChar = *(pData + iIndex); 449 patternChar = pData[iIndex];
450 if (patternChar == 0x27) { 450 if (patternChar == 0x27) {
451 bSingleQuotation = !bSingleQuotation; 451 bSingleQuotation = !bSingleQuotation;
452 } else if (!bSingleQuotation && 452 } else if (!bSingleQuotation &&
453 (patternChar == 'y' || patternChar == 'j')) { 453 (patternChar == 'y' || patternChar == 'j')) {
454 patternType = XFA_VT_DATE; 454 patternType = XFA_VT_DATE;
455 iIndex++; 455 iIndex++;
456 FX_WCHAR timePatternChar; 456 FX_WCHAR timePatternChar;
457 while (iIndex < iLength) { 457 while (iIndex < iLength) {
458 timePatternChar = *(pData + iIndex); 458 timePatternChar = pData[iIndex];
459 if (timePatternChar == 0x27) { 459 if (timePatternChar == 0x27) {
460 bSingleQuotation = !bSingleQuotation; 460 bSingleQuotation = !bSingleQuotation;
461 } else if (!bSingleQuotation && timePatternChar == 't') { 461 } else if (!bSingleQuotation && timePatternChar == 't') {
462 patternType = XFA_VT_DATETIME; 462 patternType = XFA_VT_DATETIME;
463 break; 463 break;
464 } 464 }
465 iIndex++; 465 iIndex++;
466 } 466 }
467 break; 467 break;
468 } else if (!bSingleQuotation && 468 } else if (!bSingleQuotation &&
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 FXJSE_Value_SetDouble(args.GetReturnValue(), 894 FXJSE_Value_SetDouble(args.GetReturnValue(),
895 dDividend - dDivisor * (int32_t)(dDividend / dDivisor)); 895 dDividend - dDivisor * (int32_t)(dDividend / dDivisor));
896 } 896 }
897 897
898 // static 898 // static
899 void CXFA_FM2JSContext::Round(CFXJSE_Value* pThis, 899 void CXFA_FM2JSContext::Round(CFXJSE_Value* pThis,
900 const CFX_ByteStringC& szFuncName, 900 const CFX_ByteStringC& szFuncName,
901 CFXJSE_Arguments& args) { 901 CFXJSE_Arguments& args) {
902 CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr); 902 CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr);
903 int32_t argc = args.GetLength(); 903 int32_t argc = args.GetLength();
904 if (argc != 1 && argc != 2) { 904 if (argc < 1 || argc > 2) {
905 pContext->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Round"); 905 pContext->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Round");
906 return; 906 return;
907 } 907 }
908 908
909 std::unique_ptr<CFXJSE_Value> argOne = args.GetValue(0); 909 std::unique_ptr<CFXJSE_Value> argOne = args.GetValue(0);
910 if (FXJSE_Value_IsNull(argOne.get())) { 910 if (FXJSE_Value_IsNull(argOne.get())) {
911 FXJSE_Value_SetNull(args.GetReturnValue()); 911 FXJSE_Value_SetNull(args.GetReturnValue());
912 return; 912 return;
913 } 913 }
914 914
915 bool dValueRet; 915 bool dValueRet;
916 FX_DOUBLE dValue = ExtractDouble(pThis, argOne.get(), &dValueRet); 916 FX_DOUBLE dValue = ExtractDouble(pThis, argOne.get(), &dValueRet);
917 if (!dValueRet) { 917 if (!dValueRet) {
918 pContext->ThrowException(XFA_IDS_ARGUMENT_MISMATCH); 918 pContext->ThrowException(XFA_IDS_ARGUMENT_MISMATCH);
919 return; 919 return;
920 } 920 }
921 921
922 uint8_t uPrecision = 0; 922 uint8_t uPrecision = 0;
923 if (argc == 2) { 923 if (argc > 1) {
924 std::unique_ptr<CFXJSE_Value> argTwo = args.GetValue(1); 924 std::unique_ptr<CFXJSE_Value> argTwo = args.GetValue(1);
925 if (FXJSE_Value_IsNull(argTwo.get())) { 925 if (FXJSE_Value_IsNull(argTwo.get())) {
926 FXJSE_Value_SetNull(args.GetReturnValue()); 926 FXJSE_Value_SetNull(args.GetReturnValue());
927 return; 927 return;
928 } 928 }
929 929
930 bool dPrecisionRet; 930 bool dPrecisionRet;
931 FX_DOUBLE dPrecision = ExtractDouble(pThis, argTwo.get(), &dPrecisionRet); 931 FX_DOUBLE dPrecision = ExtractDouble(pThis, argTwo.get(), &dPrecisionRet);
932 if (!dPrecisionRet) { 932 if (!dPrecisionRet) {
933 pContext->ThrowException(XFA_IDS_ARGUMENT_MISMATCH); 933 pContext->ThrowException(XFA_IDS_ARGUMENT_MISMATCH);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 CFX_ByteString bufferCurrent = bufferYear + bufferMon + bufferDay; 1050 CFX_ByteString bufferCurrent = bufferYear + bufferMon + bufferDay;
1051 FXJSE_Value_SetInteger(args.GetReturnValue(), 1051 FXJSE_Value_SetInteger(args.GetReturnValue(),
1052 DateString2Num(bufferCurrent.AsStringC())); 1052 DateString2Num(bufferCurrent.AsStringC()));
1053 } 1053 }
1054 1054
1055 // static 1055 // static
1056 void CXFA_FM2JSContext::Date2Num(CFXJSE_Value* pThis, 1056 void CXFA_FM2JSContext::Date2Num(CFXJSE_Value* pThis,
1057 const CFX_ByteStringC& szFuncName, 1057 const CFX_ByteStringC& szFuncName,
1058 CFXJSE_Arguments& args) { 1058 CFXJSE_Arguments& args) {
1059 int32_t argc = args.GetLength(); 1059 int32_t argc = args.GetLength();
1060 if (argc <= 0 || argc >= 4) { 1060 if (argc < 1 || argc > 3) {
1061 ToJSContext(pThis, nullptr) 1061 ToJSContext(pThis, nullptr)
1062 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Date2Num"); 1062 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Date2Num");
1063 return; 1063 return;
1064 } 1064 }
1065 1065
1066 std::unique_ptr<CFXJSE_Value> dateValue = GetSimpleValue(pThis, args, 0); 1066 std::unique_ptr<CFXJSE_Value> dateValue = GetSimpleValue(pThis, args, 0);
1067 if (ValueIsNull(pThis, dateValue.get())) { 1067 if (ValueIsNull(pThis, dateValue.get())) {
1068 FXJSE_Value_SetNull(args.GetReturnValue()); 1068 FXJSE_Value_SetNull(args.GetReturnValue());
1069 return; 1069 return;
1070 } 1070 }
1071 1071
1072 CFX_ByteString dateString; 1072 CFX_ByteString dateString;
1073 ValueToUTF8String(dateValue.get(), dateString); 1073 ValueToUTF8String(dateValue.get(), dateString);
1074 1074
1075 CFX_ByteString formatString; 1075 CFX_ByteString formatString;
1076 if (argc > 1) { 1076 if (argc > 1) {
1077 std::unique_ptr<CFXJSE_Value> formatValue = GetSimpleValue(pThis, args, 1); 1077 std::unique_ptr<CFXJSE_Value> formatValue = GetSimpleValue(pThis, args, 1);
1078 if (ValueIsNull(pThis, formatValue.get())) { 1078 if (ValueIsNull(pThis, formatValue.get())) {
1079 FXJSE_Value_SetNull(args.GetReturnValue()); 1079 FXJSE_Value_SetNull(args.GetReturnValue());
1080 return; 1080 return;
1081 } 1081 }
1082 ValueToUTF8String(formatValue.get(), formatString); 1082 ValueToUTF8String(formatValue.get(), formatString);
1083 } 1083 }
1084 1084
1085 CFX_ByteString localString; 1085 CFX_ByteString localString;
1086 if (argc == 3) { 1086 if (argc > 2) {
1087 std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2); 1087 std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2);
1088 if (ValueIsNull(pThis, localValue.get())) { 1088 if (ValueIsNull(pThis, localValue.get())) {
1089 FXJSE_Value_SetNull(args.GetReturnValue()); 1089 FXJSE_Value_SetNull(args.GetReturnValue());
1090 return; 1090 return;
1091 } 1091 }
1092 ValueToUTF8String(localValue.get(), localString); 1092 ValueToUTF8String(localValue.get(), localString);
1093 } 1093 }
1094 1094
1095 CFX_ByteString szIsoDateString; 1095 CFX_ByteString szIsoDateString;
1096 if (!Local2IsoDate(pThis, dateString.AsStringC(), formatString.AsStringC(), 1096 if (!Local2IsoDate(pThis, dateString.AsStringC(), formatString.AsStringC(),
1097 localString.AsStringC(), szIsoDateString)) { 1097 localString.AsStringC(), szIsoDateString)) {
1098 FXJSE_Value_SetInteger(args.GetReturnValue(), 0); 1098 FXJSE_Value_SetInteger(args.GetReturnValue(), 0);
1099 return; 1099 return;
1100 } 1100 }
1101 1101
1102 FXJSE_Value_SetInteger(args.GetReturnValue(), 1102 FXJSE_Value_SetInteger(args.GetReturnValue(),
1103 DateString2Num(szIsoDateString.AsStringC())); 1103 DateString2Num(szIsoDateString.AsStringC()));
1104 } 1104 }
1105 1105
1106 // static 1106 // static
1107 void CXFA_FM2JSContext::DateFmt(CFXJSE_Value* pThis, 1107 void CXFA_FM2JSContext::DateFmt(CFXJSE_Value* pThis,
1108 const CFX_ByteStringC& szFuncName, 1108 const CFX_ByteStringC& szFuncName,
1109 CFXJSE_Arguments& args) { 1109 CFXJSE_Arguments& args) {
1110 int32_t argc = args.GetLength(); 1110 int32_t argc = args.GetLength();
1111 if (argc >= 3) { 1111 if (argc > 2) {
1112 ToJSContext(pThis, nullptr) 1112 ToJSContext(pThis, nullptr)
1113 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Date2Num"); 1113 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Date2Num");
1114 return; 1114 return;
1115 } 1115 }
1116 1116
1117 int32_t iStyle = 0; 1117 int32_t iStyle = 0;
1118 if (argc > 0) { 1118 if (argc > 0) {
1119 std::unique_ptr<CFXJSE_Value> argStyle = GetSimpleValue(pThis, args, 0); 1119 std::unique_ptr<CFXJSE_Value> argStyle = GetSimpleValue(pThis, args, 0);
1120 if (FXJSE_Value_IsNull(argStyle.get())) { 1120 if (FXJSE_Value_IsNull(argStyle.get())) {
1121 FXJSE_Value_SetNull(args.GetReturnValue()); 1121 FXJSE_Value_SetNull(args.GetReturnValue());
1122 return; 1122 return;
1123 } 1123 }
1124 1124
1125 iStyle = (int32_t)ValueToFloat(pThis, argStyle.get()); 1125 iStyle = (int32_t)ValueToFloat(pThis, argStyle.get());
1126 if (iStyle < 0 || iStyle > 4) 1126 if (iStyle < 0 || iStyle > 4)
1127 iStyle = 0; 1127 iStyle = 0;
1128 } 1128 }
1129 1129
1130 CFX_ByteString szLocal; 1130 CFX_ByteString szLocal;
1131 if (argc == 2) { 1131 if (argc > 1) {
1132 std::unique_ptr<CFXJSE_Value> argLocal = GetSimpleValue(pThis, args, 1); 1132 std::unique_ptr<CFXJSE_Value> argLocal = GetSimpleValue(pThis, args, 1);
1133 if (FXJSE_Value_IsNull(argLocal.get())) { 1133 if (FXJSE_Value_IsNull(argLocal.get())) {
1134 FXJSE_Value_SetNull(args.GetReturnValue()); 1134 FXJSE_Value_SetNull(args.GetReturnValue());
1135 return; 1135 return;
1136 } 1136 }
1137 ValueToUTF8String(argLocal.get(), szLocal); 1137 ValueToUTF8String(argLocal.get(), szLocal);
1138 } 1138 }
1139 1139
1140 CFX_ByteString formatStr; 1140 CFX_ByteString formatStr;
1141 GetStandardDateFormat(pThis, iStyle, szLocal.AsStringC(), formatStr); 1141 GetStandardDateFormat(pThis, iStyle, szLocal.AsStringC(), formatStr);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1221 int32_t iResult = 1221 int32_t iResult =
1222 hour * 3600000 + min * 60000 + second * 1000 + milSecond + 1; 1222 hour * 3600000 + min * 60000 + second * 1000 + milSecond + 1;
1223 FXJSE_Value_SetInteger(args.GetReturnValue(), iResult); 1223 FXJSE_Value_SetInteger(args.GetReturnValue(), iResult);
1224 } 1224 }
1225 1225
1226 // static 1226 // static
1227 void CXFA_FM2JSContext::LocalDateFmt(CFXJSE_Value* pThis, 1227 void CXFA_FM2JSContext::LocalDateFmt(CFXJSE_Value* pThis,
1228 const CFX_ByteStringC& szFuncName, 1228 const CFX_ByteStringC& szFuncName,
1229 CFXJSE_Arguments& args) { 1229 CFXJSE_Arguments& args) {
1230 int32_t argc = args.GetLength(); 1230 int32_t argc = args.GetLength();
1231 if (argc < 3) { 1231 if (argc > 2) {
1232 FX_BOOL bFlags = FALSE;
1233 int32_t iStyle = 0;
1234 CFX_ByteString szLocal;
1235 if (argc > 0) {
1236 std::unique_ptr<CFXJSE_Value> argStyle = GetSimpleValue(pThis, args, 0);
1237 if (FXJSE_Value_IsNull(argStyle.get())) {
1238 bFlags = TRUE;
1239 }
1240 iStyle = (int32_t)ValueToFloat(pThis, argStyle.get());
1241 if (iStyle > 4 || iStyle < 0) {
1242 iStyle = 0;
1243 }
1244 }
1245 if (argc == 2) {
1246 std::unique_ptr<CFXJSE_Value> argLocal = GetSimpleValue(pThis, args, 1);
1247 if (FXJSE_Value_IsNull(argLocal.get())) {
1248 bFlags = TRUE;
1249 } else {
1250 ValueToUTF8String(argLocal.get(), szLocal);
1251 }
1252 }
1253 if (!bFlags) {
1254 CFX_ByteString formatStr;
1255 GetLocalDateFormat(pThis, iStyle, szLocal.AsStringC(), formatStr, FALSE);
1256 if (formatStr.IsEmpty()) {
1257 formatStr = "";
1258 }
1259 FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr.AsStringC());
1260 } else {
1261 FXJSE_Value_SetNull(args.GetReturnValue());
1262 }
1263 } else {
1264 ToJSContext(pThis, nullptr) 1232 ToJSContext(pThis, nullptr)
1265 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"LocalDateFmt"); 1233 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"LocalDateFmt");
1234 return;
1266 } 1235 }
1236
1237 int32_t iStyle = 0;
1238 if (argc > 0) {
1239 std::unique_ptr<CFXJSE_Value> argStyle = GetSimpleValue(pThis, args, 0);
1240 if (FXJSE_Value_IsNull(argStyle.get())) {
1241 FXJSE_Value_SetNull(args.GetReturnValue());
1242 return;
1243 }
1244 iStyle = (int32_t)ValueToFloat(pThis, argStyle.get());
1245 if (iStyle > 4 || iStyle < 0)
1246 iStyle = 0;
1247 }
1248
1249 CFX_ByteString szLocal;
1250 if (argc > 1) {
1251 std::unique_ptr<CFXJSE_Value> argLocal = GetSimpleValue(pThis, args, 1);
1252 if (FXJSE_Value_IsNull(argLocal.get())) {
1253 FXJSE_Value_SetNull(args.GetReturnValue());
1254 return;
1255 }
1256 ValueToUTF8String(argLocal.get(), szLocal);
1257 }
1258
1259 CFX_ByteString formatStr;
1260 GetLocalDateFormat(pThis, iStyle, szLocal.AsStringC(), formatStr, FALSE);
1261 FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr.AsStringC());
1267 } 1262 }
1268 1263
1269 // static 1264 // static
1270 void CXFA_FM2JSContext::LocalTimeFmt(CFXJSE_Value* pThis, 1265 void CXFA_FM2JSContext::LocalTimeFmt(CFXJSE_Value* pThis,
1271 const CFX_ByteStringC& szFuncName, 1266 const CFX_ByteStringC& szFuncName,
1272 CFXJSE_Arguments& args) { 1267 CFXJSE_Arguments& args) {
1273 int32_t argc = args.GetLength(); 1268 int32_t argc = args.GetLength();
1274 if (argc < 3) { 1269 if (argc > 2) {
1275 FX_BOOL bFlags = FALSE;
1276 int32_t iStyle = 0;
1277 CFX_ByteString szLocal;
1278 if (argc > 0) {
1279 std::unique_ptr<CFXJSE_Value> argStyle = GetSimpleValue(pThis, args, 0);
1280 if (FXJSE_Value_IsNull(argStyle.get())) {
1281 bFlags = TRUE;
1282 }
1283 iStyle = (int32_t)ValueToFloat(pThis, argStyle.get());
1284 if (iStyle > 4 || iStyle < 0) {
1285 iStyle = 0;
1286 }
1287 }
1288 if (argc == 2) {
1289 std::unique_ptr<CFXJSE_Value> argLocal = GetSimpleValue(pThis, args, 1);
1290 if (FXJSE_Value_IsNull(argLocal.get())) {
1291 bFlags = TRUE;
1292 } else {
1293 ValueToUTF8String(argLocal.get(), szLocal);
1294 }
1295 }
1296 if (!bFlags) {
1297 CFX_ByteString formatStr;
1298 GetLocalTimeFormat(pThis, iStyle, szLocal.AsStringC(), formatStr, FALSE);
1299 if (formatStr.IsEmpty()) {
1300 formatStr = "";
1301 }
1302 FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr.AsStringC());
1303 } else {
1304 FXJSE_Value_SetNull(args.GetReturnValue());
1305 }
1306 } else {
1307 ToJSContext(pThis, nullptr) 1270 ToJSContext(pThis, nullptr)
1308 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"LocalTimeFmt"); 1271 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"LocalTimeFmt");
1272 return;
1309 } 1273 }
1274
1275 int32_t iStyle = 0;
1276 if (argc > 0) {
1277 std::unique_ptr<CFXJSE_Value> argStyle = GetSimpleValue(pThis, args, 0);
1278 if (FXJSE_Value_IsNull(argStyle.get())) {
1279 FXJSE_Value_SetNull(args.GetReturnValue());
1280 return;
1281 }
1282 iStyle = (int32_t)ValueToFloat(pThis, argStyle.get());
1283 if (iStyle > 4 || iStyle < 0)
1284 iStyle = 0;
1285 }
1286
1287 CFX_ByteString szLocal;
1288 if (argc > 1) {
1289 std::unique_ptr<CFXJSE_Value> argLocal = GetSimpleValue(pThis, args, 1);
1290 if (FXJSE_Value_IsNull(argLocal.get())) {
1291 FXJSE_Value_SetNull(args.GetReturnValue());
1292 return;
1293 }
1294 ValueToUTF8String(argLocal.get(), szLocal);
1295 }
1296
1297 CFX_ByteString formatStr;
1298 GetLocalTimeFormat(pThis, iStyle, szLocal.AsStringC(), formatStr, FALSE);
1299 FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr.AsStringC());
1310 } 1300 }
1311 1301
1312 // static 1302 // static
1313 void CXFA_FM2JSContext::Num2Date(CFXJSE_Value* pThis, 1303 void CXFA_FM2JSContext::Num2Date(CFXJSE_Value* pThis,
1314 const CFX_ByteStringC& szFuncName, 1304 const CFX_ByteStringC& szFuncName,
1315 CFXJSE_Arguments& args) { 1305 CFXJSE_Arguments& args) {
1316 int32_t argc = args.GetLength(); 1306 int32_t argc = args.GetLength();
1317 if ((argc > 0) && (argc < 4)) { 1307 if (argc < 1 || argc > 3) {
1318 FX_BOOL bFlags = FALSE; 1308 ToJSContext(pThis, nullptr)
1319 int32_t dDate = 0; 1309 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Num2Date");
1320 CFX_ByteString formatString; 1310 return;
1321 CFX_ByteString localString; 1311 }
1322 std::unique_ptr<CFXJSE_Value> dateValue = GetSimpleValue(pThis, args, 0); 1312
1323 if (ValueIsNull(pThis, dateValue.get())) { 1313 std::unique_ptr<CFXJSE_Value> dateValue = GetSimpleValue(pThis, args, 0);
1324 bFlags = TRUE; 1314 if (ValueIsNull(pThis, dateValue.get())) {
1315 FXJSE_Value_SetNull(args.GetReturnValue());
1316 return;
1317 }
1318 int32_t dDate = (int32_t)ValueToFloat(pThis, dateValue.get());
1319 if (dDate < 1) {
1320 FXJSE_Value_SetNull(args.GetReturnValue());
1321 return;
1322 }
1323
1324 CFX_ByteString formatString;
1325 if (argc > 1) {
1326 std::unique_ptr<CFXJSE_Value> formatValue = GetSimpleValue(pThis, args, 1);
1327 if (ValueIsNull(pThis, formatValue.get())) {
1328 FXJSE_Value_SetNull(args.GetReturnValue());
1329 return;
1330 }
1331 ValueToUTF8String(formatValue.get(), formatString);
1332 }
1333
1334 CFX_ByteString localString;
1335 if (argc > 2) {
1336 std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2);
1337 if (ValueIsNull(pThis, localValue.get())) {
1338 FXJSE_Value_SetNull(args.GetReturnValue());
1339 return;
1340 }
1341 ValueToUTF8String(localValue.get(), localString);
1342 }
1343
1344 int32_t iYear = 1900;
1345 int32_t iMonth = 1;
1346 int32_t iDay = 1;
1347 int32_t i = 0;
1348 while (dDate > 0) {
1349 if (iMonth == 2) {
1350 if ((!((iYear + i) % 4) && ((iYear + i) % 100)) || !((iYear + i) % 400)) {
1351 if (dDate > 29) {
1352 ++iMonth;
1353 if (iMonth > 12) {
1354 iMonth = 1;
1355 ++i;
1356 }
1357 iDay = 1;
1358 dDate -= 29;
1359 } else {
1360 iDay += static_cast<int32_t>(dDate) - 1;
1361 dDate = 0;
1362 }
1363 } else {
1364 if (dDate > 28) {
1365 ++iMonth;
1366 if (iMonth > 12) {
1367 iMonth = 1;
1368 ++i;
1369 }
1370 iDay = 1;
1371 dDate -= 28;
1372 } else {
1373 iDay += static_cast<int32_t>(dDate) - 1;
1374 dDate = 0;
1375 }
1376 }
1377 } else if (iMonth < 8) {
1378 if ((iMonth % 2 == 0)) {
1379 if (dDate > 30) {
1380 ++iMonth;
1381 if (iMonth > 12) {
1382 iMonth = 1;
1383 ++i;
1384 }
1385 iDay = 1;
1386 dDate -= 30;
1387 } else {
1388 iDay += static_cast<int32_t>(dDate) - 1;
1389 dDate = 0;
1390 }
1391 } else {
1392 if (dDate > 31) {
1393 ++iMonth;
1394 if (iMonth > 12) {
1395 iMonth = 1;
1396 ++i;
1397 }
1398 iDay = 1;
1399 dDate -= 31;
1400 } else {
1401 iDay += static_cast<int32_t>(dDate) - 1;
1402 dDate = 0;
1403 }
1404 }
1325 } else { 1405 } else {
1326 dDate = (int32_t)ValueToFloat(pThis, dateValue.get()); 1406 if (iMonth % 2 != 0) {
1327 bFlags = dDate < 1; 1407 if (dDate > 30) {
1328 } 1408 ++iMonth;
1329 if (argc > 1) { 1409 if (iMonth > 12) {
1330 std::unique_ptr<CFXJSE_Value> formatValue = 1410 iMonth = 1;
1331 GetSimpleValue(pThis, args, 1); 1411 ++i;
1332 if (ValueIsNull(pThis, formatValue.get())) { 1412 }
1333 bFlags = TRUE; 1413 iDay = 1;
1414 dDate -= 30;
1415 } else {
1416 iDay += static_cast<int32_t>(dDate) - 1;
1417 dDate = 0;
1418 }
1334 } else { 1419 } else {
1335 ValueToUTF8String(formatValue.get(), formatString); 1420 if (dDate > 31) {
1421 ++iMonth;
1422 if (iMonth > 12) {
1423 iMonth = 1;
1424 ++i;
1425 }
1426 iDay = 1;
1427 dDate -= 31;
1428 } else {
1429 iDay += static_cast<int32_t>(dDate) - 1;
1430 dDate = 0;
1431 }
1336 } 1432 }
1337 } 1433 }
1338 if (argc == 3) {
1339 std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2);
1340 if (ValueIsNull(pThis, localValue.get())) {
1341 bFlags = TRUE;
1342 } else {
1343 ValueToUTF8String(localValue.get(), localString);
1344 }
1345 }
1346 if (!bFlags) {
1347 int32_t iYear = 1900;
1348 int32_t iMonth = 1;
1349 int32_t iDay = 1;
1350 int32_t i = 0;
1351 while (dDate > 0) {
1352 if (iMonth == 2) {
1353 if ((!((iYear + i) % 4) && ((iYear + i) % 100)) ||
1354 !((iYear + i) % 400)) {
1355 if (dDate > 29) {
1356 ++iMonth;
1357 if (iMonth > 12) {
1358 iMonth = 1;
1359 ++i;
1360 }
1361 iDay = 1;
1362 dDate -= 29;
1363 } else {
1364 iDay += static_cast<int32_t>(dDate) - 1;
1365 dDate = 0;
1366 }
1367 } else {
1368 if (dDate > 28) {
1369 ++iMonth;
1370 if (iMonth > 12) {
1371 iMonth = 1;
1372 ++i;
1373 }
1374 iDay = 1;
1375 dDate -= 28;
1376 } else {
1377 iDay += static_cast<int32_t>(dDate) - 1;
1378 dDate = 0;
1379 }
1380 }
1381 } else if (iMonth < 8) {
1382 if ((iMonth % 2 == 0)) {
1383 if (dDate > 30) {
1384 ++iMonth;
1385 if (iMonth > 12) {
1386 iMonth = 1;
1387 ++i;
1388 }
1389 iDay = 1;
1390 dDate -= 30;
1391 } else {
1392 iDay += static_cast<int32_t>(dDate) - 1;
1393 dDate = 0;
1394 }
1395 } else {
1396 if (dDate > 31) {
1397 ++iMonth;
1398 if (iMonth > 12) {
1399 iMonth = 1;
1400 ++i;
1401 }
1402 iDay = 1;
1403 dDate -= 31;
1404 } else {
1405 iDay += static_cast<int32_t>(dDate) - 1;
1406 dDate = 0;
1407 }
1408 }
1409 } else {
1410 if (iMonth % 2 != 0) {
1411 if (dDate > 30) {
1412 ++iMonth;
1413 if (iMonth > 12) {
1414 iMonth = 1;
1415 ++i;
1416 }
1417 iDay = 1;
1418 dDate -= 30;
1419 } else {
1420 iDay += static_cast<int32_t>(dDate) - 1;
1421 dDate = 0;
1422 }
1423 } else {
1424 if (dDate > 31) {
1425 ++iMonth;
1426 if (iMonth > 12) {
1427 iMonth = 1;
1428 ++i;
1429 }
1430 iDay = 1;
1431 dDate -= 31;
1432 } else {
1433 iDay += static_cast<int32_t>(dDate) - 1;
1434 dDate = 0;
1435 }
1436 }
1437 }
1438 }
1439 CFX_ByteString szIsoDateString;
1440 szIsoDateString.Format("%d%02d%02d", iYear + i, iMonth, iDay);
1441 CFX_ByteString szLocalDateString;
1442 IsoDate2Local(pThis, szIsoDateString.AsStringC(),
1443 formatString.AsStringC(), localString.AsStringC(),
1444 szLocalDateString);
1445 if (szLocalDateString.IsEmpty()) {
1446 szLocalDateString = "";
1447 }
1448 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
1449 szLocalDateString.AsStringC());
1450 } else {
1451 FXJSE_Value_SetNull(args.GetReturnValue());
1452 }
1453 } else {
1454 ToJSContext(pThis, nullptr)
1455 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Num2Date");
1456 } 1434 }
1435
1436 CFX_ByteString szIsoDateString;
1437 szIsoDateString.Format("%d%02d%02d", iYear + i, iMonth, iDay);
1438 CFX_ByteString szLocalDateString;
1439 IsoDate2Local(pThis, szIsoDateString.AsStringC(), formatString.AsStringC(),
1440 localString.AsStringC(), szLocalDateString);
1441 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
1442 szLocalDateString.AsStringC());
1457 } 1443 }
1458 1444
1459 // static 1445 // static
1460 void CXFA_FM2JSContext::Num2GMTime(CFXJSE_Value* pThis, 1446 void CXFA_FM2JSContext::Num2GMTime(CFXJSE_Value* pThis,
1461 const CFX_ByteStringC& szFuncName, 1447 const CFX_ByteStringC& szFuncName,
1462 CFXJSE_Arguments& args) { 1448 CFXJSE_Arguments& args) {
1463 int32_t argc = args.GetLength(); 1449 int32_t argc = args.GetLength();
1464 if ((argc > 0) && (argc < 4)) { 1450 if (argc < 1 || argc > 3) {
1465 FX_BOOL bFlags = FALSE;
1466 int32_t iTime = 0;
1467 CFX_ByteString formatString;
1468 CFX_ByteString localString;
1469 std::unique_ptr<CFXJSE_Value> timeValue = GetSimpleValue(pThis, args, 0);
1470 if (FXJSE_Value_IsNull(timeValue.get())) {
1471 bFlags = TRUE;
1472 } else {
1473 iTime = (int32_t)ValueToFloat(pThis, timeValue.get());
1474 if (FXSYS_abs(iTime) < 1.0) {
1475 bFlags = TRUE;
1476 }
1477 }
1478 if (argc > 1) {
1479 std::unique_ptr<CFXJSE_Value> formatValue =
1480 GetSimpleValue(pThis, args, 1);
1481 if (FXJSE_Value_IsNull(formatValue.get())) {
1482 bFlags = TRUE;
1483 } else {
1484 ValueToUTF8String(formatValue.get(), formatString);
1485 }
1486 }
1487 if (argc == 3) {
1488 std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2);
1489 if (FXJSE_Value_IsNull(localValue.get())) {
1490 bFlags = TRUE;
1491 } else {
1492 ValueToUTF8String(localValue.get(), localString);
1493 }
1494 }
1495 if (!bFlags) {
1496 CFX_ByteString szGMTTimeString;
1497 Num2AllTime(pThis, iTime, formatString.AsStringC(),
1498 localString.AsStringC(), TRUE, szGMTTimeString);
1499 if (szGMTTimeString.IsEmpty()) {
1500 szGMTTimeString = "";
1501 }
1502 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
1503 szGMTTimeString.AsStringC());
1504 } else {
1505 FXJSE_Value_SetNull(args.GetReturnValue());
1506 }
1507 } else {
1508 ToJSContext(pThis, nullptr) 1451 ToJSContext(pThis, nullptr)
1509 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Num2GMTime"); 1452 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Num2GMTime");
1453 return;
1510 } 1454 }
1455
1456 std::unique_ptr<CFXJSE_Value> timeValue = GetSimpleValue(pThis, args, 0);
1457 if (FXJSE_Value_IsNull(timeValue.get())) {
1458 FXJSE_Value_SetNull(args.GetReturnValue());
1459 return;
1460 }
1461 int32_t iTime = (int32_t)ValueToFloat(pThis, timeValue.get());
1462 if (FXSYS_abs(iTime) < 1.0) {
1463 FXJSE_Value_SetNull(args.GetReturnValue());
1464 return;
1465 }
1466
1467 CFX_ByteString formatString;
1468 if (argc > 1) {
1469 std::unique_ptr<CFXJSE_Value> formatValue = GetSimpleValue(pThis, args, 1);
1470 if (FXJSE_Value_IsNull(formatValue.get())) {
1471 FXJSE_Value_SetNull(args.GetReturnValue());
1472 return;
1473 }
1474 ValueToUTF8String(formatValue.get(), formatString);
1475 }
1476
1477 CFX_ByteString localString;
1478 if (argc > 2) {
1479 std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2);
1480 if (FXJSE_Value_IsNull(localValue.get())) {
1481 FXJSE_Value_SetNull(args.GetReturnValue());
1482 return;
1483 }
1484 ValueToUTF8String(localValue.get(), localString);
1485 }
1486
1487 CFX_ByteString szGMTTimeString;
1488 Num2AllTime(pThis, iTime, formatString.AsStringC(), localString.AsStringC(),
1489 TRUE, szGMTTimeString);
1490 FXJSE_Value_SetUTF8String(args.GetReturnValue(), szGMTTimeString.AsStringC());
1511 } 1491 }
1512 1492
1513 // static 1493 // static
1514 void CXFA_FM2JSContext::Num2Time(CFXJSE_Value* pThis, 1494 void CXFA_FM2JSContext::Num2Time(CFXJSE_Value* pThis,
1515 const CFX_ByteStringC& szFuncName, 1495 const CFX_ByteStringC& szFuncName,
1516 CFXJSE_Arguments& args) { 1496 CFXJSE_Arguments& args) {
1517 int32_t argc = args.GetLength(); 1497 int32_t argc = args.GetLength();
1518 if ((argc > 0) && (argc < 4)) { 1498 if (argc < 1 || argc > 3) {
1519 FX_BOOL bFlags = FALSE;
1520 FX_FLOAT fTime = 0.0f;
1521 CFX_ByteString formatString;
1522 CFX_ByteString localString;
1523 std::unique_ptr<CFXJSE_Value> timeValue = GetSimpleValue(pThis, args, 0);
1524 if (FXJSE_Value_IsNull(timeValue.get())) {
1525 bFlags = TRUE;
1526 } else {
1527 fTime = ValueToFloat(pThis, timeValue.get());
1528 if (FXSYS_fabs(fTime) < 1.0) {
1529 bFlags = TRUE;
1530 }
1531 }
1532 if (argc > 1) {
1533 std::unique_ptr<CFXJSE_Value> formatValue =
1534 GetSimpleValue(pThis, args, 1);
1535 if (FXJSE_Value_IsNull(formatValue.get())) {
1536 bFlags = TRUE;
1537 } else {
1538 ValueToUTF8String(formatValue.get(), formatString);
1539 }
1540 }
1541 if (argc == 3) {
1542 std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2);
1543 if (FXJSE_Value_IsNull(localValue.get())) {
1544 bFlags = TRUE;
1545 } else {
1546 ValueToUTF8String(localValue.get(), localString);
1547 }
1548 }
1549 if (!bFlags) {
1550 CFX_ByteString szLocalTimeString;
1551 Num2AllTime(pThis, (int32_t)fTime, formatString.AsStringC(),
1552 localString.AsStringC(), FALSE, szLocalTimeString);
1553 if (szLocalTimeString.IsEmpty()) {
1554 szLocalTimeString = "";
1555 }
1556 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
1557 szLocalTimeString.AsStringC());
1558 } else {
1559 FXJSE_Value_SetNull(args.GetReturnValue());
1560 }
1561 } else {
1562 ToJSContext(pThis, nullptr) 1499 ToJSContext(pThis, nullptr)
1563 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Num2Time"); 1500 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Num2Time");
1501 return;
1564 } 1502 }
1503
1504 std::unique_ptr<CFXJSE_Value> timeValue = GetSimpleValue(pThis, args, 0);
1505 if (FXJSE_Value_IsNull(timeValue.get())) {
1506 FXJSE_Value_SetNull(args.GetReturnValue());
1507 return;
1508 }
1509 FX_FLOAT fTime = ValueToFloat(pThis, timeValue.get());
1510 if (FXSYS_fabs(fTime) < 1.0) {
1511 FXJSE_Value_SetNull(args.GetReturnValue());
1512 return;
1513 }
1514
1515 CFX_ByteString formatString;
1516 if (argc > 1) {
1517 std::unique_ptr<CFXJSE_Value> formatValue = GetSimpleValue(pThis, args, 1);
1518 if (FXJSE_Value_IsNull(formatValue.get())) {
1519 FXJSE_Value_SetNull(args.GetReturnValue());
1520 return;
1521 }
1522 ValueToUTF8String(formatValue.get(), formatString);
1523 }
1524
1525 CFX_ByteString localString;
1526 if (argc > 2) {
1527 std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2);
1528 if (FXJSE_Value_IsNull(localValue.get())) {
1529 FXJSE_Value_SetNull(args.GetReturnValue());
1530 return;
1531 }
1532 ValueToUTF8String(localValue.get(), localString);
1533 }
1534
1535 CFX_ByteString szLocalTimeString;
1536 Num2AllTime(pThis, (int32_t)fTime, formatString.AsStringC(),
1537 localString.AsStringC(), FALSE, szLocalTimeString);
1538 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
1539 szLocalTimeString.AsStringC());
1565 } 1540 }
1566 1541
1567 // static 1542 // static
1568 void CXFA_FM2JSContext::Time(CFXJSE_Value* pThis, 1543 void CXFA_FM2JSContext::Time(CFXJSE_Value* pThis,
1569 const CFX_ByteStringC& szFuncName, 1544 const CFX_ByteStringC& szFuncName,
1570 CFXJSE_Arguments& args) { 1545 CFXJSE_Arguments& args) {
1571 if (args.GetLength() == 0) { 1546 if (args.GetLength() != 0) {
1572 time_t now;
1573 time(&now);
1574 struct tm* pGmt = gmtime(&now);
1575 int32_t iGMHour = pGmt->tm_hour;
1576 int32_t iGMMin = pGmt->tm_min;
1577 int32_t iGMSec = pGmt->tm_sec;
1578 FXJSE_Value_SetInteger(args.GetReturnValue(),
1579 ((iGMHour * 3600 + iGMMin * 60 + iGMSec) * 1000));
1580 } else {
1581 ToJSContext(pThis, nullptr) 1547 ToJSContext(pThis, nullptr)
1582 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Time"); 1548 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Time");
1549 return;
1583 } 1550 }
1551
1552 time_t now;
1553 time(&now);
1554
1555 struct tm* pGmt = gmtime(&now);
1556 FXJSE_Value_SetInteger(
1557 args.GetReturnValue(),
1558 ((pGmt->tm_hour * 3600 + pGmt->tm_min * 60 + pGmt->tm_sec) * 1000));
1584 } 1559 }
1585 1560
1586 // static 1561 // static
1587 void CXFA_FM2JSContext::Time2Num(CFXJSE_Value* pThis, 1562 void CXFA_FM2JSContext::Time2Num(CFXJSE_Value* pThis,
1588 const CFX_ByteStringC& szFuncName, 1563 const CFX_ByteStringC& szFuncName,
1589 CFXJSE_Arguments& args) { 1564 CFXJSE_Arguments& args) {
1590 int32_t argc = args.GetLength(); 1565 int32_t argc = args.GetLength();
1591 if ((argc > 0) && (argc < 4)) { 1566 if (argc < 1 || argc > 3) {
1592 FX_BOOL bFlags = FALSE;
1593 CFX_ByteString timeString;
1594 CFX_ByteString formatString;
1595 CFX_ByteString localString;
1596 std::unique_ptr<CFXJSE_Value> timeValue = GetSimpleValue(pThis, args, 0);
1597 if (ValueIsNull(pThis, timeValue.get())) {
1598 bFlags = TRUE;
1599 } else {
1600 ValueToUTF8String(timeValue.get(), timeString);
1601 }
1602 if (argc > 1) {
1603 std::unique_ptr<CFXJSE_Value> formatValue =
1604 GetSimpleValue(pThis, args, 1);
1605 if (ValueIsNull(pThis, formatValue.get())) {
1606 bFlags = TRUE;
1607 } else {
1608 ValueToUTF8String(formatValue.get(), formatString);
1609 }
1610 }
1611 if (argc == 3) {
1612 std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2);
1613 if (ValueIsNull(pThis, localValue.get())) {
1614 bFlags = TRUE;
1615 } else {
1616 ValueToUTF8String(localValue.get(), localString);
1617 }
1618 }
1619 if (!bFlags) {
1620 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument();
1621 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr();
1622 IFX_Locale* pLocale = nullptr;
1623 if (localString.IsEmpty()) {
1624 CXFA_Node* pThisNode =
1625 ToNode(pDoc->GetScriptContext()->GetThisObject());
1626 ASSERT(pThisNode);
1627 CXFA_WidgetData widgetData(pThisNode);
1628 pLocale = widgetData.GetLocal();
1629 } else {
1630 pLocale = pMgr->GetLocaleByName(
1631 CFX_WideString::FromUTF8(localString.AsStringC()));
1632 }
1633 CFX_WideString wsFormat;
1634 if (formatString.IsEmpty()) {
1635 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat);
1636 } else {
1637 wsFormat = CFX_WideString::FromUTF8(formatString.AsStringC());
1638 }
1639 wsFormat = FX_WSTRC(L"time{") + wsFormat;
1640 wsFormat += FX_WSTRC(L"}");
1641 CXFA_LocaleValue localeValue(
1642 XFA_VT_TIME, CFX_WideString::FromUTF8(timeString.AsStringC()),
1643 wsFormat, pLocale, (CXFA_LocaleMgr*)pMgr);
1644 if (localeValue.IsValid()) {
1645 CFX_Unitime uniTime = localeValue.GetTime();
1646 int32_t hour = uniTime.GetHour();
1647 int32_t min = uniTime.GetMinute();
1648 int32_t second = uniTime.GetSecond();
1649 int32_t milSecond = uniTime.GetMillisecond();
1650 int32_t mins = hour * 60 + min;
1651 CXFA_TimeZoneProvider* pProvider = CXFA_TimeZoneProvider::Get();
1652 if (pProvider) {
1653 FX_TIMEZONE tz;
1654 pProvider->GetTimeZone(tz);
1655 mins -= (tz.tzHour * 60);
1656 while (mins > 1440) {
1657 mins -= 1440;
1658 }
1659 while (mins < 0) {
1660 mins += 1440;
1661 }
1662 hour = mins / 60;
1663 min = mins % 60;
1664 }
1665 int32_t iResult =
1666 hour * 3600000 + min * 60000 + second * 1000 + milSecond + 1;
1667 FXJSE_Value_SetInteger(args.GetReturnValue(), iResult);
1668 } else {
1669 FXJSE_Value_SetInteger(args.GetReturnValue(), 0);
1670 }
1671 } else {
1672 FXJSE_Value_SetNull(args.GetReturnValue());
1673 }
1674 } else {
1675 ToJSContext(pThis, nullptr) 1567 ToJSContext(pThis, nullptr)
1676 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Time2Num"); 1568 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Time2Num");
1569 return;
1677 } 1570 }
1571
1572 CFX_ByteString timeString;
1573 std::unique_ptr<CFXJSE_Value> timeValue = GetSimpleValue(pThis, args, 0);
1574 if (ValueIsNull(pThis, timeValue.get())) {
1575 FXJSE_Value_SetNull(args.GetReturnValue());
1576 return;
1577 }
1578 ValueToUTF8String(timeValue.get(), timeString);
1579
1580 CFX_ByteString formatString;
1581 if (argc > 1) {
1582 std::unique_ptr<CFXJSE_Value> formatValue = GetSimpleValue(pThis, args, 1);
1583 if (ValueIsNull(pThis, formatValue.get())) {
1584 FXJSE_Value_SetNull(args.GetReturnValue());
1585 return;
1586 }
1587 ValueToUTF8String(formatValue.get(), formatString);
1588 }
1589
1590 CFX_ByteString localString;
1591 if (argc > 2) {
1592 std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2);
1593 if (ValueIsNull(pThis, localValue.get())) {
1594 FXJSE_Value_SetNull(args.GetReturnValue());
1595 return;
1596 }
1597 ValueToUTF8String(localValue.get(), localString);
1598 }
1599
1600 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument();
1601 CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr();
1602 IFX_Locale* pLocale = nullptr;
1603 if (localString.IsEmpty()) {
1604 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
1605 ASSERT(pThisNode);
1606
1607 CXFA_WidgetData widgetData(pThisNode);
1608 pLocale = widgetData.GetLocal();
1609 } else {
1610 pLocale = pMgr->GetLocaleByName(
1611 CFX_WideString::FromUTF8(localString.AsStringC()));
1612 }
1613
1614 CFX_WideString wsFormat;
1615 if (formatString.IsEmpty())
1616 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat);
1617 else
1618 wsFormat = CFX_WideString::FromUTF8(formatString.AsStringC());
1619
1620 wsFormat = FX_WSTRC(L"time{") + wsFormat;
1621 wsFormat += FX_WSTRC(L"}");
1622 CXFA_LocaleValue localeValue(XFA_VT_TIME,
1623 CFX_WideString::FromUTF8(timeString.AsStringC()),
1624 wsFormat, pLocale, pMgr);
1625 if (!localeValue.IsValid()) {
1626 FXJSE_Value_SetInteger(args.GetReturnValue(), 0);
1627 return;
1628 }
1629
1630 CFX_Unitime uniTime = localeValue.GetTime();
1631 int32_t hour = uniTime.GetHour();
1632 int32_t min = uniTime.GetMinute();
1633 int32_t second = uniTime.GetSecond();
1634 int32_t milSecond = uniTime.GetMillisecond();
1635 int32_t mins = hour * 60 + min;
1636 CXFA_TimeZoneProvider* pProvider = CXFA_TimeZoneProvider::Get();
1637 if (pProvider) {
1638 FX_TIMEZONE tz;
1639 pProvider->GetTimeZone(tz);
1640 mins -= (tz.tzHour * 60);
1641 while (mins > 1440)
1642 mins -= 1440;
1643 while (mins < 0)
1644 mins += 1440;
1645
1646 hour = mins / 60;
1647 min = mins % 60;
1648 }
1649 FXJSE_Value_SetInteger(
1650 args.GetReturnValue(),
1651 hour * 3600000 + min * 60000 + second * 1000 + milSecond + 1);
1678 } 1652 }
1679 1653
1680 // static 1654 // static
1681 void CXFA_FM2JSContext::TimeFmt(CFXJSE_Value* pThis, 1655 void CXFA_FM2JSContext::TimeFmt(CFXJSE_Value* pThis,
1682 const CFX_ByteStringC& szFuncName, 1656 const CFX_ByteStringC& szFuncName,
1683 CFXJSE_Arguments& args) { 1657 CFXJSE_Arguments& args) {
1684 int32_t argc = args.GetLength(); 1658 int32_t argc = args.GetLength();
1685 if (argc < 3) { 1659 if (argc > 2) {
1686 FX_BOOL bFlags = FALSE;
1687 int32_t iStyle = 0;
1688 CFX_ByteString szLocal;
1689 if (argc > 0) {
1690 std::unique_ptr<CFXJSE_Value> argStyle = GetSimpleValue(pThis, args, 0);
1691 if (FXJSE_Value_IsNull(argStyle.get())) {
1692 bFlags = TRUE;
1693 }
1694 iStyle = (int32_t)ValueToFloat(pThis, argStyle.get());
1695 if (iStyle > 4 || iStyle < 0) {
1696 iStyle = 0;
1697 }
1698 }
1699 if (argc == 2) {
1700 std::unique_ptr<CFXJSE_Value> argLocal = GetSimpleValue(pThis, args, 1);
1701 if (FXJSE_Value_IsNull(argLocal.get())) {
1702 bFlags = TRUE;
1703 } else {
1704 ValueToUTF8String(argLocal.get(), szLocal);
1705 }
1706 }
1707 if (!bFlags) {
1708 CFX_ByteString formatStr;
1709 GetStandardTimeFormat(pThis, iStyle, szLocal.AsStringC(), formatStr);
1710 if (formatStr.IsEmpty()) {
1711 formatStr = "";
1712 }
1713 FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr.AsStringC());
1714 } else {
1715 FXJSE_Value_SetNull(args.GetReturnValue());
1716 }
1717 } else {
1718 ToJSContext(pThis, nullptr) 1660 ToJSContext(pThis, nullptr)
1719 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"TimeFmt"); 1661 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"TimeFmt");
1662 return;
1720 } 1663 }
1664
1665 int32_t iStyle = 0;
1666 if (argc > 0) {
1667 std::unique_ptr<CFXJSE_Value> argStyle = GetSimpleValue(pThis, args, 0);
1668 if (FXJSE_Value_IsNull(argStyle.get())) {
1669 FXJSE_Value_SetNull(args.GetReturnValue());
1670 return;
1671 }
1672 iStyle = (int32_t)ValueToFloat(pThis, argStyle.get());
1673 if (iStyle > 4 || iStyle < 0)
1674 iStyle = 0;
1675 }
1676
1677 CFX_ByteString szLocal;
1678 if (argc > 1) {
1679 std::unique_ptr<CFXJSE_Value> argLocal = GetSimpleValue(pThis, args, 1);
1680 if (FXJSE_Value_IsNull(argLocal.get())) {
1681 FXJSE_Value_SetNull(args.GetReturnValue());
1682 return;
1683 }
1684 ValueToUTF8String(argLocal.get(), szLocal);
1685 }
1686
1687 CFX_ByteString formatStr;
1688 GetStandardTimeFormat(pThis, iStyle, szLocal.AsStringC(), formatStr);
1689 FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr.AsStringC());
1721 } 1690 }
1722 1691
1723 // static 1692 // static
1724 FX_BOOL CXFA_FM2JSContext::IsIsoDateFormat(const FX_CHAR* pData, 1693 FX_BOOL CXFA_FM2JSContext::IsIsoDateFormat(const FX_CHAR* pData,
1725 int32_t iLength, 1694 int32_t iLength,
1726 int32_t& iStyle, 1695 int32_t& iStyle,
1727 int32_t& iYear, 1696 int32_t& iYear,
1728 int32_t& iMonth, 1697 int32_t& iMonth,
1729 int32_t& iDay) { 1698 int32_t& iDay) {
1730 iYear = 0; 1699 iYear = 0;
1731 iMonth = 1; 1700 iMonth = 1;
1732 iDay = 1; 1701 iDay = 1;
1733 FX_BOOL iRet = FALSE; 1702
1734 if (iLength < 4) { 1703 if (iLength < 4)
1735 return iRet; 1704 return FALSE;
1736 } 1705
1737 FX_CHAR strYear[5]; 1706 FX_CHAR strYear[5];
1738 strYear[4] = '\0'; 1707 strYear[4] = '\0';
1739 for (int32_t i = 0; i < 4; ++i) { 1708 for (int32_t i = 0; i < 4; ++i) {
1740 if (*(pData + i) <= '9' && *(pData + i) >= '0') { 1709 if (pData[i] > '9' || pData[i] < '0')
1741 strYear[i] = *(pData + i); 1710 return FALSE;
1742 } else { 1711
1743 return iRet; 1712 strYear[i] = pData[i];
1744 }
1745 } 1713 }
1746 iYear = FXSYS_atoi(strYear); 1714 iYear = FXSYS_atoi(strYear);
1747 iStyle = 0; 1715 iStyle = 0;
1748 if (iLength > 4) { 1716 if (iLength == 4)
1749 if (*(pData + 4) == '-') { 1717 return TRUE;
1750 iStyle = 1; 1718
1751 } else { 1719 iStyle = pData[4] == '-' ? 1 : 0;
1752 iStyle = 0; 1720
1753 }
1754 } else {
1755 iRet = TRUE;
1756 return iRet;
1757 }
1758 FX_CHAR strTemp[3]; 1721 FX_CHAR strTemp[3];
1759 strTemp[2] = '\0'; 1722 strTemp[2] = '\0';
1760 int32_t iPosOff = 0; 1723 int32_t iPosOff = iStyle == 0 ? 4 : 5;
1724 if ((pData[iPosOff] > '9' || pData[iPosOff] < '0') ||
1725 (pData[iPosOff + 1] > '9' || pData[iPosOff + 1] < '0'))
1726 return FALSE;
1727
1728 strTemp[0] = pData[iPosOff];
1729 strTemp[1] = pData[iPosOff + 1];
1730 iMonth = FXSYS_atoi(strTemp);
1731 if (iMonth > 12 || iMonth < 1)
1732 return FALSE;
1733
1761 if (iStyle == 0) { 1734 if (iStyle == 0) {
1762 iPosOff = 4; 1735 iPosOff += 2;
1763 if (iLength == 4) { 1736 if (iLength == 6)
1764 iRet = TRUE; 1737 return TRUE;
1765 return iRet;
1766 }
1767 } else { 1738 } else {
1768 iPosOff = 5; 1739 iPosOff += 3;
1769 if (iLength == 4) { 1740 if (iLength == 7)
1770 iRet = TRUE; 1741 return TRUE;
1771 return iRet; 1742 }
1743 if ((pData[iPosOff] > '9' || pData[iPosOff] < '0') ||
1744 (pData[iPosOff + 1] > '9' || pData[iPosOff + 1] < '0'))
1745 return FALSE;
1746
1747 strTemp[0] = pData[iPosOff];
1748 strTemp[1] = pData[iPosOff + 1];
1749 iDay = FXSYS_atoi(strTemp);
1750 if (iPosOff + 2 < iLength)
1751 return FALSE;
1752
1753 if ((!(iYear % 4) && (iYear % 100)) || !(iYear % 400)) {
1754 if (iMonth == 2 && iDay > 29)
1755 return FALSE;
1756 } else {
1757 if (iMonth == 2 && iDay > 28)
1758 return FALSE;
1759 }
1760 if (iMonth != 2) {
1761 if (iMonth < 8) {
1762 if (iDay > (iMonth % 2 == 0 ? 30 : 31))
1763 return FALSE;
1764 } else if (iDay > (iMonth % 2 == 0 ? 31 : 30)) {
1765 return FALSE;
1772 } 1766 }
1773 } 1767 }
1774 if ((*(pData + iPosOff) > '9' || *(pData + iPosOff) < '0') || 1768 return TRUE;
1775 (*(pData + iPosOff + 1) > '9' || *(pData + iPosOff + 1) < '0')) {
1776 return iRet;
1777 }
1778 strTemp[0] = *(pData + iPosOff);
1779 strTemp[1] = *(pData + iPosOff + 1);
1780 iMonth = FXSYS_atoi(strTemp);
1781 if (iMonth > 12 || iMonth < 1) {
1782 return iRet;
1783 }
1784 if (iStyle == 0) {
1785 iPosOff += 2;
1786 if (iLength == 6) {
1787 iRet = 1;
1788 return iRet;
1789 }
1790 } else {
1791 iPosOff += 3;
1792 if (iLength == 7) {
1793 iRet = 1;
1794 return iRet;
1795 }
1796 }
1797 if ((*(pData + iPosOff) > '9' || *(pData + iPosOff) < '0') ||
1798 (*(pData + iPosOff + 1) > '9' || *(pData + iPosOff + 1) < '0')) {
1799 return iRet;
1800 }
1801 strTemp[0] = *(pData + iPosOff);
1802 strTemp[1] = *(pData + iPosOff + 1);
1803 iDay = FXSYS_atoi(strTemp);
1804 if (iPosOff + 2 < iLength) {
1805 return iRet;
1806 }
1807 if ((!(iYear % 4) && (iYear % 100)) || !(iYear % 400)) {
1808 if (iMonth == 2) {
1809 if (iDay > 29) {
1810 return iRet;
1811 }
1812 } else {
1813 if (iMonth < 8) {
1814 if (iDay > (iMonth % 2 == 0 ? 30 : 31)) {
1815 return iRet;
1816 }
1817 } else {
1818 if (iDay > (iMonth % 2 == 0 ? 31 : 30)) {
1819 return iRet;
1820 }
1821 }
1822 }
1823 } else {
1824 if (iMonth == 2) {
1825 if (iDay > 28) {
1826 return iRet;
1827 }
1828 } else {
1829 if (iMonth < 8) {
1830 if (iDay > (iMonth % 2 == 0 ? 30 : 31)) {
1831 return iRet;
1832 }
1833 } else {
1834 if (iDay > (iMonth % 2 == 0 ? 31 : 30)) {
1835 return iRet;
1836 }
1837 }
1838 }
1839 }
1840 iRet = TRUE;
1841 return iRet;
1842 } 1769 }
1843 1770
1844 // static 1771 // static
1845 FX_BOOL CXFA_FM2JSContext::IsIsoTimeFormat(const FX_CHAR* pData, 1772 FX_BOOL CXFA_FM2JSContext::IsIsoTimeFormat(const FX_CHAR* pData,
1846 int32_t iLength, 1773 int32_t iLength,
1847 int32_t& iHour, 1774 int32_t& iHour,
1848 int32_t& iMinute, 1775 int32_t& iMinute,
1849 int32_t& iSecond, 1776 int32_t& iSecond,
1850 int32_t& iMilliSecond, 1777 int32_t& iMilliSecond,
1851 int32_t& iZoneHour, 1778 int32_t& iZoneHour,
1852 int32_t& iZoneMinute) { 1779 int32_t& iZoneMinute) {
1853 iHour = 0; 1780 iHour = 0;
1854 iMinute = 0; 1781 iMinute = 0;
1855 iSecond = 0; 1782 iSecond = 0;
1856 iMilliSecond = 0; 1783 iMilliSecond = 0;
1857 iZoneHour = 0; 1784 iZoneHour = 0;
1858 iZoneMinute = 0; 1785 iZoneMinute = 0;
1859 if (!pData) { 1786 if (!pData)
1860 return FALSE; 1787 return FALSE;
1861 } 1788
1862 int32_t iRet = FALSE;
1863 FX_CHAR strTemp[3]; 1789 FX_CHAR strTemp[3];
1864 strTemp[2] = '\0'; 1790 strTemp[2] = '\0';
1865 int32_t iIndex = 0;
1866 int32_t iZone = 0; 1791 int32_t iZone = 0;
1867 int32_t i = iIndex; 1792 int32_t i = 0;
1868 while (i < iLength) { 1793 while (i < iLength) {
1869 if ((*(pData + i) > '9' || *(pData + i) < '0') && *(pData + i) != ':') { 1794 if ((pData[i] > '9' || pData[i] < '0') && pData[i] != ':') {
1870 iZone = i; 1795 iZone = i;
1871 break; 1796 break;
1872 } 1797 }
1873 ++i; 1798 ++i;
1874 } 1799 }
1875 if (i == iLength) { 1800 if (i == iLength)
1876 iZone = iLength; 1801 iZone = iLength;
1877 } 1802
1878 int32_t iPos = 0; 1803 int32_t iPos = 0;
1804 int32_t iIndex = 0;
1879 while (iIndex < iZone) { 1805 while (iIndex < iZone) {
1880 if (iIndex >= iZone) { 1806 if (iIndex >= iZone)
1881 break; 1807 break;
1882 } 1808
1883 if (*(pData + iIndex) > '9' || *(pData + iIndex) < '0') { 1809 if (pData[iIndex] > '9' || pData[iIndex] < '0')
1884 return iRet; 1810 return FALSE;
1885 } 1811
1886 strTemp[0] = *(pData + iIndex); 1812 strTemp[0] = pData[iIndex];
1887 if (*(pData + iIndex + 1) > '9' || *(pData + iIndex + 1) < '0') { 1813 if (pData[iIndex + 1] > '9' || pData[iIndex + 1] < '0')
1888 return iRet; 1814 return FALSE;
1889 } 1815
1890 strTemp[1] = *(pData + iIndex + 1); 1816 strTemp[1] = pData[iIndex + 1];
1891 if (FXSYS_atoi(strTemp) > 60) { 1817 if (FXSYS_atoi(strTemp) > 60)
1892 return iRet; 1818 return FALSE;
1893 } 1819
1894 if (*(pData + 2) == ':') { 1820 if (pData[2] == ':') {
1895 if (iPos == 0) { 1821 if (iPos == 0) {
1896 iHour = FXSYS_atoi(strTemp); 1822 iHour = FXSYS_atoi(strTemp);
1897 ++iPos; 1823 ++iPos;
1898 } else if (iPos == 1) { 1824 } else if (iPos == 1) {
1899 iMinute = FXSYS_atoi(strTemp); 1825 iMinute = FXSYS_atoi(strTemp);
1900 ++iPos; 1826 ++iPos;
1901 } else { 1827 } else {
1902 iSecond = FXSYS_atoi(strTemp); 1828 iSecond = FXSYS_atoi(strTemp);
1903 } 1829 }
1904 iIndex += 3; 1830 iIndex += 3;
1905 } else { 1831 } else {
1906 if (iPos == 0) { 1832 if (iPos == 0) {
1907 iHour = FXSYS_atoi(strTemp); 1833 iHour = FXSYS_atoi(strTemp);
1908 ++iPos; 1834 ++iPos;
1909 } else if (iPos == 1) { 1835 } else if (iPos == 1) {
1910 iMinute = FXSYS_atoi(strTemp); 1836 iMinute = FXSYS_atoi(strTemp);
1911 ++iPos; 1837 ++iPos;
1912 } else if (iPos == 2) { 1838 } else if (iPos == 2) {
1913 iSecond = FXSYS_atoi(strTemp); 1839 iSecond = FXSYS_atoi(strTemp);
1914 ++iPos; 1840 ++iPos;
1915 } 1841 }
1916 iIndex += 2; 1842 iIndex += 2;
1917 } 1843 }
1918 } 1844 }
1919 if (*(pData + iIndex) == '.') { 1845 if (pData[iIndex] == '.') {
1920 ++iIndex; 1846 ++iIndex;
1921 FX_CHAR strSec[4]; 1847 FX_CHAR strSec[4];
1922 strSec[3] = '\0'; 1848 strSec[3] = '\0';
1923 if (*(pData + iIndex) > '9' || *(pData + iIndex) < '0') { 1849 if (pData[iIndex] > '9' || pData[iIndex] < '0')
1924 return iRet; 1850 return FALSE;
1925 } 1851
1926 strSec[0] = *(pData + iIndex); 1852 strSec[0] = pData[iIndex];
1927 if (*(pData + iIndex + 1) > '9' || *(pData + iIndex + 1) < '0') { 1853 if (pData[iIndex + 1] > '9' || pData[iIndex + 1] < '0')
1928 return iRet; 1854 return FALSE;
1929 } 1855
1930 strSec[1] = *(pData + iIndex + 1); 1856 strSec[1] = pData[iIndex + 1];
1931 if (*(pData + iIndex + 2) > '9' || *(pData + iIndex + 2) < '0') { 1857 if (pData[iIndex + 2] > '9' || pData[iIndex + 2] < '0')
1932 return iRet; 1858 return FALSE;
1933 } 1859
1934 strSec[2] = *(pData + iIndex + 2); 1860 strSec[2] = pData[iIndex + 2];
1935 iMilliSecond = FXSYS_atoi(strSec); 1861 iMilliSecond = FXSYS_atoi(strSec);
1936 if (iMilliSecond > 100) { 1862 if (iMilliSecond > 100) {
1937 iMilliSecond = 0; 1863 iMilliSecond = 0;
1938 return iRet; 1864 return FALSE;
1939 } 1865 }
1940 iIndex += 3; 1866 iIndex += 3;
1941 } 1867 }
1868 if (pData[iIndex] == 'z' || pData[iIndex] == 'Z')
1869 return TRUE;
1870
1942 int32_t iSign = 1; 1871 int32_t iSign = 1;
1943 if (*(pData + iIndex) == 'z' || *(pData + iIndex) == 'Z') { 1872 if (pData[iIndex] == '+') {
1944 iRet = 1;
1945 return iRet;
1946 } else if (*(pData + iIndex) == '+') {
1947 ++iIndex; 1873 ++iIndex;
1948 } else if (*(pData + iIndex) == '-') { 1874 } else if (pData[iIndex] == '-') {
1949 iSign = -1; 1875 iSign = -1;
1950 ++iIndex; 1876 ++iIndex;
1951 } 1877 }
1952 iPos = 0; 1878 iPos = 0;
1953 while (iIndex < iLength) { 1879 while (iIndex < iLength) {
1954 if (iIndex >= iLength) { 1880 if (iIndex >= iLength)
1955 return iRet; 1881 return FALSE;
1956 } 1882 if (pData[iIndex] > '9' || pData[iIndex] < '0')
1957 if (*(pData + iIndex) > '9' || *(pData + iIndex) < '0') { 1883 return FALSE;
1958 return iRet; 1884
1959 } 1885 strTemp[0] = pData[iIndex];
1960 strTemp[0] = *(pData + iIndex); 1886 if (pData[iIndex + 1] > '9' || pData[iIndex + 1] < '0')
1961 if (*(pData + iIndex + 1) > '9' || *(pData + iIndex + 1) < '0') { 1887 return FALSE;
1962 return iRet; 1888
1963 } 1889 strTemp[1] = pData[iIndex + 1];
1964 strTemp[1] = *(pData + iIndex + 1); 1890 if (FXSYS_atoi(strTemp) > 60)
1965 if (FXSYS_atoi(strTemp) > 60) { 1891 return FALSE;
1966 return iRet; 1892
1967 } 1893 if (pData[2] == ':') {
1968 if (*(pData + 2) == ':') {
1969 if (iPos == 0) { 1894 if (iPos == 0) {
1970 iZoneHour = FXSYS_atoi(strTemp); 1895 iZoneHour = FXSYS_atoi(strTemp);
1971 } else if (iPos == 1) { 1896 } else if (iPos == 1) {
1972 iZoneMinute = FXSYS_atoi(strTemp); 1897 iZoneMinute = FXSYS_atoi(strTemp);
1973 } 1898 }
1974 iIndex += 3; 1899 iIndex += 3;
1975 } else { 1900 } else {
1976 if (!iPos) { 1901 if (!iPos) {
1977 iZoneHour = FXSYS_atoi(strTemp); 1902 iZoneHour = FXSYS_atoi(strTemp);
1978 ++iPos; 1903 ++iPos;
1979 } else if (iPos == 1) { 1904 } else if (iPos == 1) {
1980 iZoneMinute = FXSYS_atoi(strTemp); 1905 iZoneMinute = FXSYS_atoi(strTemp);
1981 ++iPos; 1906 ++iPos;
1982 } 1907 }
1983 iIndex += 2; 1908 iIndex += 2;
1984 } 1909 }
1985 } 1910 }
1986 if (iIndex < iLength) { 1911 if (iIndex < iLength)
1987 return iRet; 1912 return FALSE;
1988 } 1913
1989 iZoneHour *= iSign; 1914 iZoneHour *= iSign;
1990 iRet = TRUE; 1915 return TRUE;
1991 return iRet;
1992 } 1916 }
1993 1917
1994 // static 1918 // static
1995 FX_BOOL CXFA_FM2JSContext::IsIsoDateTimeFormat(const FX_CHAR* pData, 1919 FX_BOOL CXFA_FM2JSContext::IsIsoDateTimeFormat(const FX_CHAR* pData,
1996 int32_t iLength, 1920 int32_t iLength,
1997 int32_t& iYear, 1921 int32_t& iYear,
1998 int32_t& iMonth, 1922 int32_t& iMonth,
1999 int32_t& iDay, 1923 int32_t& iDay,
2000 int32_t& iHour, 1924 int32_t& iHour,
2001 int32_t& iMinute, 1925 int32_t& iMinute,
2002 int32_t& iSecond, 1926 int32_t& iSecond,
2003 int32_t& iMillionSecond, 1927 int32_t& iMillionSecond,
2004 int32_t& iZoneHour, 1928 int32_t& iZoneHour,
2005 int32_t& iZoneMinute) { 1929 int32_t& iZoneMinute) {
2006 iYear = 0; 1930 iYear = 0;
2007 iMonth = 0; 1931 iMonth = 0;
2008 iDay = 0; 1932 iDay = 0;
2009 iHour = 0; 1933 iHour = 0;
2010 iMinute = 0; 1934 iMinute = 0;
2011 iSecond = 0; 1935 iSecond = 0;
2012 if (!pData) { 1936 if (!pData)
2013 return FALSE; 1937 return FALSE;
2014 } 1938
2015 int32_t iRet = FALSE;
2016 int32_t iIndex = 0; 1939 int32_t iIndex = 0;
2017 while (*(pData + iIndex) != 'T' && *(pData + iIndex) != 't') { 1940 while (pData[iIndex] != 'T' && pData[iIndex] != 't') {
2018 if (iIndex >= iLength) { 1941 if (iIndex >= iLength)
2019 return iRet; 1942 return FALSE;
2020 }
2021 ++iIndex; 1943 ++iIndex;
2022 } 1944 }
2023 if (iIndex != 8 && iIndex != 10) { 1945 if (iIndex != 8 && iIndex != 10)
2024 return iRet; 1946 return FALSE;
2025 } 1947
2026 int32_t iStyle = -1; 1948 int32_t iStyle = -1;
2027 iRet = IsIsoDateFormat(pData, iIndex, iStyle, iYear, iMonth, iDay); 1949 if (!IsIsoDateFormat(pData, iIndex, iStyle, iYear, iMonth, iDay))
2028 if (!iRet) { 1950 return FALSE;
2029 return iRet; 1951 if (pData[iIndex] != 'T' && pData[iIndex] != 't')
2030 } 1952 return TRUE;
2031 if (*(pData + iIndex) != 'T' && *(pData + iIndex) != 't') { 1953
2032 return iRet;
2033 }
2034 ++iIndex; 1954 ++iIndex;
2035 if (((iLength - iIndex > 13) && (iLength - iIndex < 6)) && 1955 if (((iLength - iIndex > 13) && (iLength - iIndex < 6)) &&
2036 (iLength - iIndex != 15)) { 1956 (iLength - iIndex != 15)) {
2037 return iRet; 1957 return TRUE;
2038 } 1958 }
2039 iRet = IsIsoTimeFormat(pData + iIndex, iLength - iIndex, iHour, iMinute, 1959 if (!IsIsoTimeFormat(pData + iIndex, iLength - iIndex, iHour, iMinute,
2040 iSecond, iMillionSecond, iZoneHour, iZoneMinute); 1960 iSecond, iMillionSecond, iZoneHour, iZoneMinute)) {
2041 if (!iRet) { 1961 return FALSE;
2042 return iRet;
2043 } 1962 }
2044 iRet = TRUE; 1963
2045 return iRet; 1964 return TRUE;
2046 } 1965 }
2047 1966
2048 // static 1967 // static
2049 FX_BOOL CXFA_FM2JSContext::Local2IsoDate(CFXJSE_Value* pThis, 1968 FX_BOOL CXFA_FM2JSContext::Local2IsoDate(CFXJSE_Value* pThis,
2050 const CFX_ByteStringC& szDate, 1969 const CFX_ByteStringC& szDate,
2051 const CFX_ByteStringC& szFormat, 1970 const CFX_ByteStringC& szFormat,
2052 const CFX_ByteStringC& szLocale, 1971 const CFX_ByteStringC& szLocale,
2053 CFX_ByteString& strIsoDate) { 1972 CFX_ByteString& strIsoDate) {
2054 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); 1973 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument();
2055 if (!pDoc) { 1974 if (!pDoc)
2056 return FALSE; 1975 return FALSE;
2057 } 1976
2058 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr(); 1977 CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr();
2059 IFX_Locale* pLocale = nullptr; 1978 IFX_Locale* pLocale = nullptr;
2060 if (szLocale.IsEmpty()) { 1979 if (szLocale.IsEmpty()) {
2061 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); 1980 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2062 ASSERT(pThisNode); 1981 ASSERT(pThisNode);
1982
2063 CXFA_WidgetData widgetData(pThisNode); 1983 CXFA_WidgetData widgetData(pThisNode);
2064 pLocale = widgetData.GetLocal(); 1984 pLocale = widgetData.GetLocal();
2065 } else { 1985 } else {
2066 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); 1986 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale));
2067 } 1987 }
2068 if (!pLocale) { 1988 if (!pLocale)
2069 return FALSE; 1989 return FALSE;
2070 } 1990
2071 CFX_WideString wsFormat; 1991 CFX_WideString wsFormat;
2072 if (szFormat.IsEmpty()) { 1992 if (szFormat.IsEmpty())
2073 pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); 1993 pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat);
2074 } else { 1994 else
2075 wsFormat = CFX_WideString::FromUTF8(szFormat); 1995 wsFormat = CFX_WideString::FromUTF8(szFormat);
2076 } 1996
2077 CXFA_LocaleValue widgetValue(XFA_VT_DATE, CFX_WideString::FromUTF8(szDate), 1997 CXFA_LocaleValue widgetValue(XFA_VT_DATE, CFX_WideString::FromUTF8(szDate),
2078 wsFormat, pLocale, (CXFA_LocaleMgr*)pMgr); 1998 wsFormat, pLocale, pMgr);
2079 CFX_Unitime dt = widgetValue.GetDate(); 1999 CFX_Unitime dt = widgetValue.GetDate();
2080 strIsoDate.Format("%4d-%02d-%02d", dt.GetYear(), dt.GetMonth(), dt.GetDay()); 2000 strIsoDate.Format("%4d-%02d-%02d", dt.GetYear(), dt.GetMonth(), dt.GetDay());
2081 return TRUE; 2001 return TRUE;
2082 } 2002 }
2083 2003
2084 // static 2004 // static
2085 FX_BOOL CXFA_FM2JSContext::Local2IsoTime(CFXJSE_Value* pThis, 2005 FX_BOOL CXFA_FM2JSContext::Local2IsoTime(CFXJSE_Value* pThis,
2086 const CFX_ByteStringC& szTime, 2006 const CFX_ByteStringC& szTime,
2087 const CFX_ByteStringC& szFormat, 2007 const CFX_ByteStringC& szFormat,
2088 const CFX_ByteStringC& szLocale, 2008 const CFX_ByteStringC& szLocale,
2089 CFX_ByteString& strIsoTime) { 2009 CFX_ByteString& strIsoTime) {
2090 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); 2010 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument();
2091 if (!pDoc) { 2011 if (!pDoc)
2092 return FALSE; 2012 return FALSE;
2093 } 2013
2094 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr(); 2014 CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr();
2095 IFX_Locale* pLocale = nullptr; 2015 IFX_Locale* pLocale = nullptr;
2096 if (szLocale.IsEmpty()) { 2016 if (szLocale.IsEmpty()) {
2097 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); 2017 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2098 ASSERT(pThisNode); 2018 ASSERT(pThisNode);
2019
2099 CXFA_WidgetData widgetData(pThisNode); 2020 CXFA_WidgetData widgetData(pThisNode);
2100 pLocale = widgetData.GetLocal(); 2021 pLocale = widgetData.GetLocal();
2101 } else { 2022 } else {
2102 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); 2023 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale));
2103 } 2024 }
2104 if (!pLocale) { 2025 if (!pLocale)
2105 return FALSE; 2026 return FALSE;
2106 } 2027
2107 CFX_WideString wsFormat; 2028 CFX_WideString wsFormat;
2108 if (szFormat.IsEmpty()) { 2029 if (szFormat.IsEmpty())
2109 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); 2030 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat);
2110 } else { 2031 else
2111 wsFormat = CFX_WideString::FromUTF8(szFormat); 2032 wsFormat = CFX_WideString::FromUTF8(szFormat);
2112 } 2033
2113 wsFormat = FX_WSTRC(L"time{") + wsFormat; 2034 wsFormat = FX_WSTRC(L"time{") + wsFormat;
2114 wsFormat += FX_WSTRC(L"}"); 2035 wsFormat += FX_WSTRC(L"}");
2115 CXFA_LocaleValue widgetValue(XFA_VT_TIME, CFX_WideString::FromUTF8(szTime), 2036 CXFA_LocaleValue widgetValue(XFA_VT_TIME, CFX_WideString::FromUTF8(szTime),
2116 wsFormat, pLocale, (CXFA_LocaleMgr*)pMgr); 2037 wsFormat, pLocale, pMgr);
2117 CFX_Unitime utime = widgetValue.GetTime(); 2038 CFX_Unitime utime = widgetValue.GetTime();
2118 strIsoTime.Format("%02d:%02d:%02d.%03d", utime.GetHour(), utime.GetMinute(), 2039 strIsoTime.Format("%02d:%02d:%02d.%03d", utime.GetHour(), utime.GetMinute(),
2119 utime.GetSecond(), utime.GetMillisecond()); 2040 utime.GetSecond(), utime.GetMillisecond());
2120 return TRUE; 2041 return TRUE;
2121 } 2042 }
2122 2043
2123 // static 2044 // static
2124 FX_BOOL CXFA_FM2JSContext::IsoDate2Local(CFXJSE_Value* pThis, 2045 FX_BOOL CXFA_FM2JSContext::IsoDate2Local(CFXJSE_Value* pThis,
2125 const CFX_ByteStringC& szDate, 2046 const CFX_ByteStringC& szDate,
2126 const CFX_ByteStringC& szFormat, 2047 const CFX_ByteStringC& szFormat,
2127 const CFX_ByteStringC& szLocale, 2048 const CFX_ByteStringC& szLocale,
2128 CFX_ByteString& strLocalDate) { 2049 CFX_ByteString& strLocalDate) {
2129 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); 2050 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument();
2130 if (!pDoc) { 2051 if (!pDoc)
2131 return FALSE; 2052 return FALSE;
2132 } 2053
2133 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr(); 2054 CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr();
2134 IFX_Locale* pLocale = nullptr; 2055 IFX_Locale* pLocale = nullptr;
2135 if (szLocale.IsEmpty()) { 2056 if (szLocale.IsEmpty()) {
2136 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); 2057 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2137 ASSERT(pThisNode); 2058 ASSERT(pThisNode);
2138 CXFA_WidgetData widgetData(pThisNode); 2059 CXFA_WidgetData widgetData(pThisNode);
2139 pLocale = widgetData.GetLocal(); 2060 pLocale = widgetData.GetLocal();
2140 } else { 2061 } else {
2141 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); 2062 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale));
2142 } 2063 }
2143 if (!pLocale) { 2064 if (!pLocale)
2144 return FALSE; 2065 return FALSE;
2145 } 2066
2146 CFX_WideString wsFormat; 2067 CFX_WideString wsFormat;
2147 if (szFormat.IsEmpty()) { 2068 if (szFormat.IsEmpty())
2148 pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); 2069 pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat);
2149 } else { 2070 else
2150 wsFormat = CFX_WideString::FromUTF8(szFormat); 2071 wsFormat = CFX_WideString::FromUTF8(szFormat);
2151 } 2072
2152 CXFA_LocaleValue widgetValue(XFA_VT_DATE, CFX_WideString::FromUTF8(szDate), 2073 CXFA_LocaleValue widgetValue(XFA_VT_DATE, CFX_WideString::FromUTF8(szDate),
2153 (CXFA_LocaleMgr*)pMgr); 2074 pMgr);
2154 CFX_WideString wsRet; 2075 CFX_WideString wsRet;
2155 widgetValue.FormatPatterns(wsRet, wsFormat, pLocale, 2076 widgetValue.FormatPatterns(wsRet, wsFormat, pLocale,
2156 XFA_VALUEPICTURE_Display); 2077 XFA_VALUEPICTURE_Display);
2157 strLocalDate = FX_UTF8Encode(wsRet.c_str(), wsRet.GetLength()); 2078 strLocalDate = FX_UTF8Encode(wsRet.c_str(), wsRet.GetLength());
2158 return TRUE; 2079 return TRUE;
2159 } 2080 }
2160 2081
2161 // static 2082 // static
2162 FX_BOOL CXFA_FM2JSContext::IsoTime2Local(CFXJSE_Value* pThis, 2083 FX_BOOL CXFA_FM2JSContext::IsoTime2Local(CFXJSE_Value* pThis,
2163 const CFX_ByteStringC& szTime, 2084 const CFX_ByteStringC& szTime,
2164 const CFX_ByteStringC& szFormat, 2085 const CFX_ByteStringC& szFormat,
2165 const CFX_ByteStringC& szLocale, 2086 const CFX_ByteStringC& szLocale,
2166 CFX_ByteString& strLocalTime) { 2087 CFX_ByteString& strLocalTime) {
2167 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); 2088 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument();
2168 if (!pDoc) { 2089 if (!pDoc)
2169 return FALSE; 2090 return FALSE;
2170 } 2091
2171 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr(); 2092 CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr();
2172 IFX_Locale* pLocale = nullptr; 2093 IFX_Locale* pLocale = nullptr;
2173 if (szLocale.IsEmpty()) { 2094 if (szLocale.IsEmpty()) {
2174 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); 2095 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2175 ASSERT(pThisNode); 2096 ASSERT(pThisNode);
2176 CXFA_WidgetData widgetData(pThisNode); 2097 CXFA_WidgetData widgetData(pThisNode);
2177 pLocale = widgetData.GetLocal(); 2098 pLocale = widgetData.GetLocal();
2178 } else { 2099 } else {
2179 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); 2100 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale));
2180 } 2101 }
2181 if (!pLocale) { 2102 if (!pLocale)
2182 return FALSE; 2103 return FALSE;
2183 } 2104
2184 CFX_WideString wsFormat; 2105 CFX_WideString wsFormat;
2185 if (szFormat.IsEmpty()) { 2106 if (szFormat.IsEmpty())
2186 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); 2107 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat);
2187 } else { 2108 else
2188 wsFormat = CFX_WideString::FromUTF8(szFormat); 2109 wsFormat = CFX_WideString::FromUTF8(szFormat);
2189 } 2110
2190 wsFormat = FX_WSTRC(L"time{") + wsFormat; 2111 wsFormat = FX_WSTRC(L"time{") + wsFormat;
2191 wsFormat += FX_WSTRC(L"}"); 2112 wsFormat += FX_WSTRC(L"}");
2192 CXFA_LocaleValue widgetValue(XFA_VT_TIME, CFX_WideString::FromUTF8(szTime), 2113 CXFA_LocaleValue widgetValue(XFA_VT_TIME, CFX_WideString::FromUTF8(szTime),
2193 (CXFA_LocaleMgr*)pMgr); 2114 pMgr);
2194 CFX_WideString wsRet; 2115 CFX_WideString wsRet;
2195 widgetValue.FormatPatterns(wsRet, wsFormat, pLocale, 2116 widgetValue.FormatPatterns(wsRet, wsFormat, pLocale,
2196 XFA_VALUEPICTURE_Display); 2117 XFA_VALUEPICTURE_Display);
2197 strLocalTime = FX_UTF8Encode(wsRet.c_str(), wsRet.GetLength()); 2118 strLocalTime = FX_UTF8Encode(wsRet.c_str(), wsRet.GetLength());
2198 return TRUE; 2119 return TRUE;
2199 } 2120 }
2200 2121
2201 // static 2122 // static
2202 FX_BOOL CXFA_FM2JSContext::GetGMTTime(CFXJSE_Value* pThis, 2123 FX_BOOL CXFA_FM2JSContext::GetGMTTime(CFXJSE_Value* pThis,
2203 const CFX_ByteStringC& szTime, 2124 const CFX_ByteStringC& szTime,
2204 const CFX_ByteStringC& szFormat, 2125 const CFX_ByteStringC& szFormat,
2205 const CFX_ByteStringC& szLocale, 2126 const CFX_ByteStringC& szLocale,
2206 CFX_ByteString& strGMTTime) { 2127 CFX_ByteString& strGMTTime) {
2207 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); 2128 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument();
2208 if (!pDoc) { 2129 if (!pDoc)
2209 return FALSE; 2130 return FALSE;
2210 } 2131
2211 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr(); 2132 CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr();
2212 IFX_Locale* pLocale = nullptr; 2133 IFX_Locale* pLocale = nullptr;
2213 if (szLocale.IsEmpty()) { 2134 if (szLocale.IsEmpty()) {
2214 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); 2135 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2215 ASSERT(pThisNode); 2136 ASSERT(pThisNode);
2216 CXFA_WidgetData widgetData(pThisNode); 2137 CXFA_WidgetData widgetData(pThisNode);
2217 pLocale = widgetData.GetLocal(); 2138 pLocale = widgetData.GetLocal();
2218 } else { 2139 } else {
2219 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); 2140 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale));
2220 } 2141 }
2221 if (!pLocale) { 2142 if (!pLocale)
2222 return FALSE; 2143 return FALSE;
2223 } 2144
2224 CFX_WideString wsFormat; 2145 CFX_WideString wsFormat;
2225 if (szFormat.IsEmpty()) { 2146 if (szFormat.IsEmpty())
2226 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); 2147 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat);
2227 } else { 2148 else
2228 wsFormat = CFX_WideString::FromUTF8(szFormat); 2149 wsFormat = CFX_WideString::FromUTF8(szFormat);
2229 } 2150
2230 wsFormat = FX_WSTRC(L"time{") + wsFormat; 2151 wsFormat = FX_WSTRC(L"time{") + wsFormat;
2231 wsFormat += FX_WSTRC(L"}"); 2152 wsFormat += FX_WSTRC(L"}");
2232 CXFA_LocaleValue widgetValue(XFA_VT_TIME, CFX_WideString::FromUTF8(szTime), 2153 CXFA_LocaleValue widgetValue(XFA_VT_TIME, CFX_WideString::FromUTF8(szTime),
2233 (CXFA_LocaleMgr*)pMgr); 2154 pMgr);
2234 CFX_WideString wsRet; 2155 CFX_WideString wsRet;
2235 widgetValue.FormatPatterns(wsRet, wsFormat, pLocale, 2156 widgetValue.FormatPatterns(wsRet, wsFormat, pLocale,
2236 XFA_VALUEPICTURE_Display); 2157 XFA_VALUEPICTURE_Display);
2237 strGMTTime = FX_UTF8Encode(wsRet.c_str(), wsRet.GetLength()); 2158 strGMTTime = FX_UTF8Encode(wsRet.c_str(), wsRet.GetLength());
2238 return TRUE; 2159 return TRUE;
2239 } 2160 }
2240 2161
2241 // static 2162 // static
2242 int32_t CXFA_FM2JSContext::DateString2Num(const CFX_ByteStringC& szDateString) { 2163 int32_t CXFA_FM2JSContext::DateString2Num(const CFX_ByteStringC& szDateString) {
2243 FX_BOOL bFlags = FALSE;
2244 int32_t iLength = szDateString.GetLength(); 2164 int32_t iLength = szDateString.GetLength();
2245 FX_BOOL iRet = FALSE;
2246 int32_t iStyle = -1;
2247 int32_t iYear = 0; 2165 int32_t iYear = 0;
2248 int32_t iMonth = 0; 2166 int32_t iMonth = 0;
2249 int32_t iDay = 0; 2167 int32_t iDay = 0;
2250 int32_t iHour = 0;
2251 int32_t iMinute = 0;
2252 int32_t iSecond = 0;
2253 int32_t iMillionSecond = 0;
2254 int32_t iZoneHour = 0;
2255 int32_t iZoneMinute = 0;
2256 if (iLength <= 10) { 2168 if (iLength <= 10) {
2257 iRet = IsIsoDateFormat(szDateString.c_str(), iLength, iStyle, iYear, iMonth, 2169 int32_t iStyle = -1;
2258 iDay); 2170 if (!IsIsoDateFormat(szDateString.c_str(), iLength, iStyle, iYear, iMonth,
2171 iDay)) {
2172 return 0;
2173 }
2259 } else { 2174 } else {
2260 iRet = IsIsoDateTimeFormat(szDateString.c_str(), iLength, iYear, iMonth, 2175 int32_t iHour = 0;
2261 iDay, iHour, iMinute, iSecond, iMillionSecond, 2176 int32_t iMinute = 0;
2262 iZoneHour, iZoneMinute); 2177 int32_t iSecond = 0;
2178 int32_t iMilliSecond = 0;
2179 int32_t iZoneHour = 0;
2180 int32_t iZoneMinute = 0;
2181 if (!IsIsoDateTimeFormat(szDateString.c_str(), iLength, iYear, iMonth, iDay,
2182 iHour, iMinute, iSecond, iMilliSecond, iZoneHour,
2183 iZoneMinute)) {
2184 return 0;
2185 }
2263 } 2186 }
2264 if (!iRet) { 2187
2265 bFlags = TRUE;
2266 }
2267 FX_FLOAT dDays = 0; 2188 FX_FLOAT dDays = 0;
2268 int32_t i = 1; 2189 int32_t i = 1;
2269 if (iYear < 1900) { 2190 if (iYear < 1900)
2270 bFlags = TRUE; 2191 return 0;
2192
2193 while (iYear - i >= 1900) {
2194 dDays +=
2195 ((!((iYear - i) % 4) && ((iYear - i) % 100)) || !((iYear - i) % 400))
2196 ? 366
2197 : 365;
2198 ++i;
2271 } 2199 }
2272 if (!bFlags) { 2200 i = 1;
2273 while (iYear - i >= 1900) { 2201 while (i < iMonth) {
2274 if ((!((iYear - i) % 4) && ((iYear - i) % 100)) || !((iYear - i) % 400)) { 2202 if (i == 2)
2275 dDays += 366; 2203 dDays += ((!(iYear % 4) && (iYear % 100)) || !(iYear % 400)) ? 29 : 28;
2276 } else { 2204 else if (i <= 7)
2277 dDays += 365; 2205 dDays += (i % 2 == 0) ? 30 : 31;
2278 } 2206 else
2279 ++i; 2207 dDays += (i % 2 == 0) ? 31 : 30;
2280 } 2208
2281 i = 1; 2209 ++i;
2282 while (i < iMonth) { 2210 }
2283 if (i == 2) { 2211 i = 0;
2284 if ((!(iYear % 4) && (iYear % 100)) || !(iYear % 400)) { 2212 while (iDay - i > 0) {
2285 dDays += 29; 2213 dDays += 1;
2286 } else { 2214 ++i;
2287 dDays += 28;
2288 }
2289 } else if (i <= 7) {
2290 if (i % 2 == 0) {
2291 dDays += 30;
2292 } else {
2293 dDays += 31;
2294 }
2295 } else {
2296 if (i % 2 == 0) {
2297 dDays += 31;
2298 } else {
2299 dDays += 30;
2300 }
2301 }
2302 ++i;
2303 }
2304 i = 0;
2305 while (iDay - i > 0) {
2306 dDays += 1;
2307 ++i;
2308 }
2309 } else {
2310 dDays = 0;
2311 } 2215 }
2312 return (int32_t)dDays; 2216 return (int32_t)dDays;
2313 } 2217 }
2314 2218
2315 // static 2219 // static
2316 void CXFA_FM2JSContext::GetLocalDateFormat(CFXJSE_Value* pThis, 2220 void CXFA_FM2JSContext::GetLocalDateFormat(CFXJSE_Value* pThis,
2317 int32_t iStyle, 2221 int32_t iStyle,
2318 const CFX_ByteStringC& szLocalStr, 2222 const CFX_ByteStringC& szLocalStr,
2319 CFX_ByteString& strFormat, 2223 CFX_ByteString& strFormat,
2320 FX_BOOL bStandard) { 2224 FX_BOOL bStandard) {
2321 FX_LOCALEDATETIMESUBCATEGORY strStyle; 2225 FX_LOCALEDATETIMESUBCATEGORY strStyle;
2322 switch (iStyle) { 2226 switch (iStyle) {
2323 case 0:
2324 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium;
2325 break;
2326 case 1: 2227 case 1:
2327 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Short; 2228 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Short;
2328 break; 2229 break;
2329 case 2:
2330 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium;
2331 break;
2332 case 3: 2230 case 3:
2333 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Long; 2231 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Long;
2334 break; 2232 break;
2335 case 4: 2233 case 4:
2336 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Full; 2234 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Full;
2337 break; 2235 break;
2236 case 0:
2237 case 2:
2338 default: 2238 default:
2339 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium; 2239 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium;
2340 break; 2240 break;
2341 } 2241 }
2342 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); 2242 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument();
2343 if (!pDoc) { 2243 if (!pDoc)
2344 return; 2244 return;
2345 } 2245
2346 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr();
2347 IFX_Locale* pLocale = nullptr; 2246 IFX_Locale* pLocale = nullptr;
2348 if (szLocalStr.IsEmpty()) { 2247 if (szLocalStr.IsEmpty()) {
2349 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); 2248 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2350 ASSERT(pThisNode); 2249 ASSERT(pThisNode);
2250
2351 CXFA_WidgetData widgetData(pThisNode); 2251 CXFA_WidgetData widgetData(pThisNode);
2352 pLocale = widgetData.GetLocal(); 2252 pLocale = widgetData.GetLocal();
2353 } else { 2253 } else {
2354 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocalStr)); 2254 pLocale = pDoc->GetLocalMgr()->GetLocaleByName(
2255 CFX_WideString::FromUTF8(szLocalStr));
2355 } 2256 }
2356 if (!pLocale) { 2257 if (!pLocale)
2357 return; 2258 return;
2358 } 2259
2359 CFX_WideString strRet; 2260 CFX_WideString strRet;
2360 pLocale->GetDatePattern(strStyle, strRet); 2261 pLocale->GetDatePattern(strStyle, strRet);
2361 if (!bStandard) { 2262 if (!bStandard) {
2362 CFX_WideString wsSymbols; 2263 CFX_WideString wsSymbols;
2363 pLocale->GetDateTimeSymbols(wsSymbols); 2264 pLocale->GetDateTimeSymbols(wsSymbols);
2364 AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Date); 2265 AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Date);
2365 } 2266 }
2366 strFormat = FX_UTF8Encode(strRet.c_str(), strRet.GetLength()); 2267 strFormat = FX_UTF8Encode(strRet.c_str(), strRet.GetLength());
2367 } 2268 }
2368 2269
2369 // static 2270 // static
2370 void CXFA_FM2JSContext::GetLocalTimeFormat(CFXJSE_Value* pThis, 2271 void CXFA_FM2JSContext::GetLocalTimeFormat(CFXJSE_Value* pThis,
2371 int32_t iStyle, 2272 int32_t iStyle,
2372 const CFX_ByteStringC& szLocalStr, 2273 const CFX_ByteStringC& szLocalStr,
2373 CFX_ByteString& strFormat, 2274 CFX_ByteString& strFormat,
2374 FX_BOOL bStandard) { 2275 FX_BOOL bStandard) {
2375 FX_LOCALEDATETIMESUBCATEGORY strStyle; 2276 FX_LOCALEDATETIMESUBCATEGORY strStyle;
2376 switch (iStyle) { 2277 switch (iStyle) {
2377 case 0:
2378 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium;
2379 break;
2380 case 1: 2278 case 1:
2381 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Short; 2279 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Short;
2382 break; 2280 break;
2383 case 2:
2384 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium;
2385 break;
2386 case 3: 2281 case 3:
2387 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Long; 2282 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Long;
2388 break; 2283 break;
2389 case 4: 2284 case 4:
2390 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Full; 2285 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Full;
2391 break; 2286 break;
2287 case 0:
2288 case 2:
2392 default: 2289 default:
2393 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium; 2290 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium;
2394 break; 2291 break;
2395 } 2292 }
2396 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); 2293 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument();
2397 if (!pDoc) { 2294 if (!pDoc)
2398 return; 2295 return;
2399 } 2296
2400 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr();
2401 IFX_Locale* pLocale = nullptr; 2297 IFX_Locale* pLocale = nullptr;
2402 if (szLocalStr.IsEmpty()) { 2298 if (szLocalStr.IsEmpty()) {
2403 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); 2299 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2404 ASSERT(pThisNode); 2300 ASSERT(pThisNode);
2301
2405 CXFA_WidgetData widgetData(pThisNode); 2302 CXFA_WidgetData widgetData(pThisNode);
2406 pLocale = widgetData.GetLocal(); 2303 pLocale = widgetData.GetLocal();
2407 } else { 2304 } else {
2408 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocalStr)); 2305 pLocale = pDoc->GetLocalMgr()->GetLocaleByName(
2306 CFX_WideString::FromUTF8(szLocalStr));
2409 } 2307 }
2410 if (!pLocale) { 2308 if (!pLocale)
2411 return; 2309 return;
2412 } 2310
2413 CFX_WideString strRet; 2311 CFX_WideString strRet;
2414 pLocale->GetTimePattern(strStyle, strRet); 2312 pLocale->GetTimePattern(strStyle, strRet);
2415 if (!bStandard) { 2313 if (!bStandard) {
2416 CFX_WideString wsSymbols; 2314 CFX_WideString wsSymbols;
2417 pLocale->GetDateTimeSymbols(wsSymbols); 2315 pLocale->GetDateTimeSymbols(wsSymbols);
2418 AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Time); 2316 AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Time);
2419 } 2317 }
2420 strFormat = FX_UTF8Encode(strRet.c_str(), strRet.GetLength()); 2318 strFormat = FX_UTF8Encode(strRet.c_str(), strRet.GetLength());
2421 } 2319 }
2422 2320
(...skipping 16 matching lines...) Expand all
2439 // static 2337 // static
2440 void CXFA_FM2JSContext::Num2AllTime(CFXJSE_Value* pThis, 2338 void CXFA_FM2JSContext::Num2AllTime(CFXJSE_Value* pThis,
2441 int32_t iTime, 2339 int32_t iTime,
2442 const CFX_ByteStringC& szFormat, 2340 const CFX_ByteStringC& szFormat,
2443 const CFX_ByteStringC& szLocale, 2341 const CFX_ByteStringC& szLocale,
2444 FX_BOOL bGM, 2342 FX_BOOL bGM,
2445 CFX_ByteString& strTime) { 2343 CFX_ByteString& strTime) {
2446 int32_t iHour = 0; 2344 int32_t iHour = 0;
2447 int32_t iMin = 0; 2345 int32_t iMin = 0;
2448 int32_t iSec = 0; 2346 int32_t iSec = 0;
2449 int32_t iZoneHour = 0;
2450 int32_t iZoneMin = 0;
2451 int32_t iZoneSec = 0;
2452 iHour = static_cast<int>(iTime) / 3600000; 2347 iHour = static_cast<int>(iTime) / 3600000;
2453 iMin = (static_cast<int>(iTime) - iHour * 3600000) / 60000; 2348 iMin = (static_cast<int>(iTime) - iHour * 3600000) / 60000;
2454 iSec = (static_cast<int>(iTime) - iHour * 3600000 - iMin * 60000) / 1000; 2349 iSec = (static_cast<int>(iTime) - iHour * 3600000 - iMin * 60000) / 1000;
2350
2455 if (!bGM) { 2351 if (!bGM) {
2352 int32_t iZoneHour = 0;
2353 int32_t iZoneMin = 0;
2354 int32_t iZoneSec = 0;
2456 GetLocalTimeZone(iZoneHour, iZoneMin, iZoneSec); 2355 GetLocalTimeZone(iZoneHour, iZoneMin, iZoneSec);
2457 iHour += iZoneHour; 2356 iHour += iZoneHour;
2458 iMin += iZoneMin; 2357 iMin += iZoneMin;
2459 iSec += iZoneSec; 2358 iSec += iZoneSec;
2460 } 2359 }
2461 int32_t iRet = 0; 2360
2361 FX_BOOL iRet = FALSE;
2462 CFX_ByteString strIsoTime; 2362 CFX_ByteString strIsoTime;
2463 strIsoTime.Format("%02d:%02d:%02d", iHour, iMin, iSec); 2363 strIsoTime.Format("%02d:%02d:%02d", iHour, iMin, iSec);
2464 if (bGM) { 2364 if (bGM) {
2465 iRet = 2365 iRet =
2466 GetGMTTime(pThis, strIsoTime.AsStringC(), szFormat, szLocale, strTime); 2366 GetGMTTime(pThis, strIsoTime.AsStringC(), szFormat, szLocale, strTime);
2467 } else { 2367 } else {
2468 iRet = IsoTime2Local(pThis, strIsoTime.AsStringC(), szFormat, szLocale, 2368 iRet = IsoTime2Local(pThis, strIsoTime.AsStringC(), szFormat, szLocale,
2469 strTime); 2369 strTime);
2470 } 2370 }
2471 if (!iRet) { 2371 if (!iRet)
2472 strTime = ""; 2372 strTime = "";
2473 }
2474 } 2373 }
2475 2374
2476 // static 2375 // static
2477 void CXFA_FM2JSContext::GetLocalTimeZone(int32_t& iHour, 2376 void CXFA_FM2JSContext::GetLocalTimeZone(int32_t& iHour,
2478 int32_t& iMin, 2377 int32_t& iMin,
2479 int32_t& iSec) { 2378 int32_t& iSec) {
2480 time_t now; 2379 time_t now;
2481 time(&now); 2380 time(&now);
2381
2482 struct tm* pGmt = gmtime(&now); 2382 struct tm* pGmt = gmtime(&now);
2483 int32_t iGMHour = pGmt->tm_hour;
2484 int32_t iGMMin = pGmt->tm_min;
2485 int32_t iGMSec = pGmt->tm_sec;
2486 struct tm* pLocal = localtime(&now); 2383 struct tm* pLocal = localtime(&now);
2487 int32_t iLocalHour = pLocal->tm_hour; 2384 iHour = pLocal->tm_hour - pGmt->tm_hour;
2488 int32_t iLocalMin = pLocal->tm_min; 2385 iMin = pLocal->tm_min - pGmt->tm_min;
2489 int32_t iLocalSec = pLocal->tm_sec; 2386 iSec = pLocal->tm_sec - pGmt->tm_sec;
2490 iHour = iLocalHour - iGMHour;
2491 iMin = iLocalMin - iGMMin;
2492 iSec = iLocalSec - iGMSec;
2493 } 2387 }
2494 2388
2495 // static 2389 // static
2496 void CXFA_FM2JSContext::Apr(CFXJSE_Value* pThis, 2390 void CXFA_FM2JSContext::Apr(CFXJSE_Value* pThis,
2497 const CFX_ByteStringC& szFuncName, 2391 const CFX_ByteStringC& szFuncName,
2498 CFXJSE_Arguments& args) { 2392 CFXJSE_Arguments& args) {
2499 CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr); 2393 CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr);
2500 if (args.GetLength() == 3) { 2394 if (args.GetLength() == 3) {
2501 FX_BOOL bFlags = FALSE; 2395 FX_BOOL bFlags = FALSE;
2502 FX_DOUBLE nPrincipal = 0; 2396 FX_DOUBLE nPrincipal = 0;
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
2730 for (int32_t i = 1; i < argc; i++) { 2624 for (int32_t i = 1; i < argc; i++) {
2731 pData[i - 1] = ValueToDouble(pThis, argValues[i].get()); 2625 pData[i - 1] = ValueToDouble(pThis, argValues[i].get());
2732 } 2626 }
2733 FX_DOUBLE nSum = 0; 2627 FX_DOUBLE nSum = 0;
2734 int32_t iIndex = 0; 2628 int32_t iIndex = 0;
2735 for (int32_t i = 0; i < argc - 1; i++) { 2629 for (int32_t i = 0; i < argc - 1; i++) {
2736 FX_DOUBLE nTemp = 1; 2630 FX_DOUBLE nTemp = 1;
2737 for (int32_t j = 0; j <= i; j++) { 2631 for (int32_t j = 0; j <= i; j++) {
2738 nTemp *= 1 + nRate; 2632 nTemp *= 1 + nRate;
2739 } 2633 }
2740 FX_DOUBLE nNum = *(pData + iIndex++); 2634 FX_DOUBLE nNum = pData[iIndex++];
2741 nSum += nNum / nTemp; 2635 nSum += nNum / nTemp;
2742 } 2636 }
2743 FXJSE_Value_SetDouble(args.GetReturnValue(), nSum); 2637 FXJSE_Value_SetDouble(args.GetReturnValue(), nSum);
2744 FX_Free(pData); 2638 FX_Free(pData);
2745 pData = 0; 2639 pData = nullptr;
2746 } 2640 }
2747 } else { 2641 } else {
2748 FXJSE_Value_SetNull(args.GetReturnValue()); 2642 FXJSE_Value_SetNull(args.GetReturnValue());
2749 } 2643 }
2750 } else { 2644 } else {
2751 pContext->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"NPV"); 2645 pContext->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"NPV");
2752 } 2646 }
2753 } 2647 }
2754 2648
2755 // static 2649 // static
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
3315 VALUETYPE_ISPT, 3209 VALUETYPE_ISPT,
3316 VALUETYPE_ISMP, 3210 VALUETYPE_ISMP,
3317 VALUETYPE_ISIN, 3211 VALUETYPE_ISIN,
3318 }; 3212 };
3319 unitspanString.MakeLower(); 3213 unitspanString.MakeLower();
3320 CFX_WideString wsTypeString = 3214 CFX_WideString wsTypeString =
3321 CFX_WideString::FromUTF8(unitspanString.AsStringC()); 3215 CFX_WideString::FromUTF8(unitspanString.AsStringC());
3322 const FX_WCHAR* pData = wsTypeString.c_str(); 3216 const FX_WCHAR* pData = wsTypeString.c_str();
3323 int32_t u = 0; 3217 int32_t u = 0;
3324 int32_t uLen = wsTypeString.GetLength(); 3218 int32_t uLen = wsTypeString.GetLength();
3325 while (*(pData + u) == 0x20 || *(pData + u) == 0x09 || 3219 while (pData[u] == 0x20 || pData[u] == 0x09 || pData[u] == 0x0B ||
Tom Sepez 2016/06/06 18:16:09 nit: helper function.
dsinclair 2016/06/06 18:27:50 Done.
3326 *(pData + u) == 0x0B || *(pData + u) == 0x0C || 3220 pData[u] == 0x0C || pData[u] == 0x0A || pData[u] == 0x0D) {
3327 *(pData + u) == 0x0A || *(pData + u) == 0x0D) {
3328 u++; 3221 u++;
3329 } 3222 }
3330 XFA_FM2JS_VALUETYPE_ParserStatus eParserStatus = VALUETYPE_START; 3223 XFA_FM2JS_VALUETYPE_ParserStatus eParserStatus = VALUETYPE_START;
3331 FX_WCHAR typeChar; 3224 FX_WCHAR typeChar;
3332 while (u < uLen) { 3225 while (u < uLen) {
3333 typeChar = *(pData + u); 3226 typeChar = pData[u];
3334 if (typeChar == 0x20 || typeChar == 0x09 || typeChar == 0x0B || 3227 if (typeChar == 0x20 || typeChar == 0x09 || typeChar == 0x0B ||
3335 typeChar == 0x0C || typeChar == 0x0A || typeChar == 0x0D) { 3228 typeChar == 0x0C || typeChar == 0x0A || typeChar == 0x0D) {
3336 if (eParserStatus == VALUETYPE_HAVEDIGIT || 3229 if (eParserStatus == VALUETYPE_HAVEDIGIT ||
3337 eParserStatus == VALUETYPE_HAVEDIGITWHITE) { 3230 eParserStatus == VALUETYPE_HAVEDIGITWHITE) {
3338 eParserStatus = VALUETYPE_HAVEDIGITWHITE; 3231 eParserStatus = VALUETYPE_HAVEDIGITWHITE;
3339 } else { 3232 } else {
3340 eParserStatus = VALUETYPE_ISIN; 3233 eParserStatus = VALUETYPE_ISIN;
3341 break; 3234 break;
3342 } 3235 }
3343 } else if ((typeChar >= '0' && typeChar <= '9') || typeChar == '-' || 3236 } else if ((typeChar >= '0' && typeChar <= '9') || typeChar == '-' ||
3344 typeChar == '.') { 3237 typeChar == '.') {
3345 if (eParserStatus == VALUETYPE_HAVEDIGITWHITE) { 3238 if (eParserStatus == VALUETYPE_HAVEDIGITWHITE) {
3346 eParserStatus = VALUETYPE_ISIN; 3239 eParserStatus = VALUETYPE_ISIN;
3347 break; 3240 break;
3348 } else { 3241 } else {
3349 eParserStatus = VALUETYPE_HAVEDIGIT; 3242 eParserStatus = VALUETYPE_HAVEDIGIT;
3350 } 3243 }
3351 } else if ((typeChar == 'c' || typeChar == 'p') && (u + 1 < uLen)) { 3244 } else if ((typeChar == 'c' || typeChar == 'p') && (u + 1 < uLen)) {
3352 FX_WCHAR nextChar = *(pData + u + 1); 3245 FX_WCHAR nextChar = pData[u + 1];
3353 if ((eParserStatus == VALUETYPE_START || 3246 if ((eParserStatus == VALUETYPE_START ||
3354 eParserStatus == VALUETYPE_HAVEDIGIT || 3247 eParserStatus == VALUETYPE_HAVEDIGIT ||
3355 eParserStatus == VALUETYPE_HAVEDIGITWHITE) && 3248 eParserStatus == VALUETYPE_HAVEDIGITWHITE) &&
3356 (nextChar > '9' || nextChar < '0') && nextChar != '.' && 3249 (nextChar > '9' || nextChar < '0') && nextChar != '.' &&
3357 nextChar != '-') { 3250 nextChar != '-') {
3358 eParserStatus = (typeChar == 'c') ? VALUETYPE_ISCM : VALUETYPE_ISPT; 3251 eParserStatus = (typeChar == 'c') ? VALUETYPE_ISCM : VALUETYPE_ISPT;
3359 break; 3252 break;
3360 } else { 3253 } else {
3361 eParserStatus = VALUETYPE_HAVEINVALIDCHAR; 3254 eParserStatus = VALUETYPE_HAVEINVALIDCHAR;
3362 } 3255 }
3363 } else if (typeChar == 'm' && (u + 1 < uLen)) { 3256 } else if (typeChar == 'm' && (u + 1 < uLen)) {
3364 FX_WCHAR nextChar = *(pData + u + 1); 3257 FX_WCHAR nextChar = pData[u + 1];
3365 if ((eParserStatus == VALUETYPE_START || 3258 if ((eParserStatus == VALUETYPE_START ||
3366 eParserStatus == VALUETYPE_HAVEDIGIT || 3259 eParserStatus == VALUETYPE_HAVEDIGIT ||
3367 eParserStatus == VALUETYPE_HAVEDIGITWHITE) && 3260 eParserStatus == VALUETYPE_HAVEDIGITWHITE) &&
3368 (nextChar > '9' || nextChar < '0') && nextChar != '.' && 3261 (nextChar > '9' || nextChar < '0') && nextChar != '.' &&
3369 nextChar != '-') { 3262 nextChar != '-') {
3370 eParserStatus = VALUETYPE_ISMM; 3263 eParserStatus = VALUETYPE_ISMM;
3371 if (nextChar == 'p' || 3264 if (nextChar == 'p' ||
3372 ((u + 5 < uLen) && *(pData + u + 1) == 'i' && 3265 ((u + 5 < uLen) && pData[u + 1] == 'i' && pData[u + 2] == 'l' &&
3373 *(pData + u + 2) == 'l' && *(pData + u + 3) == 'l' && 3266 pData[u + 3] == 'l' && pData[u + 4] == 'i' &&
3374 *(pData + u + 4) == 'i' && *(pData + u + 5) == 'p')) { 3267 pData[u + 5] == 'p')) {
3375 eParserStatus = VALUETYPE_ISMP; 3268 eParserStatus = VALUETYPE_ISMP;
3376 } 3269 }
3377 break; 3270 break;
3378 } 3271 }
3379 } else { 3272 } else {
3380 eParserStatus = VALUETYPE_HAVEINVALIDCHAR; 3273 eParserStatus = VALUETYPE_HAVEINVALIDCHAR;
3381 } 3274 }
3382 u++; 3275 u++;
3383 } 3276 }
3384 switch (eParserStatus) { 3277 switch (eParserStatus) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3417 FX_DOUBLE dFirstNumber = 0; 3310 FX_DOUBLE dFirstNumber = 0;
3418 CFX_ByteString strFirstUnit; 3311 CFX_ByteString strFirstUnit;
3419 CFX_ByteString strUnit; 3312 CFX_ByteString strUnit;
3420 if (FXJSE_Value_IsNull(unitspanValue.get())) { 3313 if (FXJSE_Value_IsNull(unitspanValue.get())) {
3421 FXJSE_Value_SetNull(args.GetReturnValue()); 3314 FXJSE_Value_SetNull(args.GetReturnValue());
3422 } else { 3315 } else {
3423 ValueToUTF8String(unitspanValue.get(), unitspanString); 3316 ValueToUTF8String(unitspanValue.get(), unitspanString);
3424 const FX_CHAR* pData = unitspanString.c_str(); 3317 const FX_CHAR* pData = unitspanString.c_str();
3425 if (pData) { 3318 if (pData) {
3426 int32_t u = 0; 3319 int32_t u = 0;
3427 while (*(pData + u) == 0x20 || *(pData + u) == 0x09 || 3320 while (pData[u] == 0x20 || pData[u] == 0x09 || pData[u] == 0x0B ||
Tom Sepez 2016/06/06 18:16:09 nit: here too.
dsinclair 2016/06/06 18:27:50 Done.
3428 *(pData + u) == 0x0B || *(pData + u) == 0x0C || 3321 pData[u] == 0x0C || pData[u] == 0x0A || pData[u] == 0x0D) {
3429 *(pData + u) == 0x0A || *(pData + u) == 0x0D) {
3430 ++u; 3322 ++u;
3431 } 3323 }
3432 while (u < unitspanString.GetLength()) { 3324 while (u < unitspanString.GetLength()) {
3433 if ((*(pData + u) > '9' || *(pData + u) < '0') && 3325 if ((pData[u] > '9' || pData[u] < '0') && pData[u] != '.' &&
3434 *(pData + u) != '.' && *(pData + u) != '-') { 3326 pData[u] != '-') {
3435 break; 3327 break;
3436 } 3328 }
3437 ++u; 3329 ++u;
3438 } 3330 }
3439 FX_CHAR* pTemp = nullptr; 3331 FX_CHAR* pTemp = nullptr;
3440 dFirstNumber = strtod(pData, &pTemp); 3332 dFirstNumber = strtod(pData, &pTemp);
3441 while (*(pData + u) == ' ' || *(pData + u) == 0x09 || 3333 while (pData[u] == ' ' || pData[u] == 0x09 || pData[u] == 0x0B ||
3442 *(pData + u) == 0x0B || *(pData + u) == 0x0C || 3334 pData[u] == 0x0C || pData[u] == 0x0A || pData[u] == 0x0D) {
Tom Sepez 2016/06/06 18:16:10 nit: and a'here.
dsinclair 2016/06/06 18:27:50 Done.
3443 *(pData + u) == 0x0A || *(pData + u) == 0x0D) {
3444 ++u; 3335 ++u;
3445 } 3336 }
3446 int32_t uLen = unitspanString.GetLength(); 3337 int32_t uLen = unitspanString.GetLength();
3447 while (u < uLen) { 3338 while (u < uLen) {
3448 if (*(pData + u) == ' ') { 3339 if (pData[u] == ' ') {
3449 break; 3340 break;
3450 } 3341 }
3451 strFirstUnit += (*(pData + u)); 3342 strFirstUnit += pData[u];
3452 ++u; 3343 ++u;
3453 } 3344 }
3454 strFirstUnit.MakeLower(); 3345 strFirstUnit.MakeLower();
3455 if (argc == 2) { 3346 if (argc == 2) {
3456 std::unique_ptr<CFXJSE_Value> unitValue = 3347 std::unique_ptr<CFXJSE_Value> unitValue =
3457 GetSimpleValue(pThis, args, 1); 3348 GetSimpleValue(pThis, args, 1);
3458 CFX_ByteString unitTempString; 3349 CFX_ByteString unitTempString;
3459 ValueToUTF8String(unitValue.get(), unitTempString); 3350 ValueToUTF8String(unitValue.get(), unitTempString);
3460 const FX_CHAR* pChar = unitTempString.c_str(); 3351 const FX_CHAR* pChar = unitTempString.c_str();
3461 int32_t uVal = 0; 3352 int32_t uVal = 0;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
3586 ToJSContext(pThis, nullptr) 3477 ToJSContext(pThis, nullptr)
3587 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"At"); 3478 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"At");
3588 } 3479 }
3589 } 3480 }
3590 3481
3591 // static 3482 // static
3592 void CXFA_FM2JSContext::Concat(CFXJSE_Value* pThis, 3483 void CXFA_FM2JSContext::Concat(CFXJSE_Value* pThis,
3593 const CFX_ByteStringC& szFuncName, 3484 const CFX_ByteStringC& szFuncName,
3594 CFXJSE_Arguments& args) { 3485 CFXJSE_Arguments& args) {
3595 int32_t argc = args.GetLength(); 3486 int32_t argc = args.GetLength();
3596 if (argc >= 1) { 3487 if (argc > 0) {
3597 CFX_ByteString resultString; 3488 CFX_ByteString resultString;
3598 FX_BOOL bAllNull = TRUE; 3489 FX_BOOL bAllNull = TRUE;
3599 3490
3600 for (int32_t i = 0; i < argc; i++) { 3491 for (int32_t i = 0; i < argc; i++) {
3601 std::unique_ptr<CFXJSE_Value> value = GetSimpleValue(pThis, args, i); 3492 std::unique_ptr<CFXJSE_Value> value = GetSimpleValue(pThis, args, i);
3602 if (!ValueIsNull(pThis, value.get())) { 3493 if (!ValueIsNull(pThis, value.get())) {
3603 CFX_ByteString valueStr; 3494 CFX_ByteString valueStr;
3604 ValueToUTF8String(value.get(), valueStr); 3495 ValueToUTF8String(value.get(), valueStr);
3605 resultString += valueStr; 3496 resultString += valueStr;
3606 bAllNull = FALSE; 3497 bAllNull = FALSE;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3665 void CXFA_FM2JSContext::DecodeURL(const CFX_ByteStringC& szURLString, 3556 void CXFA_FM2JSContext::DecodeURL(const CFX_ByteStringC& szURLString,
3666 CFX_ByteTextBuf& szResultString) { 3557 CFX_ByteTextBuf& szResultString) {
3667 CFX_WideString wsURLString = CFX_WideString::FromUTF8(szURLString); 3558 CFX_WideString wsURLString = CFX_WideString::FromUTF8(szURLString);
3668 const FX_WCHAR* pData = wsURLString.c_str(); 3559 const FX_WCHAR* pData = wsURLString.c_str();
3669 int32_t iLen = wsURLString.GetLength(); 3560 int32_t iLen = wsURLString.GetLength();
3670 int32_t i = 0; 3561 int32_t i = 0;
3671 FX_WCHAR ch = 0; 3562 FX_WCHAR ch = 0;
3672 FX_WCHAR chTemp = 0; 3563 FX_WCHAR chTemp = 0;
3673 CFX_WideTextBuf wsResultBuf; 3564 CFX_WideTextBuf wsResultBuf;
3674 while (i < iLen) { 3565 while (i < iLen) {
3675 ch = *(pData + i); 3566 ch = pData[i];
3676 if ('%' == ch) { 3567 if ('%' == ch) {
3677 chTemp = 0; 3568 chTemp = 0;
3678 int32_t iCount = 0; 3569 int32_t iCount = 0;
3679 while (iCount < 2) { 3570 while (iCount < 2) {
3680 ++i; 3571 ++i;
3681 ch = *(pData + i); 3572 ch = pData[i];
3682 if (ch <= '9' && ch >= '0') { 3573 if (ch <= '9' && ch >= '0') {
3683 if (!iCount) { 3574 if (!iCount) {
3684 chTemp += (ch - '0') * 16; 3575 chTemp += (ch - '0') * 16;
3685 } else { 3576 } else {
3686 chTemp += (ch - '0'); 3577 chTemp += (ch - '0');
3687 } 3578 }
3688 } else { 3579 } else {
3689 if (ch <= 'F' && ch >= 'A') { 3580 if (ch <= 'F' && ch >= 'A') {
3690 if (!iCount) { 3581 if (!iCount) {
3691 chTemp += (ch - 'A' + 10) * 16; 3582 chTemp += (ch - 'A' + 10) * 16;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3724 CFX_WideString wsHTMLString = CFX_WideString::FromUTF8(szHTMLString); 3615 CFX_WideString wsHTMLString = CFX_WideString::FromUTF8(szHTMLString);
3725 FX_WCHAR strString[9]; 3616 FX_WCHAR strString[9];
3726 int32_t iStrIndex = 0; 3617 int32_t iStrIndex = 0;
3727 int32_t iLen = wsHTMLString.GetLength(); 3618 int32_t iLen = wsHTMLString.GetLength();
3728 int32_t i = 0; 3619 int32_t i = 0;
3729 int32_t iCode = 0; 3620 int32_t iCode = 0;
3730 FX_WCHAR ch = 0; 3621 FX_WCHAR ch = 0;
3731 const FX_WCHAR* pData = wsHTMLString.c_str(); 3622 const FX_WCHAR* pData = wsHTMLString.c_str();
3732 CFX_WideTextBuf wsResultBuf; 3623 CFX_WideTextBuf wsResultBuf;
3733 while (i < iLen) { 3624 while (i < iLen) {
3734 ch = *(pData + i); 3625 ch = pData[i];
3735 if (ch == '&') { 3626 if (ch == '&') {
3736 ++i; 3627 ++i;
3737 ch = *(pData + i); 3628 ch = pData[i];
3738 if (ch == '#') { 3629 if (ch == '#') {
3739 ++i; 3630 ++i;
3740 ch = *(pData + i); 3631 ch = pData[i];
3741 if (ch == 'x' || ch == 'X') { 3632 if (ch == 'x' || ch == 'X') {
3742 ++i; 3633 ++i;
3743 ch = *(pData + i); 3634 ch = pData[i];
3744 if ((ch >= '0' && ch <= '9') || (ch <= 'f' && ch >= 'a') || 3635 if ((ch >= '0' && ch <= '9') || (ch <= 'f' && ch >= 'a') ||
3745 (ch <= 'F' && ch >= 'A')) { 3636 (ch <= 'F' && ch >= 'A')) {
3746 while (ch != ';' && i < iLen) { 3637 while (ch != ';' && i < iLen) {
3747 if (ch >= '0' && ch <= '9') { 3638 if (ch >= '0' && ch <= '9') {
3748 iCode += ch - '0'; 3639 iCode += ch - '0';
3749 } else if (ch <= 'f' && ch >= 'a') { 3640 } else if (ch <= 'f' && ch >= 'a') {
3750 iCode += ch - 'a' + 10; 3641 iCode += ch - 'a' + 10;
3751 } else if (ch <= 'F' && ch >= 'A') { 3642 } else if (ch <= 'F' && ch >= 'A') {
3752 iCode += ch - 'A' + 10; 3643 iCode += ch - 'A' + 10;
3753 } else { 3644 } else {
3754 wsResultBuf.Clear(); 3645 wsResultBuf.Clear();
3755 return; 3646 return;
3756 } 3647 }
3757 ++i; 3648 ++i;
3758 iCode *= 16; 3649 iCode *= 16;
3759 ch = *(pData + i); 3650 ch = pData[i];
3760 } 3651 }
3761 iCode /= 16; 3652 iCode /= 16;
3762 } 3653 }
3763 } else { 3654 } else {
3764 wsResultBuf.Clear(); 3655 wsResultBuf.Clear();
3765 return; 3656 return;
3766 } 3657 }
3767 } else { 3658 } else {
3768 while (ch != ';' && i < iLen) { 3659 while (ch != ';' && i < iLen) {
3769 strString[iStrIndex++] = ch; 3660 strString[iStrIndex++] = ch;
3770 ++i; 3661 ++i;
3771 ch = *(pData + i); 3662 ch = pData[i];
3772 } 3663 }
3773 strString[iStrIndex] = 0; 3664 strString[iStrIndex] = 0;
3774 } 3665 }
3775 } else { 3666 } else {
3776 wsResultBuf.AppendChar(ch); 3667 wsResultBuf.AppendChar(ch);
3777 ++i; 3668 ++i;
3778 continue; 3669 continue;
3779 } 3670 }
3780 uint32_t iData = 0; 3671 uint32_t iData = 0;
3781 if (HTMLSTR2Code(strString, iData)) { 3672 if (HTMLSTR2Code(strString, iData)) {
(...skipping 18 matching lines...) Expand all
3800 CFX_WideString wsXMLString = CFX_WideString::FromUTF8(szXMLString); 3691 CFX_WideString wsXMLString = CFX_WideString::FromUTF8(szXMLString);
3801 FX_WCHAR strString[9]; 3692 FX_WCHAR strString[9];
3802 int32_t iStrIndex = 0; 3693 int32_t iStrIndex = 0;
3803 int32_t iLen = wsXMLString.GetLength(); 3694 int32_t iLen = wsXMLString.GetLength();
3804 int32_t i = 0; 3695 int32_t i = 0;
3805 int32_t iCode = 0; 3696 int32_t iCode = 0;
3806 FX_WCHAR ch = 0; 3697 FX_WCHAR ch = 0;
3807 const FX_WCHAR* pData = wsXMLString.c_str(); 3698 const FX_WCHAR* pData = wsXMLString.c_str();
3808 CFX_WideTextBuf wsXMLBuf; 3699 CFX_WideTextBuf wsXMLBuf;
3809 while (i < iLen) { 3700 while (i < iLen) {
3810 ch = *(pData + i); 3701 ch = pData[i];
3811 if (ch == '&') { 3702 if (ch == '&') {
3812 ++i; 3703 ++i;
3813 ch = *(pData + i); 3704 ch = pData[i];
3814 if (ch == '#') { 3705 if (ch == '#') {
3815 ++i; 3706 ++i;
3816 ch = *(pData + i); 3707 ch = pData[i];
3817 if (ch == 'x' || ch == 'X') { 3708 if (ch == 'x' || ch == 'X') {
3818 ++i; 3709 ++i;
3819 ch = *(pData + i); 3710 ch = pData[i];
3820 if ((ch >= '0' && ch <= '9') || (ch <= 'f' && ch >= 'a') || 3711 if ((ch >= '0' && ch <= '9') || (ch <= 'f' && ch >= 'a') ||
3821 (ch <= 'F' && ch >= 'A')) { 3712 (ch <= 'F' && ch >= 'A')) {
3822 while (ch != ';') { 3713 while (ch != ';') {
3823 if (ch >= '0' && ch <= '9') { 3714 if (ch >= '0' && ch <= '9') {
3824 iCode += ch - '0'; 3715 iCode += ch - '0';
3825 } else if (ch <= 'f' && ch >= 'a') { 3716 } else if (ch <= 'f' && ch >= 'a') {
3826 iCode += ch - 'a' + 10; 3717 iCode += ch - 'a' + 10;
3827 } else if (ch <= 'F' && ch >= 'A') { 3718 } else if (ch <= 'F' && ch >= 'A') {
3828 iCode += ch - 'A' + 10; 3719 iCode += ch - 'A' + 10;
3829 } else { 3720 } else {
3830 wsXMLBuf.Clear(); 3721 wsXMLBuf.Clear();
3831 return; 3722 return;
3832 } 3723 }
3833 ++i; 3724 ++i;
3834 iCode *= 16; 3725 iCode *= 16;
3835 ch = *(pData + i); 3726 ch = pData[i];
3836 } 3727 }
3837 iCode /= 16; 3728 iCode /= 16;
3838 } 3729 }
3839 } else { 3730 } else {
3840 wsXMLBuf.Clear(); 3731 wsXMLBuf.Clear();
3841 return; 3732 return;
3842 } 3733 }
3843 } else { 3734 } else {
3844 while (ch != ';' && i < iLen) { 3735 while (ch != ';' && i < iLen) {
3845 strString[iStrIndex++] = ch; 3736 strString[iStrIndex++] = ch;
3846 ++i; 3737 ++i;
3847 ch = *(pData + i); 3738 ch = pData[i];
3848 } 3739 }
3849 strString[iStrIndex] = 0; 3740 strString[iStrIndex] = 0;
3850 } 3741 }
3851 } else { 3742 } else {
3852 wsXMLBuf.AppendChar(ch); 3743 wsXMLBuf.AppendChar(ch);
3853 ++i; 3744 ++i;
3854 continue; 3745 continue;
3855 } 3746 }
3856 const FX_WCHAR* const strName[] = {L"quot", L"amp", L"apos", L"lt", L"gt"}; 3747 const FX_WCHAR* const strName[] = {L"quot", L"amp", L"apos", L"lt", L"gt"};
3857 int32_t iIndex = 0; 3748 int32_t iIndex = 0;
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
4059 strEncode[7] = ';'; 3950 strEncode[7] = ';';
4060 strEncode[8] = 0; 3951 strEncode[8] = 0;
4061 CFX_WideTextBuf wsResultBuf; 3952 CFX_WideTextBuf wsResultBuf;
4062 uint32_t ch = 0; 3953 uint32_t ch = 0;
4063 int32_t iLen = wsHTMLString.GetLength(); 3954 int32_t iLen = wsHTMLString.GetLength();
4064 int32_t i = 0; 3955 int32_t i = 0;
4065 const FX_WCHAR* pData = wsHTMLString.c_str(); 3956 const FX_WCHAR* pData = wsHTMLString.c_str();
4066 int32_t iIndex = 0; 3957 int32_t iIndex = 0;
4067 CFX_WideString htmlReserve; 3958 CFX_WideString htmlReserve;
4068 while (i < iLen) { 3959 while (i < iLen) {
4069 ch = *(pData + i); 3960 ch = pData[i];
4070 htmlReserve.clear(); 3961 htmlReserve.clear();
4071 if (HTMLCode2STR(ch, htmlReserve)) { 3962 if (HTMLCode2STR(ch, htmlReserve)) {
4072 wsResultBuf.AppendChar(L'&'); 3963 wsResultBuf.AppendChar(L'&');
4073 wsResultBuf << htmlReserve; 3964 wsResultBuf << htmlReserve;
4074 wsResultBuf.AppendChar(L';'); 3965 wsResultBuf.AppendChar(L';');
4075 } else { 3966 } else {
4076 if (ch >= 32 && ch <= 126) { 3967 if (ch >= 32 && ch <= 126) {
4077 wsResultBuf.AppendChar((FX_WCHAR)ch); 3968 wsResultBuf.AppendChar((FX_WCHAR)ch);
4078 } else if (ch < 256) { 3969 } else if (ch < 256) {
4079 iIndex = ch / 16; 3970 iIndex = ch / 16;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
4121 strEncode[7] = ';'; 4012 strEncode[7] = ';';
4122 strEncode[8] = 0; 4013 strEncode[8] = 0;
4123 const FX_WCHAR* const strName[] = {L"quot", L"amp", L"apos", L"lt", L"gt"}; 4014 const FX_WCHAR* const strName[] = {L"quot", L"amp", L"apos", L"lt", L"gt"};
4124 const FX_WCHAR* strCode = L"0123456789abcdef"; 4015 const FX_WCHAR* strCode = L"0123456789abcdef";
4125 FX_WCHAR ch = 0; 4016 FX_WCHAR ch = 0;
4126 int32_t iLength = wsXMLString.GetLength(); 4017 int32_t iLength = wsXMLString.GetLength();
4127 int32_t iIndex = 0; 4018 int32_t iIndex = 0;
4128 int32_t u = 0; 4019 int32_t u = 0;
4129 const FX_WCHAR* pData = wsXMLString.c_str(); 4020 const FX_WCHAR* pData = wsXMLString.c_str();
4130 for (u = 0; u < iLength; ++u) { 4021 for (u = 0; u < iLength; ++u) {
4131 ch = *(pData + u); 4022 ch = pData[u];
4132 switch (ch) { 4023 switch (ch) {
4133 case '"': 4024 case '"':
4134 wsResultBuf.AppendChar('&'); 4025 wsResultBuf.AppendChar('&');
4135 wsResultBuf << CFX_WideStringC(strName[QUOT]); 4026 wsResultBuf << CFX_WideStringC(strName[QUOT]);
4136 wsResultBuf.AppendChar(';'); 4027 wsResultBuf.AppendChar(';');
4137 break; 4028 break;
4138 case '&': 4029 case '&':
4139 wsResultBuf.AppendChar('&'); 4030 wsResultBuf.AppendChar('&');
4140 wsResultBuf << CFX_WideStringC(strName[AMP]); 4031 wsResultBuf << CFX_WideStringC(strName[AMP]);
4141 wsResultBuf.AppendChar(';'); 4032 wsResultBuf.AppendChar(';');
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
4372 } else { 4263 } else {
4373 ValueToUTF8String(argOne.get(), argString); 4264 ValueToUTF8String(argOne.get(), argString);
4374 CFX_WideTextBuf lowStringBuf; 4265 CFX_WideTextBuf lowStringBuf;
4375 CFX_WideString wsArgString = 4266 CFX_WideString wsArgString =
4376 CFX_WideString::FromUTF8(argString.AsStringC()); 4267 CFX_WideString::FromUTF8(argString.AsStringC());
4377 const FX_WCHAR* pData = wsArgString.c_str(); 4268 const FX_WCHAR* pData = wsArgString.c_str();
4378 int32_t iLen = argString.GetLength(); 4269 int32_t iLen = argString.GetLength();
4379 int32_t i = 0; 4270 int32_t i = 0;
4380 int32_t ch = 0; 4271 int32_t ch = 0;
4381 while (i < iLen) { 4272 while (i < iLen) {
4382 ch = *(pData + i); 4273 ch = pData[i];
4383 if (ch >= 0x41 && ch <= 0x5A) { 4274 if (ch >= 0x41 && ch <= 0x5A) {
4384 ch += 32; 4275 ch += 32;
4385 } else if (ch >= 0xC0 && ch <= 0xDE) { 4276 } else if (ch >= 0xC0 && ch <= 0xDE) {
4386 ch += 32; 4277 ch += 32;
4387 } else if (ch == 0x100 || ch == 0x102 || ch == 0x104) { 4278 } else if (ch == 0x100 || ch == 0x102 || ch == 0x104) {
4388 ch += 1; 4279 ch += 1;
4389 } 4280 }
4390 lowStringBuf.AppendChar(ch); 4281 lowStringBuf.AppendChar(ch);
4391 ++i; 4282 ++i;
4392 } 4283 }
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
4571 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); 4462 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4572 std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1); 4463 std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1);
4573 CFX_ByteString oneString; 4464 CFX_ByteString oneString;
4574 CFX_ByteString twoString; 4465 CFX_ByteString twoString;
4575 CFX_ByteString threeString; 4466 CFX_ByteString threeString;
4576 if (!ValueIsNull(pThis, argOne.get()) && 4467 if (!ValueIsNull(pThis, argOne.get()) &&
4577 !ValueIsNull(pThis, argTwo.get())) { 4468 !ValueIsNull(pThis, argTwo.get())) {
4578 ValueToUTF8String(argOne.get(), oneString); 4469 ValueToUTF8String(argOne.get(), oneString);
4579 ValueToUTF8String(argTwo.get(), twoString); 4470 ValueToUTF8String(argTwo.get(), twoString);
4580 } 4471 }
4581 if (argc == 3) { 4472 if (argc > 2) {
4582 std::unique_ptr<CFXJSE_Value> argThree = GetSimpleValue(pThis, args, 2); 4473 std::unique_ptr<CFXJSE_Value> argThree = GetSimpleValue(pThis, args, 2);
4583 ValueToUTF8String(argThree.get(), threeString); 4474 ValueToUTF8String(argThree.get(), threeString);
4584 } 4475 }
4585 int32_t iSrcLen = oneString.GetLength(); 4476 int32_t iSrcLen = oneString.GetLength();
4586 int32_t iFindLen = twoString.GetLength(); 4477 int32_t iFindLen = twoString.GetLength();
4587 CFX_ByteTextBuf resultString; 4478 CFX_ByteTextBuf resultString;
4588 int32_t iFindIndex = 0; 4479 int32_t iFindIndex = 0;
4589 uint8_t ch = 0; 4480 uint8_t ch = 0;
4590 for (int32_t u = 0; u < iSrcLen; ++u) { 4481 for (int32_t u = 0; u < iSrcLen; ++u) {
4591 ch = oneString.GetAt(u); 4482 ch = oneString.GetAt(u);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
4713 std::unique_ptr<CFXJSE_Value> numberValue = GetSimpleValue(pThis, args, 0); 4604 std::unique_ptr<CFXJSE_Value> numberValue = GetSimpleValue(pThis, args, 0);
4714 if (FXJSE_Value_IsNull(numberValue.get())) { 4605 if (FXJSE_Value_IsNull(numberValue.get())) {
4715 bFlags = TRUE; 4606 bFlags = TRUE;
4716 } else { 4607 } else {
4717 fNumber = ValueToFloat(pThis, numberValue.get()); 4608 fNumber = ValueToFloat(pThis, numberValue.get());
4718 } 4609 }
4719 if (argc > 1) { 4610 if (argc > 1) {
4720 std::unique_ptr<CFXJSE_Value> widthValue = GetSimpleValue(pThis, args, 1); 4611 std::unique_ptr<CFXJSE_Value> widthValue = GetSimpleValue(pThis, args, 1);
4721 iWidth = (int32_t)ValueToFloat(pThis, widthValue.get()); 4612 iWidth = (int32_t)ValueToFloat(pThis, widthValue.get());
4722 } 4613 }
4723 if (argc == 3) { 4614 if (argc > 2) {
4724 std::unique_ptr<CFXJSE_Value> precisionValue = 4615 std::unique_ptr<CFXJSE_Value> precisionValue =
4725 GetSimpleValue(pThis, args, 2); 4616 GetSimpleValue(pThis, args, 2);
4726 iPrecision = (int32_t)ValueToFloat(pThis, precisionValue.get()); 4617 iPrecision = (int32_t)ValueToFloat(pThis, precisionValue.get());
4727 if (iPrecision < 0) { 4618 if (iPrecision < 0) {
4728 iPrecision = 0; 4619 iPrecision = 0;
4729 } 4620 }
4730 } 4621 }
4731 if (!bFlags) { 4622 if (!bFlags) {
4732 CFX_ByteString numberString; 4623 CFX_ByteString numberString;
4733 CFX_ByteString formatStr = "%"; 4624 CFX_ByteString formatStr = "%";
4734 if (iPrecision) { 4625 if (iPrecision) {
4735 formatStr += "."; 4626 formatStr += ".";
4736 formatStr += CFX_ByteString::FormatInteger(iPrecision); 4627 formatStr += CFX_ByteString::FormatInteger(iPrecision);
4737 } 4628 }
4738 formatStr += "f"; 4629 formatStr += "f";
4739 numberString.Format(formatStr.c_str(), fNumber); 4630 numberString.Format(formatStr.c_str(), fNumber);
4740 const FX_CHAR* pData = numberString.c_str(); 4631 const FX_CHAR* pData = numberString.c_str();
4741 int32_t iLength = numberString.GetLength(); 4632 int32_t iLength = numberString.GetLength();
4742 int32_t u = 0; 4633 int32_t u = 0;
4743 while (u < iLength) { 4634 while (u < iLength) {
4744 if (*(pData + u) == '.') { 4635 if (pData[u] == '.') {
4745 break; 4636 break;
4746 } 4637 }
4747 ++u; 4638 ++u;
4748 } 4639 }
4749 CFX_ByteTextBuf resultBuf; 4640 CFX_ByteTextBuf resultBuf;
4750 if (u > iWidth || (iPrecision + u) >= iWidth) { 4641 if (u > iWidth || (iPrecision + u) >= iWidth) {
4751 int32_t i = 0; 4642 int32_t i = 0;
4752 while (i < iWidth) { 4643 while (i < iWidth) {
4753 resultBuf.AppendChar('*'); 4644 resultBuf.AppendChar('*');
4754 ++i; 4645 ++i;
(...skipping 23 matching lines...) Expand all
4778 } else { 4669 } else {
4779 iLeavingSpace = iWidth - (u + iPrecision + 1); 4670 iLeavingSpace = iWidth - (u + iPrecision + 1);
4780 } 4671 }
4781 int32_t i = 0; 4672 int32_t i = 0;
4782 while (i < iLeavingSpace) { 4673 while (i < iLeavingSpace) {
4783 resultBuf.AppendChar(' '); 4674 resultBuf.AppendChar(' ');
4784 ++i; 4675 ++i;
4785 } 4676 }
4786 i = 0; 4677 i = 0;
4787 while (i < u) { 4678 while (i < u) {
4788 resultBuf.AppendChar(*(pData + i)); 4679 resultBuf.AppendChar(pData[i]);
4789 ++i; 4680 ++i;
4790 } 4681 }
4791 if (iPrecision != 0) { 4682 if (iPrecision != 0) {
4792 resultBuf.AppendChar('.'); 4683 resultBuf.AppendChar('.');
4793 } 4684 }
4794 u++; 4685 u++;
4795 i = 0; 4686 i = 0;
4796 while (u < iLength) { 4687 while (u < iLength) {
4797 if (i >= iPrecision) { 4688 if (i >= iPrecision) {
4798 break; 4689 break;
4799 } 4690 }
4800 resultBuf.AppendChar(*(pData + u)); 4691 resultBuf.AppendChar(pData[u]);
4801 ++i; 4692 ++i;
4802 ++u; 4693 ++u;
4803 } 4694 }
4804 while (i < iPrecision) { 4695 while (i < iPrecision) {
4805 resultBuf.AppendChar('0'); 4696 resultBuf.AppendChar('0');
4806 ++i; 4697 ++i;
4807 } 4698 }
4808 resultBuf.AppendChar(0); 4699 resultBuf.AppendChar(0);
4809 } 4700 }
4810 } 4701 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4842 iStart = 1; 4733 iStart = 1;
4843 } 4734 }
4844 if (iStart > iLength) { 4735 if (iStart > iLength) {
4845 iStart = iLength; 4736 iStart = iLength;
4846 } 4737 }
4847 iDelete = (int32_t)ValueToFloat(pThis, deleteValue.get()); 4738 iDelete = (int32_t)ValueToFloat(pThis, deleteValue.get());
4848 if (iDelete <= 0) { 4739 if (iDelete <= 0) {
4849 iDelete = 0; 4740 iDelete = 0;
4850 } 4741 }
4851 } 4742 }
4852 if (argc == 4) { 4743 if (argc > 3) {
4853 std::unique_ptr<CFXJSE_Value> insertValue = 4744 std::unique_ptr<CFXJSE_Value> insertValue =
4854 GetSimpleValue(pThis, args, 3); 4745 GetSimpleValue(pThis, args, 3);
4855 ValueToUTF8String(insertValue.get(), insertString); 4746 ValueToUTF8String(insertValue.get(), insertString);
4856 } 4747 }
4857 iStart -= 1; 4748 iStart -= 1;
4858 CFX_ByteTextBuf resultString; 4749 CFX_ByteTextBuf resultString;
4859 int32_t i = 0; 4750 int32_t i = 0;
4860 while (i < iStart) { 4751 while (i < iStart) {
4861 resultString.AppendChar(sourceString.GetAt(i)); 4752 resultString.AppendChar(sourceString.GetAt(i));
4862 ++i; 4753 ++i;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
4918 } 4809 }
4919 } 4810 }
4920 4811
4921 // static 4812 // static
4922 void CXFA_FM2JSContext::Uuid(CFXJSE_Value* pThis, 4813 void CXFA_FM2JSContext::Uuid(CFXJSE_Value* pThis,
4923 const CFX_ByteStringC& szFuncName, 4814 const CFX_ByteStringC& szFuncName,
4924 CFXJSE_Arguments& args) { 4815 CFXJSE_Arguments& args) {
4925 int32_t argc = args.GetLength(); 4816 int32_t argc = args.GetLength();
4926 if ((argc == 0) || (argc == 1)) { 4817 if ((argc == 0) || (argc == 1)) {
4927 int32_t iNum = 0; 4818 int32_t iNum = 0;
4928 if (argc == 1) { 4819 if (argc > 0) {
4929 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); 4820 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4930 iNum = (int32_t)ValueToFloat(pThis, argOne.get()); 4821 iNum = (int32_t)ValueToFloat(pThis, argOne.get());
4931 } 4822 }
4932 FX_GUID guid; 4823 FX_GUID guid;
4933 FX_GUID_CreateV4(&guid); 4824 FX_GUID_CreateV4(&guid);
4934 CFX_ByteString bsUId; 4825 CFX_ByteString bsUId;
4935 FX_GUID_ToString(&guid, bsUId, iNum); 4826 FX_GUID_ToString(&guid, bsUId, iNum);
4936 FXJSE_Value_SetUTF8String(args.GetReturnValue(), bsUId.AsStringC()); 4827 FXJSE_Value_SetUTF8String(args.GetReturnValue(), bsUId.AsStringC());
4937 } else { 4828 } else {
4938 ToJSContext(pThis, nullptr) 4829 ToJSContext(pThis, nullptr)
(...skipping 14 matching lines...) Expand all
4953 } else { 4844 } else {
4954 ValueToUTF8String(argOne.get(), argString); 4845 ValueToUTF8String(argOne.get(), argString);
4955 CFX_WideTextBuf upperStringBuf; 4846 CFX_WideTextBuf upperStringBuf;
4956 CFX_WideString wsArgString = 4847 CFX_WideString wsArgString =
4957 CFX_WideString::FromUTF8(argString.AsStringC()); 4848 CFX_WideString::FromUTF8(argString.AsStringC());
4958 const FX_WCHAR* pData = wsArgString.c_str(); 4849 const FX_WCHAR* pData = wsArgString.c_str();
4959 int32_t iLen = wsArgString.GetLength(); 4850 int32_t iLen = wsArgString.GetLength();
4960 int32_t i = 0; 4851 int32_t i = 0;
4961 int32_t ch = 0; 4852 int32_t ch = 0;
4962 while (i < iLen) { 4853 while (i < iLen) {
4963 ch = *(pData + i); 4854 ch = pData[i];
4964 if (ch >= 0x61 && ch <= 0x7A) { 4855 if (ch >= 0x61 && ch <= 0x7A) {
4965 ch -= 32; 4856 ch -= 32;
4966 } else if (ch >= 0xE0 && ch <= 0xFE) { 4857 } else if (ch >= 0xE0 && ch <= 0xFE) {
4967 ch -= 32; 4858 ch -= 32;
4968 } else if (ch == 0x101 || ch == 0x103 || ch == 0x105) { 4859 } else if (ch == 0x101 || ch == 0x103 || ch == 0x105) {
4969 ch -= 1; 4860 ch -= 1;
4970 } 4861 }
4971 upperStringBuf.AppendChar(ch); 4862 upperStringBuf.AppendChar(ch);
4972 ++i; 4863 ++i;
4973 } 4864 }
(...skipping 27 matching lines...) Expand all
5001 } 4892 }
5002 if (argc > 1) { 4893 if (argc > 1) {
5003 std::unique_ptr<CFXJSE_Value> identifierValue = 4894 std::unique_ptr<CFXJSE_Value> identifierValue =
5004 GetSimpleValue(pThis, args, 1); 4895 GetSimpleValue(pThis, args, 1);
5005 if (FXJSE_Value_IsNull(identifierValue.get())) { 4896 if (FXJSE_Value_IsNull(identifierValue.get())) {
5006 bFlags = TRUE; 4897 bFlags = TRUE;
5007 } else { 4898 } else {
5008 iIdentifier = (int32_t)ValueToFloat(pThis, identifierValue.get()); 4899 iIdentifier = (int32_t)ValueToFloat(pThis, identifierValue.get());
5009 } 4900 }
5010 } 4901 }
5011 if (argc == 3) { 4902 if (argc > 2) {
5012 std::unique_ptr<CFXJSE_Value> localeValue = 4903 std::unique_ptr<CFXJSE_Value> localeValue =
5013 GetSimpleValue(pThis, args, 2); 4904 GetSimpleValue(pThis, args, 2);
5014 if (FXJSE_Value_IsNull(localeValue.get())) { 4905 if (FXJSE_Value_IsNull(localeValue.get())) {
5015 bFlags = TRUE; 4906 bFlags = TRUE;
5016 } else { 4907 } else {
5017 ValueToUTF8String(localeValue.get(), localeString); 4908 ValueToUTF8String(localeValue.get(), localeString);
5018 } 4909 }
5019 } 4910 }
5020 if (!bFlags) { 4911 if (!bFlags) {
5021 if ((fNumber < 0) || (fNumber > 922337203685477550)) { 4912 if ((fNumber < 0) || (fNumber > 922337203685477550)) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
5061 iComm = 2; 4952 iComm = 2;
5062 } else if (iLength > 3) { 4953 } else if (iLength > 3) {
5063 iComm = 1; 4954 iComm = 1;
5064 } 4955 }
5065 int32_t iIndex = 0; 4956 int32_t iIndex = 0;
5066 int32_t iFirstCount = iLength % 3; 4957 int32_t iFirstCount = iLength % 3;
5067 if (iFirstCount == 0) { 4958 if (iFirstCount == 0) {
5068 iFirstCount = 3; 4959 iFirstCount = 3;
5069 } 4960 }
5070 if (iFirstCount == 3) { 4961 if (iFirstCount == 3) {
5071 if (*(pData + iIndex) != '0') { 4962 if (pData[iIndex] != '0') {
5072 strBuf << pCapUnits[*(pData + iIndex) - '0']; 4963 strBuf << pCapUnits[pData[iIndex] - '0'];
5073 strBuf << pComm[0]; 4964 strBuf << pComm[0];
5074 } 4965 }
5075 if (*(pData + iIndex + 1) == '0') { 4966 if (pData[iIndex + 1] == '0') {
5076 strBuf << pCapUnits[*(pData + iIndex + 2) - '0']; 4967 strBuf << pCapUnits[pData[iIndex + 2] - '0'];
5077 } else { 4968 } else {
5078 if (*(pData + iIndex + 1) > '1') { 4969 if (pData[iIndex + 1] > '1') {
5079 strBuf << pLastTens[*(pData + iIndex + 1) - '2']; 4970 strBuf << pLastTens[pData[iIndex + 1] - '2'];
5080 strBuf << "-"; 4971 strBuf << "-";
5081 strBuf << pUnits[*(pData + iIndex + 2) - '0']; 4972 strBuf << pUnits[pData[iIndex + 2] - '0'];
5082 } else if (*(pData + iIndex + 1) == '1') { 4973 } else if (pData[iIndex + 1] == '1') {
5083 strBuf << pTens[*(pData + iIndex + 2) - '0']; 4974 strBuf << pTens[pData[iIndex + 2] - '0'];
5084 } else if (*(pData + iIndex + 1) == '0') { 4975 } else if (pData[iIndex + 1] == '0') {
5085 strBuf << pCapUnits[*(pData + iIndex + 2) - '0']; 4976 strBuf << pCapUnits[pData[iIndex + 2] - '0'];
5086 } 4977 }
5087 } 4978 }
5088 iIndex += 3; 4979 iIndex += 3;
5089 } else if (iFirstCount == 2) { 4980 } else if (iFirstCount == 2) {
5090 if (*(pData + iIndex) == '0') { 4981 if (pData[iIndex] == '0') {
5091 strBuf << pCapUnits[*(pData + iIndex + 1) - '0']; 4982 strBuf << pCapUnits[pData[iIndex + 1] - '0'];
5092 } else { 4983 } else {
5093 if (*(pData + iIndex) > '1') { 4984 if (pData[iIndex] > '1') {
5094 strBuf << pLastTens[*(pData + iIndex) - '2']; 4985 strBuf << pLastTens[pData[iIndex] - '2'];
5095 strBuf << "-"; 4986 strBuf << "-";
5096 strBuf << pUnits[*(pData + iIndex + 1) - '0']; 4987 strBuf << pUnits[pData[iIndex + 1] - '0'];
5097 } else if (*(pData + iIndex) == '1') { 4988 } else if (pData[iIndex] == '1') {
5098 strBuf << pTens[*(pData + iIndex + 1) - '0']; 4989 strBuf << pTens[pData[iIndex + 1] - '0'];
5099 } else if (*(pData + iIndex) == '0') { 4990 } else if (pData[iIndex] == '0') {
5100 strBuf << pCapUnits[*(pData + iIndex + 1) - '0']; 4991 strBuf << pCapUnits[pData[iIndex + 1] - '0'];
5101 } 4992 }
5102 } 4993 }
5103 iIndex += 2; 4994 iIndex += 2;
5104 } else if (iFirstCount == 1) { 4995 } else if (iFirstCount == 1) {
5105 strBuf << pCapUnits[*(pData + iIndex) - '0']; 4996 strBuf << pCapUnits[pData[iIndex] - '0'];
5106 iIndex += 1; 4997 iIndex += 1;
5107 } 4998 }
5108 if (iLength > 3 && iFirstCount > 0) { 4999 if (iLength > 3 && iFirstCount > 0) {
5109 strBuf << pComm[iComm]; 5000 strBuf << pComm[iComm];
5110 --iComm; 5001 --iComm;
5111 } 5002 }
5112 while (iIndex < iLength) { 5003 while (iIndex < iLength) {
5113 if (*(pData + iIndex) != '0') { 5004 if (pData[iIndex] != '0') {
5114 strBuf << pCapUnits[*(pData + iIndex) - '0']; 5005 strBuf << pCapUnits[pData[iIndex] - '0'];
5115 strBuf << pComm[0]; 5006 strBuf << pComm[0];
5116 } 5007 }
5117 if (*(pData + iIndex + 1) == '0') { 5008 if (pData[iIndex + 1] == '0') {
5118 strBuf << pCapUnits[*(pData + iIndex + 2) - '0']; 5009 strBuf << pCapUnits[pData[iIndex + 2] - '0'];
5119 } else { 5010 } else {
5120 if (*(pData + iIndex + 1) > '1') { 5011 if (pData[iIndex + 1] > '1') {
5121 strBuf << pLastTens[*(pData + iIndex + 1) - '2']; 5012 strBuf << pLastTens[pData[iIndex + 1] - '2'];
5122 strBuf << "-"; 5013 strBuf << "-";
5123 strBuf << pUnits[*(pData + iIndex + 2) - '0']; 5014 strBuf << pUnits[pData[iIndex + 2] - '0'];
5124 } else if (*(pData + iIndex + 1) == '1') { 5015 } else if (pData[iIndex + 1] == '1') {
5125 strBuf << pTens[*(pData + iIndex + 2) - '0']; 5016 strBuf << pTens[pData[iIndex + 2] - '0'];
5126 } else if (*(pData + iIndex + 1) == '0') { 5017 } else if (pData[iIndex + 1] == '0') {
5127 strBuf << pCapUnits[*(pData + iIndex + 2) - '0']; 5018 strBuf << pCapUnits[pData[iIndex + 2] - '0'];
5128 } 5019 }
5129 } 5020 }
5130 if (iIndex < iLength - 3) { 5021 if (iIndex < iLength - 3) {
5131 strBuf << pComm[iComm]; 5022 strBuf << pComm[iComm];
5132 --iComm; 5023 --iComm;
5133 } 5024 }
5134 iIndex += 3; 5025 iIndex += 3;
5135 } 5026 }
5136 } 5027 }
5137 5028
5138 // static 5029 // static
5139 void CXFA_FM2JSContext::WordUS(const CFX_ByteStringC& szData, 5030 void CXFA_FM2JSContext::WordUS(const CFX_ByteStringC& szData,
5140 int32_t iStyle, 5031 int32_t iStyle,
5141 CFX_ByteTextBuf& strBuf) { 5032 CFX_ByteTextBuf& strBuf) {
5142 const FX_CHAR* pData = szData.c_str(); 5033 const FX_CHAR* pData = szData.c_str();
5143 int32_t iLength = szData.GetLength(); 5034 int32_t iLength = szData.GetLength();
5144 switch (iStyle) { 5035 switch (iStyle) {
5145 case 0: { 5036 case 0: {
5146 int32_t iIndex = 0; 5037 int32_t iIndex = 0;
5147 while (iIndex < iLength) { 5038 while (iIndex < iLength) {
5148 if (*(pData + iIndex) == '.') { 5039 if (pData[iIndex] == '.') {
5149 break; 5040 break;
5150 } 5041 }
5151 ++iIndex; 5042 ++iIndex;
5152 } 5043 }
5153 iLength = iIndex; 5044 iLength = iIndex;
5154 iIndex = 0; 5045 iIndex = 0;
5155 int32_t iCount = 0; 5046 int32_t iCount = 0;
5156 while (iIndex < iLength) { 5047 while (iIndex < iLength) {
5157 iCount = (iLength - iIndex) % 12; 5048 iCount = (iLength - iIndex) % 12;
5158 if (!iCount && iLength - iIndex > 0) { 5049 if (!iCount && iLength - iIndex > 0) {
5159 iCount = 12; 5050 iCount = 12;
5160 } 5051 }
5161 TrillionUS(CFX_ByteStringC(pData + iIndex, iCount), strBuf); 5052 TrillionUS(CFX_ByteStringC(pData + iIndex, iCount), strBuf);
5162 iIndex += iCount; 5053 iIndex += iCount;
5163 if (iIndex < iLength) { 5054 if (iIndex < iLength) {
5164 strBuf << " Trillion "; 5055 strBuf << " Trillion ";
5165 } 5056 }
5166 } 5057 }
5167 } break; 5058 } break;
5168 case 1: { 5059 case 1: {
5169 int32_t iIndex = 0; 5060 int32_t iIndex = 0;
5170 while (iIndex < iLength) { 5061 while (iIndex < iLength) {
5171 if (*(pData + iIndex) == '.') { 5062 if (pData[iIndex] == '.') {
5172 break; 5063 break;
5173 } 5064 }
5174 ++iIndex; 5065 ++iIndex;
5175 } 5066 }
5176 iLength = iIndex; 5067 iLength = iIndex;
5177 iIndex = 0; 5068 iIndex = 0;
5178 int32_t iCount = 0; 5069 int32_t iCount = 0;
5179 while (iIndex < iLength) { 5070 while (iIndex < iLength) {
5180 iCount = (iLength - iIndex) % 12; 5071 iCount = (iLength - iIndex) % 12;
5181 if (!iCount && iLength - iIndex > 0) { 5072 if (!iCount && iLength - iIndex > 0) {
5182 iCount = 12; 5073 iCount = 12;
5183 } 5074 }
5184 TrillionUS(CFX_ByteStringC(pData + iIndex, iCount), strBuf); 5075 TrillionUS(CFX_ByteStringC(pData + iIndex, iCount), strBuf);
5185 iIndex += iCount; 5076 iIndex += iCount;
5186 if (iIndex < iLength) { 5077 if (iIndex < iLength) {
5187 strBuf << " Trillion "; 5078 strBuf << " Trillion ";
5188 } 5079 }
5189 } 5080 }
5190 strBuf << " Dollars"; 5081 strBuf << " Dollars";
5191 } break; 5082 } break;
5192 case 2: { 5083 case 2: {
5193 int32_t iIndex = 0; 5084 int32_t iIndex = 0;
5194 while (iIndex < iLength) { 5085 while (iIndex < iLength) {
5195 if (*(pData + iIndex) == '.') { 5086 if (pData[iIndex] == '.') {
5196 break; 5087 break;
5197 } 5088 }
5198 ++iIndex; 5089 ++iIndex;
5199 } 5090 }
5200 int32_t iInteger = iIndex; 5091 int32_t iInteger = iIndex;
5201 iIndex = 0; 5092 iIndex = 0;
5202 int32_t iCount = 0; 5093 int32_t iCount = 0;
5203 while (iIndex < iInteger) { 5094 while (iIndex < iInteger) {
5204 iCount = (iInteger - iIndex) % 12; 5095 iCount = (iInteger - iIndex) % 12;
5205 if (!iCount && iLength - iIndex > 0) { 5096 if (!iCount && iLength - iIndex > 0) {
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
5821 CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr); 5712 CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr);
5822 v8::Isolate* pIsolate = pContext->GetScriptRuntime(); 5713 v8::Isolate* pIsolate = pContext->GetScriptRuntime();
5823 int32_t argc = args.GetLength(); 5714 int32_t argc = args.GetLength();
5824 if ((argc == 4) || (argc == 5)) { 5715 if ((argc == 4) || (argc == 5)) {
5825 FX_BOOL bIsStar = TRUE; 5716 FX_BOOL bIsStar = TRUE;
5826 std::unique_ptr<CFXJSE_Value> argAccessor = args.GetValue(0); 5717 std::unique_ptr<CFXJSE_Value> argAccessor = args.GetValue(0);
5827 CFX_ByteString bsAccessorName = args.GetUTF8String(1); 5718 CFX_ByteString bsAccessorName = args.GetUTF8String(1);
5828 CFX_ByteString szName = args.GetUTF8String(2); 5719 CFX_ByteString szName = args.GetUTF8String(2);
5829 int32_t iIndexFlags = args.GetInt32(3); 5720 int32_t iIndexFlags = args.GetInt32(3);
5830 int32_t iIndexValue = 0; 5721 int32_t iIndexValue = 0;
5831 if (argc == 5) { 5722 if (argc > 4) {
5832 bIsStar = FALSE; 5723 bIsStar = FALSE;
5833 std::unique_ptr<CFXJSE_Value> argIndex = args.GetValue(4); 5724 std::unique_ptr<CFXJSE_Value> argIndex = args.GetValue(4);
5834 iIndexValue = ValueToInteger(pThis, argIndex.get()); 5725 iIndexValue = ValueToInteger(pThis, argIndex.get());
5835 } 5726 }
5836 CFX_ByteString szSomExp; 5727 CFX_ByteString szSomExp;
5837 GenerateSomExpression(szName.AsStringC(), iIndexFlags, iIndexValue, bIsStar, 5728 GenerateSomExpression(szName.AsStringC(), iIndexFlags, iIndexValue, bIsStar,
5838 szSomExp); 5729 szSomExp);
5839 if (FXJSE_Value_IsArray(argAccessor.get())) { 5730 if (FXJSE_Value_IsArray(argAccessor.get())) {
5840 std::unique_ptr<CFXJSE_Value> pLengthValue(new CFXJSE_Value(pIsolate)); 5731 std::unique_ptr<CFXJSE_Value> pLengthValue(new CFXJSE_Value(pIsolate));
5841 FXJSE_Value_GetObjectProp(argAccessor.get(), "length", 5732 FXJSE_Value_GetObjectProp(argAccessor.get(), "length",
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
5969 CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr); 5860 CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr);
5970 v8::Isolate* pIsolate = pContext->GetScriptRuntime(); 5861 v8::Isolate* pIsolate = pContext->GetScriptRuntime();
5971 int32_t argc = args.GetLength(); 5862 int32_t argc = args.GetLength();
5972 if ((argc == 4) || (argc == 5)) { 5863 if ((argc == 4) || (argc == 5)) {
5973 FX_BOOL bIsStar = TRUE; 5864 FX_BOOL bIsStar = TRUE;
5974 std::unique_ptr<CFXJSE_Value> argAccessor = args.GetValue(0); 5865 std::unique_ptr<CFXJSE_Value> argAccessor = args.GetValue(0);
5975 CFX_ByteString bsAccessorName = args.GetUTF8String(1); 5866 CFX_ByteString bsAccessorName = args.GetUTF8String(1);
5976 CFX_ByteString szName = args.GetUTF8String(2); 5867 CFX_ByteString szName = args.GetUTF8String(2);
5977 int32_t iIndexFlags = args.GetInt32(3); 5868 int32_t iIndexFlags = args.GetInt32(3);
5978 int32_t iIndexValue = 0; 5869 int32_t iIndexValue = 0;
5979 if (argc == 5) { 5870 if (argc > 4) {
5980 bIsStar = FALSE; 5871 bIsStar = FALSE;
5981 std::unique_ptr<CFXJSE_Value> argIndex = args.GetValue(4); 5872 std::unique_ptr<CFXJSE_Value> argIndex = args.GetValue(4);
5982 iIndexValue = ValueToInteger(pThis, argIndex.get()); 5873 iIndexValue = ValueToInteger(pThis, argIndex.get());
5983 } 5874 }
5984 CFX_ByteString szSomExp; 5875 CFX_ByteString szSomExp;
5985 GenerateSomExpression(szName.AsStringC(), iIndexFlags, iIndexValue, bIsStar, 5876 GenerateSomExpression(szName.AsStringC(), iIndexFlags, iIndexValue, bIsStar,
5986 szSomExp); 5877 szSomExp);
5987 if (FXJSE_Value_IsArray(argAccessor.get())) { 5878 if (FXJSE_Value_IsArray(argAccessor.get())) {
5988 std::unique_ptr<CFXJSE_Value> pLengthValue(new CFXJSE_Value(pIsolate)); 5879 std::unique_ptr<CFXJSE_Value> pLengthValue(new CFXJSE_Value(pIsolate));
5989 FXJSE_Value_GetObjectProp(argAccessor.get(), "length", 5880 FXJSE_Value_GetObjectProp(argAccessor.get(), "length",
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
6882 CFX_WideString wsFormat; 6773 CFX_WideString wsFormat;
6883 pAppProvider->LoadString(iStringID, wsFormat); 6774 pAppProvider->LoadString(iStringID, wsFormat);
6884 CFX_WideString wsMessage; 6775 CFX_WideString wsMessage;
6885 va_list arg_ptr; 6776 va_list arg_ptr;
6886 va_start(arg_ptr, iStringID); 6777 va_start(arg_ptr, iStringID);
6887 wsMessage.FormatV(wsFormat.c_str(), arg_ptr); 6778 wsMessage.FormatV(wsFormat.c_str(), arg_ptr);
6888 va_end(arg_ptr); 6779 va_end(arg_ptr);
6889 FXJSE_ThrowMessage( 6780 FXJSE_ThrowMessage(
6890 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); 6781 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC());
6891 } 6782 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698