Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:51:25

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 #ifdef BOOST_MSVC
0024 #pragma warning(push)
0025 #pragma warning(disable: 4103)
0026 #endif
0027 #ifdef BOOST_HAS_ABI_HEADERS
0028 #  include BOOST_ABI_PREFIX
0029 #endif
0030 #ifdef BOOST_MSVC
0031 #pragma warning(pop)
0032 #endif
0033 
0034 namespace boost{
0035    namespace BOOST_REGEX_DETAIL_NS{
0036 
0037 
0038 enum{
0039    sort_C,
0040    sort_fixed,
0041    sort_delim,
0042    sort_unknown
0043 };
0044 
0045 template <class S, class charT>
0046 unsigned count_chars(const S& s, charT c)
0047 {
0048    //
0049    // Count how many occurrences of character c occur
0050    // in string s: if c is a delimeter between collation
0051    // fields, then this should be the same value for all
0052    // sort keys:
0053    //
0054    unsigned int count = 0;
0055    for(unsigned pos = 0; pos < s.size(); ++pos)
0056    {
0057       if(s[pos] == c) ++count;
0058    }
0059    return count;
0060 }
0061 
0062 
0063 template <class traits, class charT>
0064 unsigned find_sort_syntax(const traits* pt, charT* delim)
0065 {
0066    //
0067    // compare 'a' with 'A' to see how similar they are,
0068    // should really use a-accute but we can't portably do that,
0069    //
0070    typedef typename traits::string_type string_type;
0071    typedef typename traits::char_type char_type;
0072 
0073    // Suppress incorrect warning for MSVC
0074    (void)pt;
0075 
0076    char_type a[2] = {'a', '\0', };
0077    string_type sa(pt->transform(a, a+1));
0078    if(sa == a)
0079    {
0080       *delim = 0;
0081       return sort_C;
0082    }
0083    char_type A[2] = { 'A', '\0', };
0084    string_type sA(pt->transform(A, A+1));
0085    char_type c[2] = { ';', '\0', };
0086    string_type sc(pt->transform(c, c+1));
0087 
0088    int pos = 0;
0089    while((pos <= static_cast<int>(sa.size())) && (pos <= static_cast<int>(sA.size())) && (sa[pos] == sA[pos])) ++pos;
0090    --pos;
0091    if(pos < 0)
0092    {
0093       *delim = 0;
0094       return sort_unknown;
0095    }
0096    //
0097    // at this point sa[pos] is either the end of a fixed width field
0098    // or the character that acts as a delimiter:
0099    //
0100    charT maybe_delim = sa[pos];
0101    if((pos != 0) && (count_chars(sa, maybe_delim) == count_chars(sA, maybe_delim)) && (count_chars(sa, maybe_delim) == count_chars(sc, maybe_delim)))
0102    {
0103       *delim = maybe_delim;
0104       return sort_delim;
0105    }
0106    //
0107    // OK doen't look like a delimiter, try for fixed width field:
0108    //
0109    if((sa.size() == sA.size()) && (sa.size() == sc.size()))
0110    {
0111       // note assumes that the fixed width field is less than
0112       // (numeric_limits<charT>::max)(), should be true for all types
0113       // I can't imagine 127 character fields...
0114       *delim = static_cast<charT>(++pos);
0115       return sort_fixed;
0116    }
0117    //
0118    // don't know what it is:
0119    //
0120    *delim = 0;
0121    return sort_unknown;
0122 }
0123 
0124 
0125    } // namespace BOOST_REGEX_DETAIL_NS
0126 } // namespace boost
0127 
0128 #ifdef BOOST_MSVC
0129 #pragma warning(push)
0130 #pragma warning(disable: 4103)
0131 #endif
0132 #ifdef BOOST_HAS_ABI_HEADERS
0133 #  include BOOST_ABI_SUFFIX
0134 #endif
0135 #ifdef BOOST_MSVC
0136 #pragma warning(pop)
0137 #endif
0138 
0139 #endif
0140 
0141 
0142 
0143 
0144 
0145 
0146