annotate DEPENDENCIES/generic/include/boost/regex/v4/primary_transform.hpp @ 133:4acb5d8d80b6 tip

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