|
Last change
on this file was
10953,
checked in by westram, 12 years ago
|
- do not depend on '_GLIBCXX_STRING' for definition of inline helper functions (should fix another clang error)
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Author Date Id Revision
|
|
File size:
2.0 KB
|
| Line | |
|---|
| 1 | // ================================================================= // |
|---|
| 2 | // // |
|---|
| 3 | // File : arb_str.h // |
|---|
| 4 | // Purpose : inlined string functions // |
|---|
| 5 | // // |
|---|
| 6 | // Coded by Ralf Westram (coder@reallysoft.de) in June 2002 // |
|---|
| 7 | // Institute of Microbiology (Technical University Munich) // |
|---|
| 8 | // http://www.arb-home.de/ // |
|---|
| 9 | // // |
|---|
| 10 | // ================================================================= // |
|---|
| 11 | |
|---|
| 12 | #ifndef ARB_STR_H |
|---|
| 13 | #define ARB_STR_H |
|---|
| 14 | |
|---|
| 15 | #ifndef _GLIBCXX_CSTDDEF |
|---|
| 16 | #include <cstddef> |
|---|
| 17 | #endif |
|---|
| 18 | #ifndef _GLIBCXX_CCTYPE |
|---|
| 19 | #include <cctype> |
|---|
| 20 | #endif |
|---|
| 21 | #ifndef _GLIBCXX_CSTRING |
|---|
| 22 | #include <cstring> |
|---|
| 23 | #endif |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | inline int ARB_stricmp(const char *s1, const char *s2) { |
|---|
| 27 | //! Like strcmp but ignoring case |
|---|
| 28 | |
|---|
| 29 | int cmp = 0; |
|---|
| 30 | size_t idx = 0; |
|---|
| 31 | while (!cmp) { |
|---|
| 32 | if (!s1[idx]) return s2[idx] ? -1 : 0; |
|---|
| 33 | if (!s2[idx]) return 1; |
|---|
| 34 | cmp = tolower(s1[idx]) - tolower(s2[idx]); |
|---|
| 35 | ++idx; |
|---|
| 36 | } |
|---|
| 37 | return cmp; |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | inline bool ARB_strBeginsWith(const char *str, const char *with) { |
|---|
| 41 | /*! returns true if 'str' begins with 'with' |
|---|
| 42 | */ |
|---|
| 43 | |
|---|
| 44 | for (size_t idx = 0; with[idx]; ++idx) { |
|---|
| 45 | if (str[idx] != with[idx]) return false; |
|---|
| 46 | } |
|---|
| 47 | return true; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | inline int ARB_strNULLcmp(const char *s1, const char *s2) { |
|---|
| 51 | /*! Like strcmp, but allows NULL as arguments |
|---|
| 52 | * NULL is bigger than anything else (i.e. it sorts "missing" values to the end) |
|---|
| 53 | */ |
|---|
| 54 | return |
|---|
| 55 | s1 |
|---|
| 56 | ? (s2 ? strcmp(s1, s2) : -1) |
|---|
| 57 | : (s2 ? 1 : 0); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | inline char *ARB_strupper(char *s) { for (int i = 0; s[i]; ++i) s[i] = toupper(s[i]); return s; } // strupr |
|---|
| 62 | inline char *ARB_strlower(char *s) { for (int i = 0; s[i]; ++i) s[i] = tolower(s[i]); return s; } // strlwr |
|---|
| 63 | |
|---|
| 64 | #else |
|---|
| 65 | #error arb_str.h included twice |
|---|
| 66 | #endif // ARB_STR_H |
|---|
Note: See
TracBrowser
for help on using the repository browser.