neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
symbol.hpp
Go to the documentation of this file.
1
// symbol.hpp
2
/*
3
neoGFX Design Studio
4
Copyright(C) 2016 Leigh Johnston
5
6
This program is free software: you can redistribute it and / or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
10
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
15
16
You should have received a copy of the GNU General Public License
17
along with this program. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
#pragma once
21
22
#include <
neogfx/tools/DesignStudio/DesignStudio.hpp
>
23
#include <
neolib/core/string_utils.hpp
>
24
#include <
neogfx/tools/DesignStudio/symbol.hpp
>
25
26
namespace
neogfx::DesignStudio
27
{
28
enum class
naming_convention
29
{
30
LowerCaseSnake
,
31
MixedCaseSnake
,
32
UpperCamelCase
,
33
LowerCamelCase
,
34
Neogfx
35
};
36
37
enum class
named_entity
38
{
39
LocalVariable
,
40
ParameterVariable
,
41
MemberVariable
,
42
StaticVariable
,
43
Namespace
,
44
Function
,
45
Class
46
};
47
48
inline
bool
named_entity_is_variable
(
named_entity
aNamedEntity)
49
{
50
switch
(aNamedEntity)
51
{
52
case
named_entity::LocalVariable
:
53
case
named_entity::ParameterVariable
:
54
case
named_entity::MemberVariable
:
55
case
named_entity::StaticVariable
:
56
return
true
;
57
default
:
58
return
false
;
59
}
60
}
61
62
inline
string
to_symbol_name
(std::string
const
& aString,
naming_convention
aNamingConvention,
named_entity
aNamedEntity)
63
{
64
std::vector<std::string> tokens;
65
neolib::tokens
(aString, std::string{
" _"
}, tokens);
66
std::string symbolName;
67
switch
(aNamingConvention)
68
{
69
case
naming_convention::LowerCaseSnake
:
70
for
(
auto
& word : tokens)
71
word =
neolib::to_lower
(word);
72
break
;
73
case
naming_convention::MixedCaseSnake
:
74
case
naming_convention::UpperCamelCase
:
75
for
(
auto
& word : tokens)
76
word =
neolib::to_upper
(word.substr(0, 1)) +
neolib::to_lower
(word.substr(1));
77
break
;
78
case
naming_convention::LowerCamelCase
:
79
for
(
auto
& word : tokens)
80
if
(&word == &tokens[0])
81
word =
neolib::to_lower
(word);
82
else
83
word =
neolib::to_upper
(word.substr(0, 1)) +
neolib::to_lower
(word.substr(1));
84
break
;
85
case
naming_convention::Neogfx
:
86
if
(!
named_entity_is_variable
(aNamedEntity))
87
{
88
for
(
auto
& word : tokens)
89
word =
neolib::to_lower
(word);
90
}
91
else
92
{
93
for
(
auto
& word : tokens)
94
word =
neolib::to_upper
(word.substr(0, 1)) +
neolib::to_lower
(word.substr(1));
95
switch
(aNamedEntity)
96
{
97
case
named_entity::LocalVariable
:
98
tokens[0] =
neolib::to_lower
(tokens[0]);
99
break
;
100
case
named_entity::ParameterVariable
:
101
tokens[0] =
"a"
+ tokens[0];
102
break
;
103
case
named_entity::MemberVariable
:
104
tokens[0] =
"i"
+ tokens[0];
105
break
;
106
case
named_entity::StaticVariable
:
107
tokens[0] =
"s"
+ tokens[0];
108
break
;
109
}
110
}
111
break
;
112
}
113
for
(
auto
& word : tokens)
114
{
115
if
(!symbolName.empty() &&
116
(aNamingConvention ==
naming_convention::LowerCaseSnake
||
117
aNamingConvention ==
naming_convention::MixedCaseSnake
||
118
(aNamingConvention ==
naming_convention::Neogfx
&& !
named_entity_is_variable
(aNamedEntity))))
119
symbolName +=
'_'
;
120
symbolName += word;
121
}
122
return
symbolName;
123
}
124
}
DesignStudio.hpp
neogfx::DesignStudio
Definition
console_client.hpp:26
neogfx::DesignStudio::to_symbol_name
string to_symbol_name(std::string const &aString, naming_convention aNamingConvention, named_entity aNamedEntity)
Definition
symbol.hpp:62
neogfx::DesignStudio::named_entity_is_variable
bool named_entity_is_variable(named_entity aNamedEntity)
Definition
symbol.hpp:48
neogfx::DesignStudio::naming_convention
naming_convention
Definition
symbol.hpp:29
neogfx::DesignStudio::naming_convention::UpperCamelCase
@ UpperCamelCase
neogfx::DesignStudio::naming_convention::LowerCamelCase
@ LowerCamelCase
neogfx::DesignStudio::naming_convention::Neogfx
@ Neogfx
neogfx::DesignStudio::naming_convention::LowerCaseSnake
@ LowerCaseSnake
neogfx::DesignStudio::naming_convention::MixedCaseSnake
@ MixedCaseSnake
neogfx::DesignStudio::named_entity
named_entity
Definition
symbol.hpp:38
neogfx::DesignStudio::named_entity::ParameterVariable
@ ParameterVariable
neogfx::DesignStudio::named_entity::Function
@ Function
neogfx::DesignStudio::named_entity::LocalVariable
@ LocalVariable
neogfx::DesignStudio::named_entity::Class
@ Class
neogfx::DesignStudio::named_entity::Namespace
@ Namespace
neogfx::DesignStudio::named_entity::StaticVariable
@ StaticVariable
neogfx::DesignStudio::named_entity::MemberVariable
@ MemberVariable
neolib::tokens
FwdIter1 tokens(FwdIter1 aFirst, FwdIter1 aLast, FwdIter2 aDelimeterFirst, FwdIter2 aDelimiterLast, ResultContainer &aTokens, std::size_t aMaxTokens=0, bool aSkipEmptyTokens=true, bool aDelimeterIsSubsequence=false)
Definition
string_utils.hpp:124
neolib::to_lower
std::basic_string< CharT, Traits, Alloc > to_lower(const std::basic_string< CharT, Traits, Alloc > &aString)
Definition
string_utils.hpp:200
neolib::to_upper
std::basic_string< CharT, Traits, Alloc > to_upper(const std::basic_string< CharT, Traits, Alloc > &aString)
Definition
string_utils.hpp:214
string_utils.hpp
symbol.hpp
include
neogfx
tools
DesignStudio
symbol.hpp
Generated by
1.9.8