source: tags/arb_5.5/TEMPLATES/inline.h

Last change on this file was 5675, checked in by westram, 17 years ago
  • removed automatic timestamps (the best they were good for, were vc-conflicts)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.2 KB
Line 
1//  ==================================================================== //
2//                                                                       //
3//    File      : inline.h                                               //
4//    Purpose   : general purpose inlined funcions                       //
5//                                                                       //
6//                                                                       //
7//  Coded by Ralf Westram (coder@reallysoft.de) in June 2002             //
8//  Copyright Department of Microbiology (Technical University Munich)   //
9//                                                                       //
10//  Visit our web site at: http://www.arb-home.de/                       //
11//                                                                       //
12//                                                                       //
13//  ==================================================================== //
14
15#ifndef INLINE_H
16#define INLINE_H
17
18#include <cctype>
19
20#ifndef __cplusplus
21// this header only works with c++
22// those functions needed by ARBDB are duplicated in adstring.c (with GBS_-prefix)
23#error inline.h may be used in C++ only
24#endif
25
26/** Like strcmp but ignoring case */
27inline int ARB_stricmp(const char *s1, const char *s2) {
28    int    cmp = 0;
29    size_t idx = 0;
30    while (!cmp) {
31        if (!s1[idx]) return s2[idx] ? -1 : 0;
32        if (!s2[idx]) return 1;
33        cmp = tolower(s1[idx]) - tolower(s2[idx]);
34        ++idx;
35    }
36    return cmp;
37}
38/** compares the beginning of two strings
39    (Note: always returns 0 if one the the strings is empty) */
40inline int ARB_strscmp(const char *s1, const char *s2) {
41    int    cmp = 0;
42    size_t idx = 0;
43    while (!cmp) {
44        if (!s1[idx] || !s2[idx]) break;
45        cmp = s1[idx] - s2[idx];
46        ++idx;
47    }
48    return cmp;
49}
50
51inline void ARB_strupper(char *s) { for (int i = 0; s[i]; ++i) s[i] = toupper(s[i]); } // strupr
52inline void ARB_strlower(char *s) { for (int i = 0; s[i]; ++i) s[i] = tolower(s[i]); } // strlwr
53
54inline unsigned char safeCharIndex(char c) { return static_cast<unsigned char>(c); }
55
56#else
57#error inline.h included twice
58#endif // INLINE_H
59
Note: See TracBrowser for help on using the repository browser.