Debian Codegraph @

js/src/util/Identifier.h

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef util_Identifier_h
8 #define util_Identifier_h
9
10 #include <stddef.h> // size_t
11
12 #include "js/TypeDecls.h" // JS::Latin1Char
13
14 class JSLinearString;
15
16 namespace js {
17
18 /*
19 * True if str consists of an IdentifierStart character, followed by one or
20 * more IdentifierPart characters, i.e. it matches the IdentifierName production
21 * in the language spec.
22 *
23 * This returns true even if str is a keyword like "if".
24 */
25 bool IsIdentifier(const JSLinearString* str);
26
27 /*
28 * As above, but taking chars + length.
29 */
30 bool IsIdentifier(const JS::Latin1Char* chars, size_t length);
31 bool IsIdentifier(const char16_t* chars, size_t length);
32
33 /*
34 * ASCII variant with known length.
35 */
36 bool IsIdentifierASCII(char c);
37 bool IsIdentifierASCII(char c1, char c2);
38
39 /*
40 * True if str consists of an optional leading '#', followed by an
41 * IdentifierStart character, followed by one or more IdentifierPart characters,
42 * i.e. it matches the IdentifierName production or PrivateIdentifier production
43 * in the language spec.
44 *
45 * This returns true even if str is a keyword like "if".
46 */
47 bool IsIdentifierNameOrPrivateName(const JSLinearString* str);
48
49 /*
50 * As above, but taking chars + length.
51 */
52 bool IsIdentifierNameOrPrivateName(const JS::Latin1Char* chars, size_t length);
53 bool IsIdentifierNameOrPrivateName(const char16_t* chars, size_t length);
54
55 } /* namespace js */
56
57 #endif /* util_Identifier_h */