Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
is_identifier.cpp
Go to the documentation of this file.
2
3/////////////////////////////////////////////////////////////////////////////
4constexpr bool joedb::is_letter(char c)
5/////////////////////////////////////////////////////////////////////////////
6{
7 return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
8}
9
10/////////////////////////////////////////////////////////////////////////////
11constexpr bool joedb::is_number(char c)
12/////////////////////////////////////////////////////////////////////////////
13{
14 return ('0' <= c && c <= '9');
15}
16
17/////////////////////////////////////////////////////////////////////////////
18bool joedb::is_identifier(const std::string &s)
19/////////////////////////////////////////////////////////////////////////////
20{
21 if (s.empty())
22 return false;
23
24 if (is_number(s[0]))
25 return false;
26
27 char previous = 0;
28 for (const char c: s)
29 {
30 if (c != '_' && !is_letter(c) && !is_number(c))
31 return false;
32 if (c == '_' && previous == '_')
33 return false;
34 previous = c;
35 }
36
37 return true;
38}
bool is_identifier(const std::string &s)
constexpr bool is_letter(char c)
constexpr bool is_number(char c)