SO3Engine
ALStringCleaner.cpp
Go to the documentation of this file.
1
8#include <algorithm>
9#include <sstream>
10
11unsigned int ALStringCleaner::uids=0;
12
13ALStringCleaner::ALStringCleaner()
14{
15 // Forbiden (private). Use static functions instead.
16}
17
18bool ALStringCleaner::invalidASCIIChar(char c)
19{
20 return !(c>=0 && ((c > 44 && c < 47) || (c > 47 && c < 58) || (c > 64 && c < 91) || (c > 96 && c < 123) || (c == 95)));
21}
22
23bool ALStringCleaner::invalidCharE(char c)
24{
25 return (c == 'é' || c == 'è' || c == 'ê' || c == 'ë');
26}
27
28bool ALStringCleaner::invalidCharA(char c)
29{
30 return (c == 'à' || c == 'á' || c == 'â' || c == 'ã' || c == 'ä' || c == 'å' || c == 'æ');
31}
32
33bool ALStringCleaner::isSpace(char toTest)
34{
35 return (toTest == '\f' || toTest == '\n' || toTest == '\t' || toTest == '\r' || toTest == '\v' || toTest == 0x20);
36}
37
38std::string ALStringCleaner::cleanASCII(std::string str, bool replace, char replaceBy)
39{
40 std::string cleanString;
41 if(replace)
42 {
43 for(unsigned int n=0; n<str.size(); ++n)
44 {
45 if (invalidCharE(str[n]))
46 cleanString += 'e';
47 else if (invalidCharA(str[n]))
48 cleanString += 'a';
49 else if(invalidASCIIChar(str[n]))
50 cleanString += replaceBy;
51 else
52 cleanString += str[n];
53 }
54 }
55 else
56 {
57 for(unsigned int n=0; n<str.size(); ++n)
58 {
59 if (invalidCharE(str[n]))
60 cleanString += 'e';
61 else if (invalidCharA(str[n]))
62 cleanString += 'a';
63 else if(!invalidASCIIChar(str[n]))
64 cleanString += str[n];
65 }
66 }
67
68 return cleanString;
69}
70
71std::string ALStringCleaner::cleanSpaces(std::string str, bool replace, char replaceBy)
72{
73 std::string cleanString;
74 if(replace)
75 {
76 for(unsigned int n=0; n<str.size(); ++n)
77 {
78 if(isSpace(str[n]))
79 cleanString += replaceBy;
80 else
81 cleanString += str[n];
82 }
83 }
84 else
85 {
86 for(unsigned int n=0; n<str.size(); ++n)
87 {
88 if(!isSpace(str[n]))
89 cleanString += str[n];
90 }
91 }
92
93 return cleanString;
94}
95
97{
98 std::transform(str.begin(), str.end(), str.begin(), ::tolower);
99}
100
101unsigned int ALStringCleaner::getFirstID()
102{
103 return uids++;
104}
105
107{
108 unsigned int id = getFirstID();
109 std::stringstream ss;
110 ss << id;
111 std::string str = ss.str();
112
113 return str;
114}
115
117{
118 std::stringstream ss;
119 ss << uids;
120 std::string str = ss.str();
121
122 return str;
123}
124
126{
127 uids = 0;
128}
129
130std::string ALStringCleaner::cleanString(std::string str, bool toLower, bool clASCII, bool clSpaces, bool bUID)
131{
132 std::string cleanString = str;
133 if(toLower)
135 if (clSpaces)
137 if(clASCII)
139 if(bUID)
140 cleanString += getUID();
141
142 return cleanString;
143}
static std::string curentUID()
return the current UID WITHOUT incrementing the UID.
static void resetUID()
reset the uid to 0.
static std::string cleanASCII(std::string str, bool replace=true, char replaceBy='_')
Clean a string of non-ASCII chars, can delete or replace them.
static void toLowerCase(std::string str)
Convert a string to lower case.
static std::string getUID()
return a unique ID.
static std::string cleanSpaces(std::string str, bool replace=true, char replaceBy='_')
Clean a string of spaces, can delete or replace them.
static std::string cleanString(std::string str, bool toLower=true, bool clASCII=true, bool clSpaces=true, bool bUID=true)
Clean a string.
STBI_EXTERN unsigned long const char * str
Definition stb_image.h:1182