File: ci_string.h

package info (click to toggle)
htmlcxx 0.87-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,412 kB
  • sloc: sh: 4,380; cpp: 4,355; yacc: 526; ansic: 205; lex: 159; makefile: 47; perl: 27
file content (48 lines) | stat: -rw-r--r-- 933 bytes parent folder | download
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
#ifndef __CI_STRING__
#define __CI_STRING__

#include <cctype>
#include <string>
#include <strings.h>

struct ci_char_traits : public std::char_traits<char>

// just inherit all the other functions
//  that we don't need to override
{
	static bool eq( char c1, char c2 ) {
		return tolower(c1) == tolower(c2);
	}

	static bool ne( char c1, char c2 ) {
		return tolower(c1) != tolower(c2);
	}

	static bool lt( char c1, char c2 ) {
		return tolower(c1) < tolower(c2);
	}

	static int compare( const char* s1,
			const char* s2,
			size_t n ) {
		#ifdef WIN32
		return _strnicmp(s1, s2, n);
		#else
		return strncasecmp( s1, s2, n );
		#endif
		// if available on your compiler,
		//  otherwise you can roll your own
	}

	static const char*
		find( const char* s, int n, char a ) {
			while( n-- > 0 && tolower(*s) != tolower(a) ) {
				++s;
			}
			return s;
		}
};

typedef std::basic_string<char, ci_char_traits> ci_string;

#endif