Joedb
9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
src
joedb
is_identifier.cpp
Go to the documentation of this file.
1
#include "
joedb/is_identifier.h
"
2
3
/////////////////////////////////////////////////////////////////////////////
4
constexpr
bool
joedb::is_letter
(
char
c)
5
/////////////////////////////////////////////////////////////////////////////
6
{
7
return
(
'a'
<= c && c <=
'z'
) || (
'A'
<= c && c <=
'Z'
);
8
}
9
10
/////////////////////////////////////////////////////////////////////////////
11
constexpr
bool
joedb::is_number
(
char
c)
12
/////////////////////////////////////////////////////////////////////////////
13
{
14
return
(
'0'
<= c && c <=
'9'
);
15
}
16
17
/////////////////////////////////////////////////////////////////////////////
18
bool
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
}
is_identifier.h
joedb::is_identifier
bool is_identifier(const std::string &s)
Definition
is_identifier.cpp:18
joedb::is_letter
constexpr bool is_letter(char c)
Definition
is_identifier.cpp:4
joedb::is_number
constexpr bool is_number(char c)
Definition
is_identifier.cpp:11
Generated by
1.9.8