From 1e60a61e79064b59a32e722a1a3e63ce06ca41bb Mon Sep 17 00:00:00 2001 From: Themaister Date: Mon, 7 Feb 2011 13:19:56 +0100 Subject: [PATCH] Clean up messy statics/inline. --- nall/string/base.hpp | 92 ++++++++++++++++++++--------------------- nall/string/compare.hpp | 14 +++---- nall/string/convert.hpp | 16 +++---- nall/string/match.hpp | 2 +- nall/string/math.hpp | 8 ++-- nall/string/strl.hpp | 4 +- nall/string/trim.hpp | 12 +++--- nall/string/utility.hpp | 26 ++++++------ 8 files changed, 87 insertions(+), 87 deletions(-) diff --git a/nall/string/base.hpp b/nall/string/base.hpp index 3fbad0e..21ad0ce 100644 --- a/nall/string/base.hpp +++ b/nall/string/base.hpp @@ -124,66 +124,66 @@ namespace nall { }; //compare.hpp - static inline char chrlower(char c); - static inline char chrupper(char c); - static inline int stricmp(const char *dest, const char *src); - static inline bool strbegin (const char *str, const char *key); - static inline bool stribegin(const char *str, const char *key); - static inline bool strend (const char *str, const char *key); - static inline bool striend(const char *str, const char *key); + inline char chrlower(char c); + inline char chrupper(char c); + inline int stricmp(const char *dest, const char *src); + inline bool strbegin (const char *str, const char *key); + inline bool stribegin(const char *str, const char *key); + inline bool strend (const char *str, const char *key); + inline bool striend(const char *str, const char *key); //convert.hpp - static inline char* strlower(char *str); - static inline char* strupper(char *str); - static inline char* strtr(char *dest, const char *before, const char *after); - static inline uintmax_t hex (const char *str); - static inline intmax_t integer (const char *str); - static inline uintmax_t decimal (const char *str); - static inline uintmax_t binary (const char *str); - static inline double fp (const char *str); + inline char* strlower(char *str); + inline char* strupper(char *str); + inline char* strtr(char *dest, const char *before, const char *after); + inline uintmax_t hex (const char *str); + inline intmax_t integer (const char *str); + inline uintmax_t decimal (const char *str); + inline uintmax_t binary (const char *str); + inline double fp (const char *str); //match.hpp - static inline bool match(const char *pattern, const char *str); + inline bool match(const char *pattern, const char *str); //math.hpp - static inline bool strint (const char *str, int &result); - static inline bool strmath(const char *str, int &result); + inline bool strint (const char *str, int &result); + inline bool strmath(const char *str, int &result); //strl.hpp - static inline unsigned strlcpy(char *dest, const char *src, unsigned length); - static inline unsigned strlcat(char *dest, const char *src, unsigned length); + inline unsigned strlcpy(char *dest, const char *src, unsigned length); + inline unsigned strlcat(char *dest, const char *src, unsigned length); //trim.hpp - static inline char* ltrim(char *str, const char *key = " "); - static inline char* rtrim(char *str, const char *key = " "); - static inline char* trim (char *str, const char *key = " "); - static inline char* ltrim_once(char *str, const char *key = " "); - static inline char* rtrim_once(char *str, const char *key = " "); - static inline char* trim_once (char *str, const char *key = " "); + inline char* ltrim(char *str, const char *key = " "); + inline char* rtrim(char *str, const char *key = " "); + inline char* trim (char *str, const char *key = " "); + inline char* ltrim_once(char *str, const char *key = " "); + inline char* rtrim_once(char *str, const char *key = " "); + inline char* trim_once (char *str, const char *key = " "); //utility.hpp - static inline unsigned strlcpy(string &dest, const char *src, unsigned length); - static inline unsigned strlcat(string &dest, const char *src, unsigned length); - static inline string substr(const char *src, unsigned start = 0, unsigned length = 0); - static inline string& strtr(string &dest, const char *before, const char *after); + inline unsigned strlcpy(string &dest, const char *src, unsigned length); + inline unsigned strlcat(string &dest, const char *src, unsigned length); + inline string substr(const char *src, unsigned start = 0, unsigned length = 0); + inline string& strtr(string &dest, const char *before, const char *after); - static inline string integer(intmax_t value); - template static inline string linteger(intmax_t value); - template static inline string rinteger(intmax_t value); - static inline string decimal(uintmax_t value); - template static inline string ldecimal(uintmax_t value); - template static inline string rdecimal(uintmax_t value); - template static inline string hex(uintmax_t value); - template static inline string binary(uintmax_t value); - static inline unsigned fp(char *str, double value); - static inline string fp(double value); + inline string integer(intmax_t value); + template inline string linteger(intmax_t value); + template inline string rinteger(intmax_t value); + inline string decimal(uintmax_t value); + template inline string ldecimal(uintmax_t value); + template inline string rdecimal(uintmax_t value); + template inline string hex(uintmax_t value); + template inline string binary(uintmax_t value); + inline unsigned fp(char *str, double value); + inline string fp(double value); - static inline string linteger(intmax_t value) { return linteger<0>(value); } - static inline string rinteger(intmax_t value) { return rinteger<0>(value); } - static inline string ldecimal(uintmax_t value) { return ldecimal<0>(value); } - static inline string rdecimal(uintmax_t value) { return rdecimal<0>(value); } - static inline string hex(uintmax_t value) { return hex<0>(value); } - static inline string binary(uintmax_t value) { return binary<0>(value); } + inline string linteger(intmax_t value) { return linteger<0>(value); } + inline string rinteger(intmax_t value) { return rinteger<0>(value); } + inline string ldecimal(uintmax_t value) { return ldecimal<0>(value); } + inline string rdecimal(uintmax_t value) { return rdecimal<0>(value); } + inline string hex(uintmax_t value) { return hex<0>(value); } + inline string binary(uintmax_t value) { return binary<0>(value); } //variadic.hpp template diff --git a/nall/string/compare.hpp b/nall/string/compare.hpp index c118778..49b74d7 100644 --- a/nall/string/compare.hpp +++ b/nall/string/compare.hpp @@ -3,15 +3,15 @@ namespace nall { -static inline char chrlower(char c) { +inline char chrlower(char c) { return (c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c; } -static inline char chrupper(char c) { +inline char chrupper(char c) { return (c >= 'a' && c <= 'z') ? c - ('a' - 'A') : c; } -static inline int stricmp(const char *dest, const char *src) { +inline int stricmp(const char *dest, const char *src) { while(*dest) { if(chrlower(*dest) != chrlower(*src)) break; dest++; @@ -21,14 +21,14 @@ static inline int stricmp(const char *dest, const char *src) { return (int)chrlower(*dest) - (int)chrlower(*src); } -static inline bool strbegin(const char *str, const char *key) { +inline bool strbegin(const char *str, const char *key) { int i, ssl = strlen(str), ksl = strlen(key); if(ksl > ssl) return false; return (!memcmp(str, key, ksl)); } -static inline bool stribegin(const char *str, const char *key) { +inline bool stribegin(const char *str, const char *key) { int ssl = strlen(str), ksl = strlen(key); if(ksl > ssl) return false; @@ -44,14 +44,14 @@ static inline bool stribegin(const char *str, const char *key) { return true; } -static inline bool strend(const char *str, const char *key) { +inline bool strend(const char *str, const char *key) { int ssl = strlen(str), ksl = strlen(key); if(ksl > ssl) return false; return (!memcmp(str + ssl - ksl, key, ksl)); } -static inline bool striend(const char *str, const char *key) { +inline bool striend(const char *str, const char *key) { int ssl = strlen(str), ksl = strlen(key); if(ksl > ssl) return false; diff --git a/nall/string/convert.hpp b/nall/string/convert.hpp index bf3a382..2f6a5ba 100644 --- a/nall/string/convert.hpp +++ b/nall/string/convert.hpp @@ -3,7 +3,7 @@ namespace nall { -static inline char* strlower(char *str) { +inline char* strlower(char *str) { if(!str) return 0; int i = 0; while(str[i]) { @@ -13,7 +13,7 @@ static inline char* strlower(char *str) { return str; } -static inline char* strupper(char *str) { +inline char* strupper(char *str) { if(!str) return 0; int i = 0; while(str[i]) { @@ -23,7 +23,7 @@ static inline char* strupper(char *str) { return str; } -static inline char* strtr(char *dest, const char *before, const char *after) { +inline char* strtr(char *dest, const char *before, const char *after) { if(!dest || !before || !after) return dest; int sl = strlen(dest), bsl = strlen(before), asl = strlen(after); @@ -44,7 +44,7 @@ inline string& string::lower() { nall::strlower(data); return *this; } inline string& string::upper() { nall::strupper(data); return *this; } inline string& string::transform(const char *before, const char *after) { nall::strtr(data, before, after); return *this; } -static inline uintmax_t hex(const char *str) { +inline uintmax_t hex(const char *str) { if(!str) return 0; uintmax_t result = 0; @@ -64,7 +64,7 @@ static inline uintmax_t hex(const char *str) { return result; } -static inline intmax_t integer(const char *str) { +inline intmax_t integer(const char *str) { if(!str) return 0; intmax_t result = 0; bool negate = false; @@ -85,7 +85,7 @@ static inline intmax_t integer(const char *str) { return !negate ? result : -result; } -static inline uintmax_t decimal(const char *str) { +inline uintmax_t decimal(const char *str) { if(!str) return 0; uintmax_t result = 0; @@ -99,7 +99,7 @@ static inline uintmax_t decimal(const char *str) { return result; } -static inline uintmax_t binary(const char *str) { +inline uintmax_t binary(const char *str) { if(!str) return 0; uintmax_t result = 0; @@ -117,7 +117,7 @@ static inline uintmax_t binary(const char *str) { return result; } -static inline double fp(const char *str) { +inline double fp(const char *str) { if(!str) return 0.0; bool negate = false; diff --git a/nall/string/match.hpp b/nall/string/match.hpp index d73cb53..8822d24 100644 --- a/nall/string/match.hpp +++ b/nall/string/match.hpp @@ -3,7 +3,7 @@ namespace nall { -static inline bool match(const char *p, const char *s) { +inline bool match(const char *p, const char *s) { const char *p_ = 0, *s_ = 0; for(;;) { diff --git a/nall/string/math.hpp b/nall/string/math.hpp index c21e762..496315f 100644 --- a/nall/string/math.hpp +++ b/nall/string/math.hpp @@ -3,7 +3,7 @@ namespace nall { -static int eval_integer(const char *&s) { +inline int eval_integer(const char *&s) { if(!*s) throw "unrecognized_integer"; int value = 0, x = *s, y = *(s + 1); @@ -57,7 +57,7 @@ static int eval_integer(const char *&s) { throw "unrecognized_integer"; } -static int eval(const char *&s, int depth = 0) { +inline int eval(const char *&s, int depth = 0) { while(*s == ' ' || *s == '\t') s++; //trim whitespace if(!*s) throw "unrecognized_token"; int value = 0, x = *s, y = *(s + 1); @@ -139,7 +139,7 @@ static int eval(const char *&s, int depth = 0) { return value; } -static inline bool strint(const char *s, int &result) { +inline bool strint(const char *s, int &result) { try { result = eval_integer(s); return true; @@ -149,7 +149,7 @@ static inline bool strint(const char *s, int &result) { } } -static inline bool strmath(const char *s, int &result) { +inline bool strmath(const char *s, int &result) { try { result = eval(s); return true; diff --git a/nall/string/strl.hpp b/nall/string/strl.hpp index 813d008..1c90c1c 100644 --- a/nall/string/strl.hpp +++ b/nall/string/strl.hpp @@ -6,7 +6,7 @@ namespace nall { //strlcpy, strlcat based on OpenBSD implementation by Todd C. Miller //return = strlen(src) -static inline unsigned strlcpy(char *dest, const char *src, unsigned length) { +inline unsigned strlcpy(char *dest, const char *src, unsigned length) { char *d = dest; const char *s = src; unsigned n = length; @@ -24,7 +24,7 @@ static inline unsigned strlcpy(char *dest, const char *src, unsigned length) { } //return = strlen(src) + min(length, strlen(dest)) -static inline unsigned strlcat(char *dest, const char *src, unsigned length) { +inline unsigned strlcat(char *dest, const char *src, unsigned length) { char *d = dest; const char *s = src; unsigned n = length; diff --git a/nall/string/trim.hpp b/nall/string/trim.hpp index c852440..f048626 100644 --- a/nall/string/trim.hpp +++ b/nall/string/trim.hpp @@ -3,7 +3,7 @@ namespace nall { -static inline char* ltrim(char *str, const char *key) { +inline char* ltrim(char *str, const char *key) { if(!key || !*key) return str; while(strbegin(str, key)) { char *dest = str, *src = str + strlen(key); @@ -16,17 +16,17 @@ static inline char* ltrim(char *str, const char *key) { return str; } -static inline char* rtrim(char *str, const char *key) { +inline char* rtrim(char *str, const char *key) { if(!key || !*key) return str; while(strend(str, key)) str[strlen(str) - strlen(key)] = 0; return str; } -static inline char* trim(char *str, const char *key) { +inline char* trim(char *str, const char *key) { return ltrim(rtrim(str, key), key); } -static inline char* ltrim_once(char *str, const char *key) { +inline char* ltrim_once(char *str, const char *key) { if(!key || !*key) return str; if(strbegin(str, key)) { char *dest = str, *src = str + strlen(key); @@ -39,13 +39,13 @@ static inline char* ltrim_once(char *str, const char *key) { return str; } -static inline char* rtrim_once(char *str, const char *key) { +inline char* rtrim_once(char *str, const char *key) { if(!key || !*key) return str; if(strend(str, key)) str[strlen(str) - strlen(key)] = 0; return str; } -static inline char* trim_once(char *str, const char *key) { +inline char* trim_once(char *str, const char *key) { return ltrim_once(rtrim_once(str, key), key); } diff --git a/nall/string/utility.hpp b/nall/string/utility.hpp index 56e1e53..f0bd1b4 100644 --- a/nall/string/utility.hpp +++ b/nall/string/utility.hpp @@ -3,17 +3,17 @@ namespace nall { -unsigned strlcpy(string &dest, const char *src, unsigned length) { +inline unsigned strlcpy(string &dest, const char *src, unsigned length) { dest.reserve(length); return strlcpy(dest(), src, length); } -unsigned strlcat(string &dest, const char *src, unsigned length) { +inline unsigned strlcat(string &dest, const char *src, unsigned length) { dest.reserve(length); return strlcat(dest(), src, length); } -string substr(const char *src, unsigned start, unsigned length) { +inline string substr(const char *src, unsigned start, unsigned length) { string dest; if(length == 0) { //copy entire string @@ -27,7 +27,7 @@ string substr(const char *src, unsigned start, unsigned length) { /* arithmetic <> string */ -string integer(intmax_t value) { +inline string integer(intmax_t value) { bool negative = value < 0; if(negative) value = abs(value); @@ -53,7 +53,7 @@ string integer(intmax_t value) { return &result[0]; } -template string linteger(intmax_t value) { +template inline string linteger(intmax_t value) { bool negative = value < 0; if(negative) value = abs(value); @@ -79,7 +79,7 @@ template string linteger(intmax_t value) { return result; } -template string rinteger(intmax_t value) { +template inline string rinteger(intmax_t value) { bool negative = value < 0; if(negative) value = abs(value); @@ -105,7 +105,7 @@ template string rinteger(intmax_t value) { return result; } -string decimal(uintmax_t value) { +inline string decimal(uintmax_t value) { char buffer[64]; unsigned size = 0; @@ -127,7 +127,7 @@ string decimal(uintmax_t value) { return &result[0]; } -template string ldecimal(uintmax_t value) { +template inline string ldecimal(uintmax_t value) { char buffer[64]; unsigned size = 0; @@ -149,7 +149,7 @@ template string ldecimal(uintmax_t value) { return &result[0]; } -template string rdecimal(uintmax_t value) { +template inline string rdecimal(uintmax_t value) { char buffer[64]; unsigned size = 0; @@ -171,7 +171,7 @@ template string rdecimal(uintmax_t value) { return &result[0]; } -template string hex(uintmax_t value) { +template inline string hex(uintmax_t value) { string output; unsigned offset = 0; @@ -195,7 +195,7 @@ template string hex(uintmax_t value) { return &output[0]; } -template string binary(uintmax_t value) { +template inline string binary(uintmax_t value) { string output; unsigned offset = 0; @@ -220,7 +220,7 @@ template string binary(uintmax_t value) { //using sprintf is certainly not the most ideal method to convert //a double to a string ... but attempting to parse a double by //hand, digit-by-digit, results in subtle rounding errors. -unsigned fp(char *str, double value) { +inline unsigned fp(char *str, double value) { char buffer[256]; sprintf(buffer, "%f", value); @@ -241,7 +241,7 @@ unsigned fp(char *str, double value) { return length + 1; } -string fp(double value) { +inline string fp(double value) { string temp; temp.reserve(fp(0, value)); fp(temp(), value);