libcopp  1.2.1
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))
38  ++s;
39  return n >= 0 ? s : 0;
40  }
41  };
42 
43  // 类型重定义
44  typedef std::basic_string<char, ci_char_traits<char> > cmd_option_ci_string;
45  } // namespace cli
46 } // namespace util
47 #endif
static const Tc * find(const char *s, int n, Tc a)
static bool lt(Tc left, Tc right)
static TCH toupper(TCH c)
字符转大写
Definition: string_oprs.h:84
static int compare(const Tc *left, const Tc *right, size_t n)
static bool eq(Tc left, Tc right)
std::basic_string< char, ci_char_traits< char > > cmd_option_ci_string