libcopp 2.3.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cmd_option_string.h
Go to the documentation of this file.
1#ifndef UTIL_CLI_CMDOPTION_STRING_H
2#define UTIL_CLI_CMDOPTION_STRING_H
3
4#pragma once
5
10#include <algorithm>
11#include <string>
12
13namespace util {
14namespace cli {
18template <typename Tc>
19struct ci_char_traits : public std::char_traits<Tc> {
20 static bool eq(Tc left, Tc right) { return toupper(left) == toupper(right); }
21 static bool lt(Tc left, Tc right) { return toupper(left) < toupper(right); }
22
23 static int compare(const Tc *left, const Tc *right, size_t n) {
24 while (n-- > 0) {
25 char cl = (Tc)toupper(*left), cr = (Tc)toupper(*right);
26 if (cl < cr)
27 return -1;
28 else if (cl > cr)
29 return 1;
30
31 ++left, ++right;
32 }
33 return 0;
34 }
35
36 static const Tc *find(const char *s, int n, Tc a) {
37 while (n-- > 0 && toupper(*s) != toupper(a)) ++s;
38 return n >= 0 ? s : 0;
39 }
40};
41
42// 类型重定义
43typedef std::basic_string<char, ci_char_traits<char> > cmd_option_ci_string;
44} // namespace cli
45} // namespace util
46#endif
std::basic_string< char, ci_char_traits< char > > cmd_option_ci_string
static const Tc * find(const char *s, int n, Tc a)
static int compare(const Tc *left, const Tc *right, size_t n)
static bool eq(Tc left, Tc right)
static bool lt(Tc left, Tc right)