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

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