Subversion Repositories tpanel

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 21
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (C) 2020 by Andreas Theofilu <andreas@theosys.at>
2
 * Copyright (C) 2020, 2021 by Andreas Theofilu <andreas@theosys.at>
3
 *
3
 *
4
 * This program is free software; you can redistribute it and/or modify
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
7
 * (at your option) any later version.
Line 26... Line 26...
26
 
26
 
27
using namespace std;
27
using namespace std;
28
 
28
 
29
std::string TNameFormat::mStr;
29
std::string TNameFormat::mStr;
30
 
30
 
-
 
31
/**
-
 
32
 * @brief TNameFormat::TNameFormat constructor
-
 
33
 */
31
TNameFormat::TNameFormat()
34
TNameFormat::TNameFormat()
32
{
35
{
33
	DECL_TRACER("TNameFormat::TNameFormat()");
36
	DECL_TRACER("TNameFormat::TNameFormat()");
34
}
37
}
35
 
38
 
-
 
39
/**
-
 
40
 * @brief TNameFormat::~TNameFormat destructor
-
 
41
 */
36
TNameFormat::~TNameFormat()
42
TNameFormat::~TNameFormat()
37
{
43
{
38
	DECL_TRACER("TNameFormat::~TNameFormat()");
44
	DECL_TRACER("TNameFormat::~TNameFormat()");
39
}
45
}
40
 
46
 
-
 
47
/**
-
 
48
 * @brief TNameFormat::toValidName filters invalid characters.
-
 
49
 *
-
 
50
 * This method filters a string for invalid characters. Allowed are all
-
 
51
 * characters between 0 to 9, a to z, A to Z and the underline(_). All other
-
 
52
 * characters will be filtered out.
-
 
53
 *
-
 
54
 * @param str   The string to filter
-
 
55
 * @return A string containing only the valid characters.
-
 
56
 */
41
string TNameFormat::toValidName(string& str)
57
string TNameFormat::toValidName(string& str)
42
{
58
{
43
	DECL_TRACER("TNameFormat::toValidName(string& str)");
59
	DECL_TRACER("TNameFormat::toValidName(string& str)");
44
	string ret;
60
	string ret;
45
 
61
 
Line 54... Line 70...
54
	}
70
	}
55
 
71
 
56
	return ret;
72
	return ret;
57
}
73
}
58
 
74
 
-
 
75
/**
-
 
76
 * @brief TNameFormat::cutNumbers filters everything but digit symbols.
-
 
77
 *
-
 
78
 * This method filters a string for digits. It filters out all characters
-
 
79
 * except digits.
-
 
80
 *
-
 
81
 * @param str   String to filter.
-
 
82
 * @return A string containing only digits or an empty string if there were
-
 
83
 * no digits in \p str.
-
 
84
 */
59
string TNameFormat::cutNumbers(string& str)
85
string TNameFormat::cutNumbers(string& str)
60
{
86
{
61
	DECL_TRACER("TNameFormat::cutNumbers(string& str)");
87
	DECL_TRACER("TNameFormat::cutNumbers(string& str)");
62
	string ret;
88
	string ret;
63
 
89
 
Line 72... Line 98...
72
	}
98
	}
73
 
99
 
74
	return ret;
100
	return ret;
75
}
101
}
76
 
102
 
-
 
103
/**
-
 
104
 * @brief TNameFormat::toShortName filters a sequence starting with a blank and ends with a dot.
-
 
105
 *
-
 
106
 * This method filters any sequence starting with one or more blanks (' ') and
-
 
107
 * end with a dot (.).
-
 
108
 *
-
 
109
 * @param str   The string to filter
-
 
110
 * @return A string containing no sequence equal (" .");
-
 
111
 */
77
string TNameFormat::toShortName(string& str)
112
string TNameFormat::toShortName(string& str)
78
{
113
{
79
	DECL_TRACER("TNameFormat::toShortName(string& str)");
114
	DECL_TRACER("TNameFormat::toShortName(string& str)");
80
	string ret;
115
	string ret;
81
	bool ignore = false;
116
	bool ignore = false;
Line 95... Line 130...
95
	}
130
	}
96
 
131
 
97
	return ret;
132
	return ret;
98
}
133
}
99
 
134
 
-
 
135
/**
-
 
136
 * @brief TNameFormat::transFontName Replaces blanks and percent to unterline.
-
 
137
 *
-
 
138
 * This method replaces every blank (' ') and percent (%) with an underline (_).
-
 
139
 * Then the seuqence **.ttf** is replace by **.woff**.
-
 
140
 *
-
 
141
 * @param str   The string to evaluate
-
 
142
 * @return A filtered string.
-
 
143
 */
100
string TNameFormat::transFontName(string& str)
144
string TNameFormat::transFontName(string& str)
101
{
145
{
102
	DECL_TRACER("TNameFormat::transFontName(string& str)");
146
	DECL_TRACER("TNameFormat::transFontName(string& str)");
103
	string ret;
147
	string ret;
104
 
148
 
Line 114... Line 158...
114
 
158
 
115
	replace(ret, ".ttf", ".woff");
159
	replace(ret, ".ttf", ".woff");
116
	return ret;
160
	return ret;
117
}
161
}
118
 
162
 
-
 
163
/**
-
 
164
 * @brief TNameFormat::toURL converts a URL into a safe URL.
-
 
165
 *
-
 
166
 * This method filters a URL in a way, that all possible dangerous characters
-
 
167
 * are replaced by a percent (%) and the byte value.
-
 
168
 *
-
 
169
 * @param str   An URL to evaluate
-
 
170
 * @return A safe URL.
-
 
171
 */
119
string TNameFormat::toURL(string& str)
172
string TNameFormat::toURL(string& str)
120
{
173
{
121
	DECL_TRACER("TNameFormat::toURL(string& str)");
174
	DECL_TRACER("TNameFormat::toURL(string& str)");
122
	string ret;
175
	string ret;
123
 
176
 
Line 139... Line 192...
139
	}
192
	}
140
 
193
 
141
	return ret;
194
	return ret;
142
}
195
}
143
 
196
 
-
 
197
/**
-
 
198
 * @brief TNameFormat::EncodeTo convert into another character set.
-
 
199
 *
-
 
200
 * This method takes a string and converts it into another character set.
-
 
201
 *
-
 
202
 * @param buf   A pointer to a buffer large enough to hold the result.
-
 
203
 * @param len   The length of the buffer \p buf.
-
 
204
 * @param str   A pointer to a string. The content will be converted.
-
 
205
 * @param from  The name of the character set in \p str.
-
 
206
 * @param to    The name of the target charcter set.
-
 
207
 * @return The pointer \p buf. This buffer is filled up to the length of \p str
-
 
208
 * or the zero byte. Whichever comes first.
-
 
209
 */
144
char *TNameFormat::EncodeTo(char* buf, size_t *len, const string& str, const string& from, const string& to)
210
char *TNameFormat::EncodeTo(char* buf, size_t *len, const string& str, const string& from, const string& to)
145
{
211
{
146
	DECL_TRACER("TNameFormat::EncodeTo(char* buf, size_t *len, const string& str, const string& from, const string& to)");
212
	DECL_TRACER("TNameFormat::EncodeTo(char* buf, size_t *len, const string& str, const string& from, const string& to)");
147
 
213
 
148
	if (!buf || str.empty())
214
	if (!buf || str.empty())