Jpp
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
JLANG::JMask::ctype
std::ctype< char > ctype
Definition: JWhiteSpacesFacet.hh:25
loc
char * loc(char *orig)
JLANG::JWhiteSpacesFacet
Auxiliary class to specify white space character(s) in currect locale.
Definition: JWhiteSpacesFacet.hh:35
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JLANG::JMask::mask_set
ctype::mask mask_set[ctype::table_size]
Definition: JWhiteSpacesFacet.hh:28
JLANG::JMask
Auxiliary class to ensure that the mask set is defined prior to the ctype<>() constructor call.
Definition: JWhiteSpacesFacet.hh:22
std
Definition: jaanetDictionary.h:36
JLANG::JWhiteSpacesFacet::JWhiteSpacesFacet
JWhiteSpacesFacet(const std::locale &loc, const std::string &ws)
Constructor.
Definition: JWhiteSpacesFacet.hh:46
JLANG
Auxiliary classes and methods for language specific functionality.
Definition: JAbstractClass.hh:10