31#include <OgreString.h>
32#include <OgreStringConverter.h>
42 if (((
Real)Number / 2) ==
int((
Real)Number / 2))
52 if (character > 47 && character < 58)
65bool IsNumeric(
const std::string &
string,
int &number)
75bool IsNumeric(
const std::string &
string,
float &number)
82 number = (float)std::strtod(
string.c_str(), &end);
84 number = std::strtof(
string.c_str(), &end);
87 return end != 0 && *end == 0;
90bool IsNumeric(
const std::string &
string,
double &number)
96 number = std::strtod(
string.c_str(), &end);
98 return end != 0 && *end == 0;
112 return radians * (180 /
pi);
118 return degrees * (
pi / 180);
124 if (a <= b && a <= c)
126 if (b <= a && b <= c)
134 if (a >= b && a >= c)
136 if (b >= a && b >= c)
144 if (a <= b && a <= c && a <= d)
146 if (b <= a && b <= c && b <= d)
148 if (c <= a && c <= b && c <= d)
156 if (a >= b && a >= c && a >= d)
158 if (b >= a && b >= c && b >= d)
160 if (c >= a && c >= b && c >= d)
172void SetCase(std::string &
string,
bool uppercase)
175 if (uppercase ==
true)
176 std::transform(
string.begin(),
string.end(),
string.begin(), ::toupper);
178 std::transform(
string.begin(),
string.end(),
string.begin(), ::tolower);
181int FindWithCase(
const std::string &
string,
bool uppercase,
const std::string &key,
int offset)
184 std::string newstring =
SetCaseCopy(
string, uppercase);
185 return (
int)newstring.find(key, offset);
191 Ogre::StringUtil::trim(
string,
true,
true);
197 Ogre::StringUtil::trim(
string,
true,
true);
201void ReplaceAll(std::string &
string,
const std::string &original,
const std::string &replacement)
209 position =
string.find(original, position);
210 if (position ==
string.npos)
212 string.replace(position, strlen(original.c_str()), replacement);
216bool StartsWith(
const std::string &
string,
const std::string &check_string,
bool ignore_case)
220 if (ignore_case ==
true)
222 std::string lower =
string.substr(0, check_string.size());
230 if (
string.substr(0, check_string.size()) == check_string)
239 return StartsWith(
string, check_string,
true);
242void SplitString(std::vector<std::string> &dest_array,
const std::string &original_string,
char separator)
248 std::string newstring;
251 std::string original = original_string;
254 endpos = original.find_first_of(separator, startpos);
255 if (endpos == std::string::npos)
257 newstring = original.substr(startpos, endpos - startpos);
259 dest_array.emplace_back(newstring);
262 while (endpos != std::string::npos)
264 newstring = original.substr(startpos, endpos - startpos);
266 dest_array.emplace_back(newstring);
267 startpos = endpos + 1;
268 endpos = original.find_first_of(separator, startpos);
269 if(endpos == std::string::npos)
272 newstring = original.substr(startpos);
274 dest_array.emplace_back(newstring);
282#if defined(__VISUALC__)
283 _snprintf_s(buffer,
sizeof(buffer), 13,
"%d", number);
285 snprintf(buffer,
sizeof(buffer),
"%d", number);
293#if defined(__VISUALC__)
294 _snprintf_s(buffer,
sizeof(buffer), 13,
"%g", number);
296 snprintf(buffer,
sizeof(buffer),
"%g", (
double)number);
304#if defined(__VISUALC__)
305 _snprintf_s(buffer,
sizeof(buffer), 13,
"%g", number);
307 snprintf(buffer,
sizeof(buffer),
"%g", number);
312#if defined(__VISUALC__)
316#if defined(__VISUALC__)
317 _snprintf_s(buffer,
sizeof(buffer), 13,
"%lu", number);
319 snprintf(buffer,
sizeof(buffer),
"%lu", number);
328#if defined(__VISUALC__)
329 _snprintf_s(buffer,
sizeof(buffer), 13,
"%lu", number);
331 snprintf(buffer,
sizeof(buffer),
"%lu", number);
338 return logf(number) / logf(2.0f);
343 return log(number) / log(2.0);
346float Round(
float number,
int decimal_places)
350 if (decimal_places <= 0)
351 return floorf(number + 0.5f);
353 float multiplier = powf(10.0f, (
float)decimal_places);
354 float rounded = floorf((number * multiplier) + 0.5f) / multiplier;
358double Round(
double number,
int decimal_places)
362 if (decimal_places <= 0)
363 return floor(number + 0.5);
365 double multiplier = pow(10.0, decimal_places);
366 double rounded = floor((number * multiplier) + 0.5) / multiplier;
375 result.x =
Round(value.x, decimal_places);
376 result.y =
Round(value.y, decimal_places);
377 result.z =
Round(value.z, decimal_places);
386 result.x =
Round(value.x, decimal_places);
387 result.y =
Round(value.y, decimal_places);
394 return (
string ==
"true" ||
string ==
"false");
399 return atof(
string.c_str());
404 return atoi(
string.c_str());
411 if (
string ==
"true")
420 if ((
int)value == value)
423 std::stringstream buffer;
424 buffer.precision(decimals);
425 buffer << std::fixed << value;
434 if ((
int)value == value)
437 std::stringstream buffer;
438 buffer.precision(decimals);
439 buffer << std::fixed << value;
448 std::string number = value;
453 int decimal = number.find(
".");
457 number.erase(decimal + decimals + 1);
458 if (number.at(number.length() - 1) ==
'.')
459 number = number.substr(0, number.length() - 1);
bool IsBoolean(std::string string)
Real DegreesToRadians(Real degrees)
bool StartsWithNoCase(const std::string &string, const std::string &check_string)
std::string TruncateNumber(float value, int decimals)
int FindWithCase(const std::string &string, bool uppercase, const std::string &key, int offset)
void SplitString(std::vector< std::string > &dest_array, const std::string &original_string, char separator)
Real Min(Real a, Real b, Real c)
void ReplaceAll(std::string &string, const std::string &original, const std::string &replacement)
int ToInt(const std::string &string)
Real Max(Real a, Real b, Real c)
void SetCase(std::string &string, bool uppercase)
std::string ToString(int number)
float Round(float number, int decimal_places)
std::string SetCaseCopy(std::string string, bool uppercase)
Real ToFloat(const std::string &string)
bool IsNumeric(char character)
bool StartsWith(const std::string &string, const std::string &check_string, bool ignore_case)
std::string BoolToString(bool item)
void TrimString(std::string &string)
std::string TrimStringCopy(std::string string)
bool ToBool(std::string string)
Real RadiansToDegrees(Real radians)