libcopp  2.2.0
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 
13 namespace util {
14 namespace cli {
18 template <typename Tc>
19 struct 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 // 类型重定义
43 typedef 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 TCH toupper(TCH c)
字符转大写
Definition: string_oprs.h:85
static int compare(const Tc *left, const Tc *right, size_t n)
static bool eq(Tc left, Tc right)
static const Tc * find(const char *s, int n, Tc a)
static bool lt(Tc left, Tc right)