summaryrefslogtreecommitdiffstats
path: root/akregator/src/mk4storage/metakit/src/std.cpp
blob: 135fe7766d6dda4bd25f0bed76019167830f2279 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// std.cpp --
// $Id$
// This is part of Metakit, the homepage is http://www.equi4.com/metakit/

/** @file
 * Implementation of STL-based strings and containers
 */

#include "header.h"

#if q4_STD // until end of source
/////////////////////////////////////////////////////////////////////////////

#include "column.h"   // c4_ColCache

#if !q4_INLINE
static char _mk4stdInl[] = "mk4str.inl";
#include "mk4str.inl"
#endif
  
#if !q4_NO_NS
using namespace std;
#endif

/////////////////////////////////////////////////////////////////////////////
// Implemented in this file

  class c4_String;

/////////////////////////////////////////////////////////////////////////////

#if !q4_MSVC && !q4_WATC

  // MS C/C++ has this handy stricmp: a case-insensitive version of strcmp
  // This version only works with 7-bit ASCII characters 0x00 through 0x7F
    
  static int stricmp(const char* p1, const char* p2)
  {
    int c1, c2;
  
#ifdef d4_USE_UNOPTIMIZED_CODE
      do
      {
        c1 = tolower(*p1++);
        c2 = tolower(*p2++);
      } while (c1 != 0 && c1 == c2);
#else
      do
      {
        c1 = *p1++;
        c2 = *p2++;
      } while (c1 != 0 && (c1 == c2 || tolower(c1) == tolower(c2)));
        
      c1 = tolower(c1);
      c2 = tolower(c2);
#endif
      
    return c1 - c2;
  }
  
#endif

/////////////////////////////////////////////////////////////////////////////
// c4_String

c4_String c4_String::Mid(int nFirst_, int nCount_) const
{
  int n = length();
  if (nFirst_ > n)
    nFirst_ = n;
  if (nFirst_ + nCount_ > n)
    nCount_ = n - nFirst_;

  return substr(nFirst_, nCount_);
}

int c4_String::CompareNoCase(const char* str_) const
{
    // this is not very "standard library-ish" ...
  return *(const string*) this == str_ ? 0 : stricmp(c_str(), str_);
}

/////////////////////////////////////////////////////////////////////////////
#endif // q4_STD