Jpp
 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(s)
45  */
46  JWhiteSpacesFacet(const std::locale& loc,
47  const std::string& ws) :
48  JMask(),
50  {
51  using namespace std;
52 
53  char buffer[table_size];
54 
55  for (unsigned int i = 0; i != table_size; ++i) {
56  buffer[i] = (char) i;
57  }
58 
59  use_facet<JMask::ctype>(loc).is(buffer, buffer + table_size, mask_set);
60 
61  for (unsigned int i = 0; i != table_size; ++i) {
62  if (mask_set[i] & JMask::ctype::space) {
63  mask_set[i] ^= JMask::ctype::space;
64  }
65  }
66 
67  for (string::const_iterator i = ws.begin(); i != ws.end(); ++i) {
68  mask_set[(int) *i] |= JMask::ctype::space;
69  }
70  }
71  };
72 }
73 
74 #endif
ctype::mask mask_set[ctype::table_size]
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...
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)