1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
/*
*
* Copyright (c) 1998-2002
* John Maddock
*
* Use, modification and distribution are subject to the
* Boost Software License, Version 1.0. (See accompanying file
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE: primary_transform.hpp
* VERSION: see <boost/version.hpp>
* DESCRIPTION: Heuristically determines the sort string format in use
* by the current locale.
*/
#ifndef BOOST_REGEX_PRIMARY_TRANSFORM
#define BOOST_REGEX_PRIMARY_TRANSFORM
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable: 4103)
#endif
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
namespace boost{
namespace re_detail{
enum{
sort_C,
sort_fixed,
sort_delim,
sort_unknown
};
template <class S, class charT>
unsigned count_chars(const S& s, charT c)
{
//
// Count how many occurances of character c occur
// in string s: if c is a delimeter between collation
// fields, then this should be the same value for all
// sort keys:
//
unsigned int count = 0;
for(unsigned pos = 0; pos < s.size(); ++pos)
{
if(s[pos] == c) ++count;
}
return count;
}
template <class traits, class charT>
unsigned find_sort_syntax(const traits* pt, charT* delim)
{
//
// compare 'a' with 'A' to see how similar they are,
// should really use a-accute but we can't portably do that,
//
typedef typename traits::string_type string_type;
typedef typename traits::char_type char_type;
// Suppress incorrect warning for MSVC
(void)pt;
char_type a[2] = {'a', '\0', };
string_type sa(pt->transform(a, a+1));
if(sa == a)
{
*delim = 0;
return sort_C;
}
char_type A[2] = { 'A', '\0', };
string_type sA(pt->transform(A, A+1));
char_type c[2] = { ';', '\0', };
string_type sc(pt->transform(c, c+1));
int pos = 0;
while((pos <= static_cast<int>(sa.size())) && (pos <= static_cast<int>(sA.size())) && (sa[pos] == sA[pos])) ++pos;
--pos;
if(pos < 0)
{
*delim = 0;
return sort_unknown;
}
//
// at this point sa[pos] is either the end of a fixed width field
// or the character that acts as a delimiter:
//
charT maybe_delim = sa[pos];
if((pos != 0) && (count_chars(sa, maybe_delim) == count_chars(sA, maybe_delim)) && (count_chars(sa, maybe_delim) == count_chars(sc, maybe_delim)))
{
*delim = maybe_delim;
return sort_delim;
}
//
// OK doen't look like a delimiter, try for fixed width field:
//
if((sa.size() == sA.size()) && (sa.size() == sc.size()))
{
// note assumes that the fixed width field is less than
// (numeric_limits<charT>::max)(), should be true for all types
// I can't imagine 127 character fields...
*delim = static_cast<charT>(++pos);
return sort_fixed;
}
//
// don't know what it is:
//
*delim = 0;
return sort_unknown;
}
} // namespace re_detail
} // namespace boost
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable: 4103)
#endif
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif
|