Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
StringHelper.cpp
Go to the documentation of this file.
1
2
4
6
7namespace Divide::Util {
8
9namespace detail
10{
12} //namespace detail
13
14bool FindCommandLineArgument(const int argc, char** argv, const char* target_arg, const char* arg_prefix)
15{
16 string tempArg(arg_prefix);
17 tempArg += target_arg;
18 const char* target = tempArg.c_str();
19
20 for (int i = 0; i < argc; ++i) {
21 if (strcasecmp(argv[i], target) == 0) {
22 return true;
23 }
24 }
25 return false;
26}
27
28bool ExtractStartupProject( int argc, char** argv, string& projectOut, const char* arg_prefix)
29{
30 string tempArg( arg_prefix );
31
32 for(int i = 0; i < argc; ++i)
33 {
34 if (auto m = ctre::match<Paths::g_useProjectPattern>(argv[i]))
35 {
36 projectOut = m.get<2>();
37 return true;
38 }
39 }
40
41 return false;
42}
43
44bool IsNumber(const char* s) {
45 F32 number = 0.0f;
46 if (istringstream(s) >> number) {
47 return !(IS_ZERO(number) && s[0] != 0);
48 }
49 return false;
50}
51
52void CStringRemoveChar(char* str, const char charToRemove) noexcept {
53 char *pr = str, *pw = str;
54 while (*pr) {
55 *pw = *pr++;
56 pw += *pw != charToRemove;
57 }
58 *pw = '\0';
59}
60
61bool IsEmptyOrNull(const char* str) noexcept {
62 return str == nullptr || str[0] == '\0';
63}
64
65//ref: http://c-faq.com/stdio/commaprint.html
66char *commaprint(U64 number) noexcept {
67 static int comma = '\0';
68 static char retbuf[30];
69 char *p = &retbuf[sizeof(retbuf) - 1];
70 int i = 0;
71
72 if (comma == '\0') {
73 struct lconv *lcp = localeconv();
74 if (lcp != nullptr) {
75 if (lcp->thousands_sep != nullptr &&
76 *lcp->thousands_sep != '\0')
77 comma = *lcp->thousands_sep;
78 else comma = ',';
79 }
80 }
81
82 *p = '\0';
83
84 do {
85 if (i % 3 == 0 && i != 0)
86 *--p = (char)comma;
87 *--p = '0' + number % 10;
88 number /= 10;
89 i++;
90 } while (number != 0);
91
92 return p;
93}
94
95} //namespace Divide::Util
#define strcasecmp
mi_stl_allocator< T > dvd_allocator
char * argv[]
Definition: main.cpp:8
dvd_allocator< char > s_allocator
bool ExtractStartupProject(int argc, char **argv, string &projectOut, const char *arg_prefix="--")
bool IsEmptyOrNull(const char *str) noexcept
void CStringRemoveChar(char *str, char charToRemove) noexcept
bool FindCommandLineArgument(int argc, char **argv, const char *target_arg, const char *arg_prefix="--")
bool IsNumber(const T_str &s)
char * commaprint(U64 number) noexcept
bool IS_ZERO(const T X) noexcept
std::basic_istringstream< char, std::char_traits< char >, dvd_allocator< char > > istringstream
Definition: STLString.h:47
uint64_t U64