Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
locale_eq.cpp
Go to the documentation of this file.
1
29#define _RWSTD_LIB_SRC
30
31#include <rw/_defs.h>
32
33#include <string.h>
34
35#include <loc/_locale.h>
36
37#include "locale_body.h"
38
39
41
42
43bool locale::operator== (const locale &rhs) const
44{
45 _RWSTD_ASSERT (_C_body);
46 _RWSTD_ASSERT (_C_body->_C_name);
47
48 _RWSTD_ASSERT (rhs._C_body);
49 _RWSTD_ASSERT (rhs._C_body->_C_name);
50
51 // same bodies (i.e., *this is a copy of `rhs') which implies that
52 // the locale objects must consist entirely of standard facets,
53 // each of which must come from the same locale
54 if (_C_body == rhs._C_body)
55 return true;
56
57 // different bodies may compare equal if they both contain only
58 // ordinary or named standard facet objects, the same sets of
59 // which having been replaced with user-defined or constructed
60 // facet objects
61 if (!_C_body->_C_n_usr_facets && !rhs._C_body->_C_n_usr_facets) {
62
63 // in order to compare equal, both bodies must have the same
64 // sets of facets (some slots may still be uninitialized) and
65 // not have different names
66 const bool eql =
67 _C_body->_C_std_facet_bits == rhs._C_body->_C_std_facet_bits
68 && _C_body->_C_byname_facet_bits == rhs._C_body->_C_byname_facet_bits
69 && !memcmp (_C_body->_C_std_facets, rhs._C_body->_C_std_facets,
70 _C_body->_C_n_std_facets * sizeof *_C_body->_C_std_facets)
71 && !strcmp (_C_body->_C_name, rhs._C_body->_C_name);
72
73 // at least some standard facets must have been replaced in order
74 // for two "equal" locale objects not to share the same body, or
75 // the locales' names must be different
76 _RWSTD_ASSERT ( eql
77 || _C_body->_C_std_facet_bits != _C_body->_C_all
78 || rhs._C_body->_C_std_facet_bits != _C_body->_C_all
79 || _C_body->_C_byname_facet_bits != _C_body->_C_all
80 || rhs._C_body->_C_byname_facet_bits != _C_body->_C_all
81 || strcmp (_C_body->_C_name, rhs._C_body->_C_name));
82
83 // facet bits of both objects must be the same if the two objects
84 // share the exact same facets (otherwise the bits may or may not
85 // be the same)
86 _RWSTD_ASSERT ( !eql
87 || _C_body->_C_std_facet_bits
88 == rhs._C_body->_C_std_facet_bits
89 && _C_body->_C_byname_facet_bits
90 == rhs._C_body->_C_byname_facet_bits);
91
92 // the names of both objects must be the same if the two objects
93 // share the exact same facets (otherwise the names may or may not
94 // be the same
95 // e.g., locale (locale ("C"), new F)
96 // and locale (locale ("C"), new G)
97 // can both be named "C;C;C;C;C;C" and distinct if F and G are
98 // distinct type neither of which defines the static member id,
99 // if both are derived from the same standard facet
100 _RWSTD_ASSERT ( !eql
101 || !strcmp (_C_body->_C_name, rhs._C_body->_C_name));
102
103 return eql;
104 }
105
106 // locales are unequal if *this has a different number of facets than `rhs'
107 if (_C_body->_C_n_usr_facets != rhs._C_body->_C_n_usr_facets)
108 return false;
109
110 // locales are unequal if their standard facets don't all come
111 // from the same named locales
112 if (strcmp (_C_body->_C_name, rhs._C_body->_C_name))
113 return false;
114
115 // highest valid index
116 const size_t maxinx =
117 rhs._C_body->_C_n_usr_facets + _RW::__rw_locale::_C_n_std_facets;
118
119 // locales with the same (non-0) number of user-defined
120 // facets compare equal iff all the facets are identical
121 for (_RWSTD_SIZE_T i = 0; i != _C_body->_C_n_usr_facets; ++i) {
122
123 const _RW::__rw_facet* const pf = _C_body->_C_usr_facets [i];
124
125 _RWSTD_ASSERT (0 != pf);
126 _RWSTD_ASSERT (0 != pf->_C_pid);
127 _RWSTD_ASSERT (0 != *pf->_C_pid);
128
129 // if the facets at the same index aren't the same but their
130 // numeric id's are the locales are not equal; this check short
131 // circuits the linear lookup of the facet in rhs done below
132 if ( pf != rhs._C_body->_C_usr_facets [i]
133 && pf->_C_pid == rhs._C_body->_C_usr_facets [i]->_C_pid)
134 return false;
135
136 // find the index of the facet in rhs if it's installed there
137 size_t inx = rhs._C_body->_C_get_facet_inx (*pf->_C_pid);
138 if (maxinx <= inx || inx < _RW::__rw_locale::_C_n_std_facets)
139 return false;
140
141 // the index starts at _C_n_std_facets
142 inx -= _RW::__rw_locale::_C_n_std_facets;
143
144 // if the two facets aren't the same objects the locales aren't
145 // equal (since they may each behave differently)
146 if (pf != rhs._C_body->_C_usr_facets [inx])
147 return false;
148 }
149
150 return true;
151}
152
153
154} // namespace std
#define i
Definition 17.names.cpp:126
#define rhs
Definition 17.names.cpp:536
#define pf
Definition 17.names.cpp:516
#define inx
Definition 17.names.cpp:484
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _RWSTD_ASSERT(ignore)
Definition _defs.h:1108
Definition json.h:5363