Visual Studio 2015でPOSIX文字クラス[:blank:]
を使用している場合、改行と改行が一致しないことが予想されますが、これは私が見ている動作ではありません。C++の17文字クラス[:blank:]が改行とキャリッジリターンに一致するのはなぜですか?
http://www.cplusplus.com/reference/regex/ECMAScript/は、POSIX文字クラス[:blank:]
がisblank
と同等であることを示していますが、それらは並んでいません。 isblank
は空白とタブで肯定を返しますが、復帰と改行ではfalseを返しますが、[:blank:]
は空白、タブ、改行、およびキャリッジリターンと一致します。ここで
は私のサンプルコードです:予想通り
Mismatch found between isblank & [[:blank:]] for \r
Mismatch found between isblank & [[:blank:]] for \n
[ \t]
行為が、[[:blank:]]
マッチ\r
と\n
:
#include <cctype>
#include <iostream>
#include <regex>
#include <string>
using namespace std;
bool reMatches(const regex &re, const char c)
{
return regex_search(string(1, c), re);
}
bool isBlank(const char c)
{
return isblank(c) != 0;
}
int main() {
const char testChars[] = { ' ', '\t', '\r', '\n', '.' };
const char *dispChars[] = { " ", "\\t", "\\r", "\\n", "." };
regex explicitClass("[ \t]");
regex posixClass("[[:blank:]]");
for (unsigned i = 0; i < sizeof(testChars); ++i)
{
char c = testChars[i];
if (isBlank(c) != reMatches(explicitClass, c))
cout << "Mismatch found between isblank & [ \t] for " << dispChars[i] << std::endl;
if (isBlank(c) != reMatches(posixClass, c))
cout << "Mismatch found between isblank & [[:blank:]] for " << dispChars[i] << std::endl;
}
}
ここで結果の出力です!私は何か間違っているのですか?