Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:08:37

0001 /*
0002  *
0003  * Copyright (c) 1998-2002
0004  * John Maddock
0005  *
0006  * Use, modification and distribution are subject to the 
0007  * Boost Software License, Version 1.0. (See accompanying file 
0008  * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009  *
0010  */
0011  
0012  /*
0013   *   LOCATION:    see http://www.boost.org for most recent version.
0014   *   FILE:        primary_transform.hpp
0015   *   VERSION:     see <boost/version.hpp>
0016   *   DESCRIPTION: Heuristically determines the sort string format in use
0017   *                by the current locale.
0018   */
0019 
0020 #ifndef BOOST_REGEX_PRIMARY_TRANSFORM
0021 #define BOOST_REGEX_PRIMARY_TRANSFORM
0022 
0023 namespace boost{
0024    namespace BOOST_REGEX_DETAIL_NS{
0025 
0026 
0027 enum{
0028    sort_C,
0029    sort_fixed,
0030    sort_delim,
0031    sort_unknown
0032 };
0033 
0034 template <class S, class charT>
0035 unsigned count_chars(const S& s, charT c)
0036 {
0037    //
0038    // Count how many occurrences of character c occur
0039    // in string s: if c is a delimeter between collation
0040    // fields, then this should be the same value for all
0041    // sort keys:
0042    //
0043    unsigned int count = 0;
0044    for(unsigned pos = 0; pos < s.size(); ++pos)
0045    {
0046       if(s[pos] == c) ++count;
0047    }
0048    return count;
0049 }
0050 
0051 
0052 template <class traits, class charT>
0053 unsigned find_sort_syntax(const traits* pt, charT* delim)
0054 {
0055    //
0056    // compare 'a' with 'A' to see how similar they are,
0057    // should really use a-accute but we can't portably do that,
0058    //
0059    typedef typename traits::string_type string_type;
0060    typedef typename traits::char_type char_type;
0061 
0062    // Suppress incorrect warning for MSVC
0063    (void)pt;
0064 
0065    char_type a[2] = {'a', '\0', };
0066    string_type sa(pt->transform(a, a+1));
0067    if(sa == a)
0068    {
0069       *delim = 0;
0070       return sort_C;
0071    }
0072    char_type A[2] = { 'A', '\0', };
0073    string_type sA(pt->transform(A, A+1));
0074    char_type c[2] = { ';', '\0', };
0075    string_type sc(pt->transform(c, c+1));
0076 
0077    int pos = 0;
0078    while((pos <= static_cast<int>(sa.size())) && (pos <= static_cast<int>(sA.size())) && (sa[pos] == sA[pos])) ++pos;
0079    --pos;
0080    if(pos < 0)
0081    {
0082       *delim = 0;
0083       return sort_unknown;
0084    }
0085    //
0086    // at this point sa[pos] is either the end of a fixed width field
0087    // or the character that acts as a delimiter:
0088    //
0089    charT maybe_delim = sa[pos];
0090    if((pos != 0) && (count_chars(sa, maybe_delim) == count_chars(sA, maybe_delim)) && (count_chars(sa, maybe_delim) == count_chars(sc, maybe_delim)))
0091    {
0092       *delim = maybe_delim;
0093       return sort_delim;
0094    }
0095    //
0096    // OK doen't look like a delimiter, try for fixed width field:
0097    //
0098    if((sa.size() == sA.size()) && (sa.size() == sc.size()))
0099    {
0100       // note assumes that the fixed width field is less than
0101       // (numeric_limits<charT>::max)(), should be true for all types
0102       // I can't imagine 127 character fields...
0103       *delim = static_cast<charT>(++pos);
0104       return sort_fixed;
0105    }
0106    //
0107    // don't know what it is:
0108    //
0109    *delim = 0;
0110    return sort_unknown;
0111 }
0112 
0113 
0114    } // namespace BOOST_REGEX_DETAIL_NS
0115 } // namespace boost
0116 
0117 #endif
0118 
0119 
0120