OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2009 The Native Client Authors. All rights reserved. | |
3 * Use of this source code is governed by a BSD-style license that can | |
4 * be found in the LICENSE file. | |
5 */ | |
6 | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 | |
10 #include "native_client/src/trusted/plugin/srpc/utility.h" | |
11 | |
12 namespace plugin { | |
13 | |
14 int gNaClPluginDebugPrintEnabled = -1; | |
15 | |
16 /* | |
17 * Currently only looks for presence of NACL_PLUGIN_DEBUG and returns | |
18 * 0 if absent and 1 if present. In the future we may include notions | |
19 * of verbosity level. | |
20 */ | |
21 int NaClPluginDebugPrintCheckEnv() { | |
22 char* env = getenv("NACL_PLUGIN_DEBUG"); | |
23 return (NULL != env); | |
24 } | |
25 | |
26 bool IsValidIdentifierString(const char* strval, uint32_t* length) { | |
27 // This function is supposed to recognize valid ECMAScript identifiers, | |
28 // as described in | |
29 // http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf | |
30 // It is currently restricted to only the ASCII subset. | |
31 // TODO(sehr): Recognize the full Unicode formulation of identifiers. | |
32 // TODO(sehr): Make this table-driven if efficiency becomes a problem. | |
33 if (NULL != length) { | |
34 *length = 0; | |
35 } | |
36 if (NULL == strval) { | |
37 return false; | |
38 } | |
39 static const char* kValidFirstChars = | |
40 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz$_"; | |
41 static const char* kValidOtherChars = | |
42 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz$_" | |
43 "0123456789"; | |
44 if (NULL == strchr(kValidFirstChars, strval[0])) { | |
45 return false; | |
46 } | |
47 uint32_t pos; | |
48 for (pos = 1; ; ++pos) { | |
49 if (0 == pos) { | |
50 // Unsigned overflow. | |
51 return false; | |
52 } | |
53 int c = strval[pos]; | |
54 if (0 == c) { | |
55 break; | |
56 } | |
57 if (NULL == strchr(kValidOtherChars, c)) { | |
58 return false; | |
59 } | |
60 } | |
61 if (NULL != length) { | |
62 *length = pos; | |
63 } | |
64 return true; | |
65 } | |
66 | |
67 } // namespace plugin | |
OLD | NEW |