3 * Copyright (c) 1998-2002
6 * Permission to use, copy, modify, distribute and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appear in all copies and
9 * that both that copyright notice and this permission notice appear
10 * in supporting documentation. Dr John Maddock makes no representations
11 * about the suitability of this software for any purpose.
12 * It is provided "as is" without express or implied warranty.
17 * LOCATION: see http://www.boost.org for most recent version.
18 * FILE: primary_transform.hpp
19 * VERSION: see <boost/version.hpp>
20 * DESCRIPTION: Heuristically determines the sort string format in use
21 * by the current locale.
35 template <class S, class charT>
36 unsigned count_chars(const S& s, charT c)
38 unsigned int count = 0;
39 for(unsigned pos = 0; pos < s.size(); ++pos)
41 if(s[pos] == c) ++count;
47 template <class traits, class charT>
48 unsigned find_sort_syntax(const traits* pt, charT* delim)
51 // compare 'a' with 'A' to see how similar they are,
52 // should really use a-accute but we can't portably do that,
54 typedef typename traits::string_type string_type;
55 typedef typename traits::char_type char_type;
57 // Suppress incorrect warning for MSVC
60 string_type a(1, (char_type)'a');
68 string_type A(1, (char_type)'A');
71 string_type c(1, (char_type)';');
76 while((pos <= static_cast<int>(sa.size())) && (pos <= static_cast<int>(sA.size())) && (sa[pos] == sA[pos])) ++pos;
84 // at this point sa[pos] is either the end of a fixed with field
85 // or the character that acts as a delimiter:
87 charT maybe_delim = sa[pos];
88 if((pos != 0) && (count_chars(sa, maybe_delim) == count_chars(sA, maybe_delim)) && (count_chars(sa, maybe_delim) == count_chars(c, maybe_delim)))
94 // OK doen't look like a delimiter, try for fixed width field:
96 if((sa.size() == sA.size()) && (sa.size() == c.size()))
98 // note assumes that the fixed width field is less than
99 // numeric_limits<charT>::max(), should be true for all types
100 // I can't imagine 127 character fields...
101 *delim = static_cast<charT>(++pos);
105 // don't know what it is:
112 } // namespace re_detail