mirror of
https://github.com/boostorg/regex.git
synced 2025-07-14 21:06:38 +02:00
Allow sort keys to contain nothing but a single NUL character (characters may be ignorable).
[SVN r27408]
This commit is contained in:
@ -407,6 +407,10 @@ re_syntax_base* basic_regex_creator<charT, traits>::append_set(
|
||||
charT a2[3] = { c2.first, c2.second, charT(0), };
|
||||
s1 = this->m_traits.transform(a1, (a1[1] ? a1+2 : a1+1));
|
||||
s2 = this->m_traits.transform(a2, (a2[1] ? a2+2 : a2+1));
|
||||
if(s1.size() == 0)
|
||||
s1 = string_type(1, charT(0));
|
||||
if(s2.size() == 0)
|
||||
s2 = string_type(1, charT(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -546,7 +550,7 @@ re_syntax_base* basic_regex_creator<charT, traits>::append_set(
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!char_less<charT>(c1, c2))
|
||||
if(char_less<charT>(c2, c1))
|
||||
{
|
||||
// Oops error:
|
||||
return 0;
|
||||
|
@ -509,10 +509,8 @@ typename cpp_regex_traits_implementation<charT>::string_type
|
||||
case sort_delim:
|
||||
// get a regular sort key, and then truncate everything after the delim:
|
||||
result.assign(this->m_pcollate->transform(p1, p2));
|
||||
if(result.size() && (result[0] == m_collate_delim))
|
||||
break;
|
||||
std::size_t i;
|
||||
for(i = 1; i < result.size(); ++i)
|
||||
for(i = 0; i < result.size(); ++i)
|
||||
{
|
||||
if(result[i] == m_collate_delim)
|
||||
break;
|
||||
@ -523,6 +521,11 @@ typename cpp_regex_traits_implementation<charT>::string_type
|
||||
}catch(...){}
|
||||
while(result.size() && (charT(0) == *result.rbegin()))
|
||||
result.erase(result.size() - 1);
|
||||
if(result.empty())
|
||||
{
|
||||
// character is ignorable at the primary level:
|
||||
result = string_type(1, charT(0));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -68,11 +68,25 @@ inline bool can_start(wchar_t c, const unsigned char* map, unsigned char mask)
|
||||
#ifndef _RWSTD_VER
|
||||
template <class C, class T, class A>
|
||||
inline int string_compare(const std::basic_string<C,T,A>& s, const C* p)
|
||||
{ return s.compare(p); }
|
||||
{
|
||||
if(0 == *p)
|
||||
{
|
||||
if(s.empty() || ((s.size() == 1) && (s[0] == 0)))
|
||||
return 0;
|
||||
}
|
||||
return s.compare(p);
|
||||
}
|
||||
#else
|
||||
template <class C, class T, class A>
|
||||
inline int string_compare(const std::basic_string<C,T,A>& s, const C* p)
|
||||
{ return s.compare(p); }
|
||||
{
|
||||
if(0 == *p)
|
||||
{
|
||||
if(s.empty() || ((s.size() == 1) && (s[0] == 0)))
|
||||
return 0;
|
||||
}
|
||||
return s.compare(p);
|
||||
}
|
||||
inline int string_compare(const std::string& s, const char* p)
|
||||
{ return std::strcmp(s.c_str(), p); }
|
||||
# ifndef BOOST_NO_WREGEX
|
||||
|
@ -372,6 +372,8 @@ typename w32_regex_traits_implementation<charT>::string_type
|
||||
result.erase(i);
|
||||
break;
|
||||
}
|
||||
if(result.empty())
|
||||
result = string_type(1, charT(0));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -102,6 +102,8 @@ c_regex_traits<char>::string_type BOOST_REGEX_CALL c_regex_traits<char>::transfo
|
||||
result.erase(i);
|
||||
break;
|
||||
}
|
||||
if(result.empty())
|
||||
result = std::string(1, char(0));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -94,6 +94,8 @@ c_regex_traits<wchar_t>::string_type BOOST_REGEX_CALL c_regex_traits<wchar_t>::t
|
||||
result.erase(i);
|
||||
break;
|
||||
}
|
||||
if(result.empty())
|
||||
result = std::wstring(1, char(0));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -153,6 +153,12 @@ void test_sets2()
|
||||
TEST_REGEX_SEARCH("[[.right-curly-bracket.]]", perl, "}", match_default, make_array(0, 1, -2, -2));
|
||||
TEST_REGEX_SEARCH("[[.NUL.]]", perl, "\0", match_default, make_array(0, 1, -2, -2));
|
||||
TEST_REGEX_SEARCH("[[.NUL.][.ae.]]", perl, "\0", match_default, make_array(0, 1, -2, -2));
|
||||
TEST_REGEX_SEARCH("[[.NUL.]-a]", extended, "\0", match_default, make_array(0, 1, -2, -2));
|
||||
TEST_REGEX_SEARCH("[[.NUL.]-a]", perl, "\0", match_default, make_array(0, 1, -2, -2));
|
||||
TEST_REGEX_SEARCH("[[.NUL.]-a]", extended, "a", match_default, make_array(0, 1, -2, -2));
|
||||
TEST_REGEX_SEARCH("[[.NUL.]-a]", perl, "a", match_default, make_array(0, 1, -2, -2));
|
||||
TEST_REGEX_SEARCH("[[.NUL.]-[.NUL.]a]", extended, "a", match_default, make_array(0, 1, -2, -2));
|
||||
TEST_REGEX_SEARCH("[[.NUL.]-[.NUL.]a]", perl, "a", match_default, make_array(0, 1, -2, -2));
|
||||
TEST_INVALID_REGEX("[[..]]", perl);
|
||||
TEST_INVALID_REGEX("[[.not-a-collating-element.]]", perl);
|
||||
TEST_INVALID_REGEX("[[.", perl);
|
||||
@ -222,6 +228,8 @@ void test_sets2()
|
||||
TEST_REGEX_SEARCH("[[=a=]]", basic, "A", match_default, make_array(0, 1, -2, -2));
|
||||
TEST_REGEX_SEARCH("[[=ae=]]", basic, "ae", match_default, make_array(0, 2, -2, -2));
|
||||
TEST_REGEX_SEARCH("[[=right-curly-bracket=]]", basic, "}", match_default, make_array(0, 1, -2, -2));
|
||||
TEST_REGEX_SEARCH("[[=NUL=]]", basic, "\x0", match_default, make_array(0, 1, -2, -2));
|
||||
TEST_REGEX_SEARCH("[[=NUL=]]", perl, "\x0", match_default, make_array(0, 1, -2, -2));
|
||||
TEST_INVALID_REGEX("[[=", perl);
|
||||
TEST_INVALID_REGEX("[[=a", perl);
|
||||
TEST_INVALID_REGEX("[[=ae", perl);
|
||||
|
Reference in New Issue
Block a user