diff options
author | Jim Ramsay <i.am@jimramsay.com> | 2009-10-14 01:05:49 (GMT) |
---|---|---|
committer | Jim Ramsay <i.am@jimramsay.com> | 2009-10-14 01:05:49 (GMT) |
commit | 839ea523164caecd8c779e60539b78c2a748a81f (patch) | |
tree | 0019d04f27a1a258bc7a900e3cf77b916dca6493 /src/FbTk/StringUtil.cc | |
parent | 4d3aa646c1d1d1de4fdb31f938f6ea62fd5dd21e (diff) | |
parent | 8def80cec337a986b762cdbb5e2555c6da809353 (diff) | |
download | fluxbox_lack-839ea523164caecd8c779e60539b78c2a748a81f.zip fluxbox_lack-839ea523164caecd8c779e60539b78c2a748a81f.tar.bz2 |
Merge branch 'master' into argbtesting/argbargb
Conflicts:
src/FbTk/FbWindow.cc
Diffstat (limited to 'src/FbTk/StringUtil.cc')
-rw-r--r-- | src/FbTk/StringUtil.cc | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/src/FbTk/StringUtil.cc b/src/FbTk/StringUtil.cc index 7c8f91c..602211e 100644 --- a/src/FbTk/StringUtil.cc +++ b/src/FbTk/StringUtil.cc | |||
@@ -48,6 +48,11 @@ | |||
48 | #include <string.h> | 48 | #include <string.h> |
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | #ifdef HAVE_CERRNO | ||
52 | #include <cerrno> | ||
53 | #else | ||
54 | #include <errno.h> | ||
55 | #endif | ||
51 | 56 | ||
52 | #include <memory> | 57 | #include <memory> |
53 | #include <algorithm> | 58 | #include <algorithm> |
@@ -56,14 +61,62 @@ | |||
56 | using std::string; | 61 | using std::string; |
57 | using std::transform; | 62 | using std::transform; |
58 | 63 | ||
64 | namespace { | ||
65 | |||
66 | int extractLongNumber(const char* in, long long int& out) { | ||
67 | |||
68 | errno = 0; | ||
69 | |||
70 | int ret = 0; | ||
71 | char* end = 0; | ||
72 | long long int result = strtoll(in, &end, 0); | ||
73 | |||
74 | if (errno == 0 && end != in) { | ||
75 | out = result; | ||
76 | ret = 1; | ||
77 | } | ||
78 | |||
79 | return ret; | ||
80 | } | ||
81 | |||
82 | template<typename T> | ||
83 | int extractNumber(const std::string& in, T& out) { | ||
84 | |||
85 | long long int result = 0; | ||
86 | |||
87 | if (::extractLongNumber(in.c_str(), result) && out >= 0) { | ||
88 | out = static_cast<T>(result); | ||
89 | return 1; | ||
90 | } | ||
91 | |||
92 | return 0; | ||
93 | } | ||
94 | |||
95 | } | ||
96 | |||
97 | |||
59 | namespace FbTk { | 98 | namespace FbTk { |
60 | 99 | ||
61 | namespace StringUtil { | 100 | namespace StringUtil { |
62 | 101 | ||
102 | int extractNumber(const std::string& in, int& out) { | ||
103 | return ::extractNumber<int>(in, out); | ||
104 | } | ||
105 | |||
106 | int extractNumber(const std::string& in, unsigned int& out) { | ||
107 | return ::extractNumber<unsigned int>(in, out); | ||
108 | } | ||
109 | |||
110 | std::string number2String(int num) { | ||
111 | char s[128]; | ||
112 | sprintf(s, "%d", num); | ||
113 | return std::string(s); | ||
114 | } | ||
115 | |||
63 | /** | 116 | /** |
64 | Tries to find a string in another and | 117 | Tries to find a string in another and |
65 | ignoring the case of the characters | 118 | ignoring the case of the characters |
66 | Returns 0 on success else pointer to str. | 119 | Returns 0 on failure else pointer to str. |
67 | */ | 120 | */ |
68 | const char *strcasestr(const char *str, const char *ptn) { | 121 | const char *strcasestr(const char *str, const char *ptn) { |
69 | const char *s2, *p2; | 122 | const char *s2, *p2; |
@@ -142,7 +195,7 @@ string replaceString(const string &original, | |||
142 | for the position + 1 in the in-string where the "last"-char value | 195 | for the position + 1 in the in-string where the "last"-char value |
143 | was found. | 196 | was found. |
144 | */ | 197 | */ |
145 | int getStringBetween(string& out, const char *instr, const char first, const char last, | 198 | int getStringBetween(string& out, const char *instr, char first, char last, |
146 | const char *ok_chars, bool allow_nesting) { | 199 | const char *ok_chars, bool allow_nesting) { |
147 | assert(first); | 200 | assert(first); |
148 | assert(last); | 201 | assert(last); |