1 // Copyright 2017 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "fxjs/cjs_globalarrays.h"
8
9 #define GLOBAL_ARRAY(rt, name, ...) \
10 { \
11 const wchar_t* values[] = {__VA_ARGS__}; \
12 v8::Local<v8::Array> array = (rt)->NewArray(); \
13 for (size_t i = 0; i < FX_ArraySize(values); ++i) \
14 array->Set(i, (rt)->NewString(values[i])); \
15 (rt)->SetConstArray((name), array); \
16 (rt)->DefineGlobalConst( \
17 (name), [](const v8::FunctionCallbackInfo<v8::Value>& info) { \
18 CJS_Runtime* pCurrentRuntime = \
19 CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate()); \
20 if (pCurrentRuntime) \
21 info.GetReturnValue().Set(pCurrentRuntime->GetConstArray(name)); \
22 }); \
23 }
24
25 // static
DefineJSObjects(CJS_Runtime * pRuntime)26 void CJS_GlobalArrays::DefineJSObjects(CJS_Runtime* pRuntime) {
27 GLOBAL_ARRAY(pRuntime, L"RE_NUMBER_ENTRY_DOT_SEP", L"[+-]?\\d*\\.?\\d*");
28 GLOBAL_ARRAY(pRuntime, L"RE_NUMBER_COMMIT_DOT_SEP",
29 L"[+-]?\\d+(\\.\\d+)?", // -1.0 or -1
30 L"[+-]?\\.\\d+", // -.1
31 L"[+-]?\\d+\\."); // -1.
32
33 GLOBAL_ARRAY(pRuntime, L"RE_NUMBER_ENTRY_COMMA_SEP", L"[+-]?\\d*,?\\d*");
34 GLOBAL_ARRAY(pRuntime, L"RE_NUMBER_COMMIT_COMMA_SEP",
35 L"[+-]?\\d+([.,]\\d+)?", // -1,0 or -1
36 L"[+-]?[.,]\\d+", // -,1
37 L"[+-]?\\d+[.,]"); // -1,
38
39 GLOBAL_ARRAY(pRuntime, L"RE_ZIP_ENTRY", L"\\d{0,5}");
40 GLOBAL_ARRAY(pRuntime, L"RE_ZIP_COMMIT", L"\\d{5}");
41 GLOBAL_ARRAY(pRuntime, L"RE_ZIP4_ENTRY", L"\\d{0,5}(\\.|[- ])?\\d{0,4}");
42 GLOBAL_ARRAY(pRuntime, L"RE_ZIP4_COMMIT", L"\\d{5}(\\.|[- ])?\\d{4}");
43 GLOBAL_ARRAY(pRuntime, L"RE_PHONE_ENTRY",
44 // 555-1234 or 408 555-1234
45 L"\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",
46
47 // (408
48 L"\\(\\d{0,3}",
49
50 // (408) 555-1234
51 // (allow the addition of parens as an afterthought)
52 L"\\(\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",
53
54 // (408 555-1234
55 L"\\(\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",
56
57 // 408) 555-1234
58 L"\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",
59
60 // international
61 L"011(\\.|[- \\d])*");
62
63 GLOBAL_ARRAY(
64 pRuntime, L"RE_PHONE_COMMIT", L"\\d{3}(\\.|[- ])?\\d{4}", // 555-1234
65 L"\\d{3}(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", // 408 555-1234
66 L"\\(\\d{3}\\)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", // (408) 555-1234
67 L"011(\\.|[- \\d])*"); // international
68
69 GLOBAL_ARRAY(pRuntime, L"RE_SSN_ENTRY",
70 L"\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}");
71
72 GLOBAL_ARRAY(pRuntime, L"RE_SSN_COMMIT",
73 L"\\d{3}(\\.|[- ])?\\d{2}(\\.|[- ])?\\d{4}");
74 }
75