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