3 * Copyright (c) 1998-2002
6 * Use, modification and distribution are subject to the
7 * Boost Software License, Version 1.0. (See accompanying file
8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
13 * LOCATION: see http://www.boost.org for most recent version.
14 * FILE: primary_transform.hpp
15 * VERSION: see <boost/version.hpp>
16 * DESCRIPTION: Heuristically determines the sort string format in use
17 * by the current locale.
20 #ifndef BOOST_REGEX_PRIMARY_TRANSFORM
21 #define BOOST_REGEX_PRIMARY_TRANSFORM
25 #pragma warning(disable: 4103)
27 #ifdef BOOST_HAS_ABI_HEADERS
28 # include BOOST_ABI_PREFIX
35 namespace BOOST_REGEX_DETAIL_NS{
45 template <class S, class charT>
46 unsigned count_chars(const S& s, charT c)
49 // Count how many occurances of character c occur
50 // in string s: if c is a delimeter between collation
51 // fields, then this should be the same value for all
54 unsigned int count = 0;
55 for(unsigned pos = 0; pos < s.size(); ++pos)
57 if(s[pos] == c) ++count;
63 template <class traits, class charT>
64 unsigned find_sort_syntax(const traits* pt, charT* delim)
67 // compare 'a' with 'A' to see how similar they are,
68 // should really use a-accute but we can't portably do that,
70 typedef typename traits::string_type string_type;
71 typedef typename traits::char_type char_type;
73 // Suppress incorrect warning for MSVC
76 char_type a[2] = {'a', '\0', };
77 string_type sa(pt->transform(a, a+1));
83 char_type A[2] = { 'A', '\0', };
84 string_type sA(pt->transform(A, A+1));
85 char_type c[2] = { ';', '\0', };
86 string_type sc(pt->transform(c, c+1));
89 while((pos <= static_cast<int>(sa.size())) && (pos <= static_cast<int>(sA.size())) && (sa[pos] == sA[pos])) ++pos;
97 // at this point sa[pos] is either the end of a fixed width field
98 // or the character that acts as a delimiter:
100 charT maybe_delim = sa[pos];
101 if((pos != 0) && (count_chars(sa, maybe_delim) == count_chars(sA, maybe_delim)) && (count_chars(sa, maybe_delim) == count_chars(sc, maybe_delim)))
103 *delim = maybe_delim;
107 // OK doen't look like a delimiter, try for fixed width field:
109 if((sa.size() == sA.size()) && (sa.size() == sc.size()))
111 // note assumes that the fixed width field is less than
112 // (numeric_limits<charT>::max)(), should be true for all types
113 // I can't imagine 127 character fields...
114 *delim = static_cast<charT>(++pos);
118 // don't know what it is:
125 } // namespace BOOST_REGEX_DETAIL_NS
129 #pragma warning(push)
130 #pragma warning(disable: 4103)
132 #ifdef BOOST_HAS_ABI_HEADERS
133 # include BOOST_ABI_SUFFIX