3

International Components for Unicode (ICU) をサポートする boost::regex バージョン 1.52 ライブラリをビルドした後、大文字と小文字を区別しない一致を含む正規表現は、ドイツ語の大文字と小文字のウムラウト文字を期待どおりに処理しないようです。

static const std::string pattern("^.*" "\303\226" ".*$");
static const std::string   test1("SCH" "\303\226" "NE");
static const std::string   test2("sch" "\303\266" "ne");
static const boost::regex exp(pattern, boost::regex::icase);
const char *result = (boost::regex_match(test1, exp)) ? "Match" : "NoMatch";
std::cout << "Testing \"" << test1 << "\" against pattern \"" << pattern 
    << "\" : " << result << std::endl;
result = (boost::regex_match(test2, exp)) ? "Match" : "NoMatch";
std::cout << "Testing \"" << test2 << "\" against pattern \"" << pattern 
    << "\" : " << result << std::endl;

収量:

Testing "SCHÖNE" against pattern "^.*Ö.*$" : Match
Testing "schöne" against pattern "^.*Ö.*$" : NoMatch
4

1 に答える 1

2

Unicode および ICU 文字列型の操作

LWS の例

#include <iostream>
#include <boost/regex.hpp>
#include <boost/regex/icu.hpp>
int main()
{
   static const std::string pattern("^.*" "\303\226" ".*$");
   static const std::string   test1("SCH" "\303\226" "NE");
   static const std::string   test2("sch" "\303\266" "ne");
   static const boost::u32regex exp=boost::make_u32regex(pattern, boost::regex::icase);
   const char *result = (boost::u32regex_match(test1, exp)) ? "Match" : "NoMatch";
   std::cout << "Testing \"" << test1 << "\" against pattern \"" << pattern 
      << "\" : " << result << std::endl;
   result = (boost::u32regex_match(test2, exp)) ? "Match" : "NoMatch";
   std::cout << "Testing \"" << test2 << "\" against pattern \"" << pattern 
      << "\" : " << result << std::endl;
}
于 2013-04-09T16:16:34.940 に答える