1// std.cpp --
2// $Id: std.cpp 1230 2007-03-09 15:58:53Z jcw $
3// This is part of Metakit, the homepage is http://www.equi4.com/metakit.html
4
5/** @file
6 * Implementation of STL-based strings and containers
7 */
8
9#include "header.h"
10
11#if q4_STD // until end of source
12/////////////////////////////////////////////////////////////////////////////
13
14#include "column.h"   // c4_ColCache
15
16#if !q4_INLINE
17static char _mk4stdInl[] = "mk4str.inl";
18#include "mk4str.inl"
19#endif
20
21#if !q4_NO_NS
22using namespace std;
23#endif
24
25/////////////////////////////////////////////////////////////////////////////
26// Implemented in this file
27
28class c4_String;
29
30/////////////////////////////////////////////////////////////////////////////
31
32#if !q4_MSVC && !q4_WATC
33
34// MS C/C++ has this handy stricmp: a case-insensitive version of strcmp
35// This version only works with 7-bit ASCII characters 0x00 through 0x7F
36
37static int stricmp(const char *p1, const char *p2) {
38    int c1, c2;
39
40#ifdef d4_USE_UNOPTIMIZED_CODE
41    do {
42        c1 = tolower(*p1++);
43        c2 = tolower(*p2++);
44    } while (c1 != 0 && c1 == c2);
45#else
46    do {
47        c1 =  *p1++;
48        c2 =  *p2++;
49    } while (c1 != 0 && (c1 == c2 || tolower(c1) == tolower(c2)));
50
51    c1 = tolower(c1);
52    c2 = tolower(c2);
53#endif
54
55    return c1 - c2;
56}
57
58#endif
59
60/////////////////////////////////////////////////////////////////////////////
61// c4_String
62
63c4_String c4_String::Mid(int nFirst_, int nCount_)const {
64  int n = length();
65  if (nFirst_ > n)
66    nFirst_ = n;
67  if (nFirst_ + nCount_ > n)
68    nCount_ = n - nFirst_;
69
70  return substr(nFirst_, nCount_);
71}
72
73int c4_String::CompareNoCase(const char *str_)const {
74  // this is not very "standard library-ish" ...
75  return *(const string*)this == str_ ? 0 : stricmp(c_str(), str_);
76}
77
78/////////////////////////////////////////////////////////////////////////////
79#endif // q4_STD
80