Opened 5 years ago
Last modified 5 years ago
#13231 new Bugs
u32regex_replace() for std::u32string (UTF-32) won't compile
| Reported by: | Owned by: | John Maddock | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | regex |
| Version: | Boost 1.64.0 | Severity: | Showstopper |
| Keywords: | Cc: |
Description
Note - This pertains to input UTF-32 strings.
Compiler: VS2015 , VC++ Boost version: 1.64
The u32regex_search() works fine and as expected
=================================
Problem description: Intellisence detects proper input
parameters using the u32string parameter, but throws many
errors when compiling.
The errors start with
boost_1_64_0\boost/functional/hash/extensions.hpp(262): error C2664: 'size_t boost::hash_value(std::type_index)': cannot convert argument 1 from 'const char32_t' to 'std::type_index'
and end with
RxReplace.cpp(9255): note: see reference to function template instantiation 'std::basic_string<char32_t,std::char_traits<char32_t>,std::allocator<char32_t>> boost::u32regex_replace<char32_t>(const std::basic_string<char32_t,std::char_traits<char32_t>,std::allocator<char32_t>> &,const boost::u32regex &,const std::basic_string<char32_t,std::char_traits<char32_t>,std::allocator<char32_t>> &,boost::regex_constants::match_flag_type)' being compiled
with about 20 errors in between.
I hope this is just a problem with extensions.hpp
and maybe there is a quick fix (or it has already been fixed).
I desperately need this to work with std::u32string types
as UnicodeString just won't cut it for my purposes.
From the documentation:
u32regex_replace
For each regex_replace algorithm defined by
<boost/regex.hpp>, then <boost/regex/icu.hpp> defines an
overloaded algorithm that takes the same arguments, but
which is called u32regex_replace, and which will accept
UTF-8, UTF-16 or UTF-32 encoded data, as well as an ICU
UnicodeString as input.
The code below reproduces the compile errors
// rxconst.h
// ==============================
typedef std::u32string X_32string;
typedef std::wstring X_string;
typedef boost::u32regex U_X_regex;
typedef boost::u32match X_u32match;
typedef std::u32string::const_iterator U32SITR;
#define U_MAKEREGEX(str,options) make_u32regex(str,options)
#define U_REGEX_SEARCH boost::u32regex_search
#define U_REGEX_REPLACE boost::u32regex_replace
// RxReplace.cpp ( won't compile )
// ==============================
#include "rxconst.h";
U_X_regex uRx = U_MAKEREGEX( _T("[trgt]+"), regex_constants::perl );
X_32string sTarget, sFmt, sOutput;
WstrToU32string( X_string(_T("target")), sTarget );
WstrToU32string( X_string(_T("")), sFmt );
sOutput = U_REGEX_REPLACE( sTarget, uRx, sFmt ); // <-- Won't compile
// RxSearch.cpp ( compiles and runs as expected )
// ==============================
#include "rxconst.h";
U_X_regex uRx = U_MAKEREGEX( _T("[abce]+"), regex_constants::perl );
X_32string sSrc;
WstrToU32string( X_string(_T("source")), sSrc );
U32SITR SitrStart = sSrc.begin();
U32SITR start = SitrStart;
U32SITR end = sSrc.end();
X_u32match _M;
while ( U_REGEX_SEARCH( start, end, _M, uRx, Flags, SitrStart ) )
{
// ...
}
Change History (3)
comment:1 by , 5 years ago
| Component: | None → regex |
|---|---|
| Owner: | set to |
comment:2 by , 5 years ago
| Severity: | Problem → Showstopper |
|---|

This looks to be fixed in release 1.65.1
I've tested the above code with this release and it works fine.
Details where it was fixed:
Chapter 15. Boost.Functional/Hash Change log: Boost 1.65.0 • Support for char16_t, char32_t, u16string, u32string ------------------------------------------------------- boost_1_65_1\boost\functional\hash\hash.hpp BOOST_HASH_SPECIALIZE(char16_t) BOOST_HASH_SPECIALIZE(char32_t) BOOST_HASH_SPECIALIZE_REF(std::basic_string<char16_t>) BOOST_HASH_SPECIALIZE_REF(std::basic_string<char32_t>)