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
25
27{
36
47
48 inline bool named_entity_is_variable(named_entity aNamedEntity)
49 {
50 switch (aNamedEntity)
51 {
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 {
70 for (auto& word : tokens)
71 word = neolib::to_lower(word);
72 break;
75 for (auto& word : tokens)
76 word = neolib::to_upper(word.substr(0, 1)) + neolib::to_lower(word.substr(1));
77 break;
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;
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 {
98 tokens[0] = neolib::to_lower(tokens[0]);
99 break;
101 tokens[0] = "a" + tokens[0];
102 break;
104 tokens[0] = "i" + tokens[0];
105 break;
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}
string to_symbol_name(std::string const &aString, naming_convention aNamingConvention, named_entity aNamedEntity)
Definition symbol.hpp:62
bool named_entity_is_variable(named_entity aNamedEntity)
Definition symbol.hpp:48
FwdIter1 tokens(FwdIter1 aFirst, FwdIter1 aLast, FwdIter2 aDelimeterFirst, FwdIter2 aDelimiterLast, ResultContainer &aTokens, std::size_t aMaxTokens=0, bool aSkipEmptyTokens=true, bool aDelimeterIsSubsequence=false)
std::basic_string< CharT, Traits, Alloc > to_lower(const std::basic_string< CharT, Traits, Alloc > &aString)
std::basic_string< CharT, Traits, Alloc > to_upper(const std::basic_string< CharT, Traits, Alloc > &aString)