source: tags/svn.1.5.4/TEMPLATES/arb_str.h

Last change on this file was 8250, checked in by westram, 12 years ago
  • extracted library for Location from GENOM_IMPORT
    • removes cyclic dependency from GENOM ≠ GENOM_IMPORT
    • makes GENOM_IMPORT, GENOM and AWTI testable
  • remove duplicated dependency EDIT4→ITEMS
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.3 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
22inline int ARB_stricmp(const char *s1, const char *s2) {
23    //! Like strcmp but ignoring case
24
25    int    cmp = 0;
26    size_t idx = 0;
27    while (!cmp) {
28        if (!s1[idx]) return s2[idx] ? -1 : 0;
29        if (!s2[idx]) return 1;
30        cmp = tolower(s1[idx]) - tolower(s2[idx]);
31        ++idx;
32    }
33    return cmp;
34}
35inline int ARB_strscmp(const char *s1, const char *s2) {
36    /*! compares the beginning of two strings
37     * (Note: always returns 0 if one the the strings is empty)
38     */
39
40    int    cmp = 0;
41    size_t idx = 0;
42    while (!cmp) {
43        if (!s1[idx] || !s2[idx]) break;
44        cmp = s1[idx] - s2[idx];
45        ++idx;
46    }
47    return cmp;
48}
49
50inline void ARB_strupper(char *s) { for (int i = 0; s[i]; ++i) s[i] = toupper(s[i]); } // strupr
51inline void ARB_strlower(char *s) { for (int i = 0; s[i]; ++i) s[i] = tolower(s[i]); } // strlwr
52
53// ----------------------------------------
54// define the following inlines only if we have string
55#ifdef _GLIBCXX_STRING
56
57inline bool beginsWith(const std::string& str, const std::string& start) {
58    return str.find(start) == 0;
59}
60
61inline bool endsWith(const std::string& str, const std::string& postfix) {
62    size_t slen = str.length();
63    size_t plen = postfix.length();
64
65    if (plen>slen) { return false; }
66    return str.substr(slen-plen) == postfix;
67}
68
69#else
70
71#define beginsWith include_string_b4_arb_str_4_beginsWith
72#define endsWith include_string_b4_arb_str_4_endsWith
73
74#endif
75
76#else
77#error arb_str.h included twice
78#endif // ARB_STR_H
Note: See TracBrowser for help on using the repository browser.