Jpp  18.0.0-rc.3
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JWhiteSpacesFacet.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JWHITESPACESFACET__
2 #define __JLANG__JWHITESPACESFACET__
3 
4 #include <locale>
5 #include <string>
6 
7 
8 /**
9  * \author mdejong
10  */
11 
12 namespace JLANG {}
13 namespace JPP { using namespace JLANG; }
14 
15 namespace JLANG {
16 
17 
18  /**
19  * Auxiliary class to ensure that the mask set is defined prior to
20  * the ctype<>() constructor call.
21  */
22  class JMask {
23  public:
24 
25  typedef std::ctype<char> ctype;
26 
27  protected:
28  ctype::mask mask_set[ctype::table_size];
29  };
30 
31 
32  /**
33  * Auxiliary class to specify white space character(s) in currect locale.
34  */
36  private JMask,
37  public std::ctype<char>
38  {
39  public:
40  /**
41  * Constructor.
42  *
43  * \param loc current locale
44  * \param ws white space character
45  */
46  JWhiteSpacesFacet(const std::locale& loc,
47  const char ws) :
48  JMask(),
50  {
51  configure(loc, std::string(1, ws));
52  }
53 
54 
55  /**
56  * Constructor.
57  *
58  * \param loc current locale
59  * \param ws white space character(s)
60  */
61  JWhiteSpacesFacet(const std::locale& loc,
62  const std::string& ws) :
63  JMask(),
65  {
66  configure(loc, ws);
67  }
68 
69  private:
70  /**
71  * Configure.
72  *
73  * \param loc current locale
74  * \param ws white space character(s)
75  */
76  void configure(const std::locale& loc,
77  const std::string& ws)
78  {
79  using namespace std;
80 
81  char buffer[table_size];
82 
83  for (unsigned int i = 0; i != table_size; ++i) {
84  buffer[i] = (char) i;
85  }
86 
87  use_facet<JMask::ctype>(loc).is(buffer, buffer + table_size, mask_set);
88 
89  for (unsigned int i = 0; i != table_size; ++i) {
90  if (mask_set[i] & JMask::ctype::space) {
91  mask_set[i] ^= JMask::ctype::space;
92  }
93  }
94 
95  for (string::const_iterator i = ws.begin(); i != ws.end(); ++i) {
96  mask_set[(int) *i] |= JMask::ctype::space;
97  }
98  }
99  };
100 }
101 
102 #endif
ctype::mask mask_set[ctype::table_size]
void configure(const std::locale &loc, const std::string &ws)
Configure.
is
Definition: JDAQCHSM.chsm:167
std::ctype< char > ctype
Auxiliary class to ensure that the mask set is defined prior to the ctype&lt;&gt;() constructor call...
then awk string
JWhiteSpacesFacet(const std::locale &loc, const char ws)
Constructor.
Auxiliary class to specify white space character(s) in currect locale.
JWhiteSpacesFacet(const std::locale &loc, const std::string &ws)
Constructor.
char * loc(char *orig)