是否期望Boost regex空白字符类也匹配垂直制表符

问题描述

我注意到字符类[:blank:]也与\v匹配,如下面的代码所示。但是,应该shouldn't be there,per POSIX吗?

#include <string>
#include <iostream>
#include <boost/regex.hpp>
using namespace std;
using namespace boost;
int main() {
    std::string const text{"\v"};
    cout << (sregex_token_iterator{text.begin(),text.end(),regex{R"((?-m)^([[:blank:]])$)"}} != sregex_token_iterator{});
    cout << (sregex_token_iterator{text.begin(),regex{R"((?-m)^([ \t])$)"}} != sregex_token_iterator{}) << '\n';
    // output: 10,but I expected 00
    return 0;
}

很显然,由于this page of Boost并没有提及我看到的here列出的所有字符类,因此我怀疑Boost regexes不兼容POSIX,即使它们使用 some 那些命名的字符类。好吧,Boost页面上甚至没有 POSIX 这个词,所以我想我几乎要回答自己了,但是我没有足够的信心。

我还没有检查这些字符中的哪个属于[:blank:]和/或[:space:],但我想这里也可能有其他惊喜:

const auto LF   = "\x0A";
const auto VT   = "\x0B";
const auto FF   = "\x0C";
const auto CR   = "\x0D";
const auto CRLF = "\x0D\x0A";
const auto NEL  = "\xC2\x85";
const auto LS   = "\xE2\x80\xA8";
const auto PS   = "\xE2\x80\xA9";

解决方法

更新
有关控制Boost Regex引擎工作方式的特定方法的信息。

可以根据
将引擎的行为更改为不同的行为 标志选项集。

请参阅:http://boost.sourceforge.net/libs/regex/doc/syntax_option_type.html

摘要摘录:

Type syntax_option type is an implementation specific bitmask type that controls how a regular expression string is to be interpreted.  For convenience note that all the constants listed here,are also duplicated within the scope of class template basic_regex.

namespace std{ namespace regex_constants{

typedef implementation-specific-bitmask-type syntax_option_type;

// these flags are standardized:
static const syntax_option_type normal;
static const syntax_option_type ECMAScript = normal;
static const syntax_option_type JavaScript = normal;
static const syntax_option_type JScript = normal;
static const syntax_option_type perl = normal;
static const syntax_option_type basic;
static const syntax_option_type sed = basic;
static const syntax_option_type extended;
static const syntax_option_type awk;
static const syntax_option_type grep;
static const syntax_option_type egrep;
static const syntax_option_type icase;
static const syntax_option_type nosubs;
static const syntax_option_type optimize;
static const syntax_option_type collate;
// other boost.regex specific options are listed below

} // namespace regex_constants
} // namespace std

看来语法类型也应该改变引擎匹配的行为。
对于特定的 POSIX 行为,语法选项类型为 extended

有关POSIX扩展选项的信息,请参阅本节:

http://boost.sourceforge.net/libs/regex/doc/syntax_option_type.html#extended

_____________________-

我不知道这是否会改变[[:blank:]]所匹配的内容
我不喜欢使用导入boost libs创建测试C ++程序
此时。

让我知道如果任何人尝试了该课程,会发现什么。 -谢谢


原始
这只是我的测试,我只能使用 Perl 选项
截至此日期我的设置。

看起来[[:blank:]]插入了18个Unicode(utf-8)代码点

00 0009    <control-0009>
00 0020    SPACE
00 00A0    NO-BREAK SPACE
00 1680    OGHAM SPACE MARK
00 2000    EN QUAD
00 2001    EM QUAD
00 2002    EN SPACE
00 2003    EM SPACE
00 2004    THREE-PER-EM SPACE
00 2005    FOUR-PER-EM SPACE
00 2006    SIX-PER-EM SPACE
00 2007    FIGURE SPACE
00 2008    PUNCTUATION SPACE
00 2009    THIN SPACE
00 200A    HAIR SPACE
00 202F    NARROW NO-BREAK SPACE
00 205F    MEDIUM MATHEMATICAL SPACE
00 3000    IDEOGRAPHIC SPACE

和4个(utf-16)代码点

00 0009    <control-0009>
00 0020    SPACE
00 00A0    NO-BREAK SPACE
00 3000    IDEOGRAPHIC SPACE