Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
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
12namespace JLANG {}
13namespace JPP { using namespace JLANG; }
14
15namespace 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
Auxiliary class to ensure that the mask set is defined prior to the ctype<>() constructor call.
ctype::mask mask_set[ctype::table_size]
std::ctype< char > ctype
Auxiliary class to specify white space character(s) in currect locale.
JWhiteSpacesFacet(const std::locale &loc, const std::string &ws)
Constructor.
JWhiteSpacesFacet(const std::locale &loc, const char ws)
Constructor.
void configure(const std::locale &loc, const std::string &ws)
Configure.
char * loc(char *orig)
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).