Regex: Tweak is_ctype implementation style

This commit is contained in:
Maxime Coste 2017-11-28 00:13:42 +08:00
parent d142db80f2
commit a52da6fe34
2 changed files with 14 additions and 23 deletions

View File

@ -1091,23 +1091,14 @@ bool is_character_class(const CharacterClass& character_class, Codepoint cp)
bool is_ctype(CharacterType ctype, Codepoint cp)
{
if ((ctype & CharacterType::Digit) and iswdigit(cp))
return true;
if ((ctype & CharacterType::Word) and is_word(cp))
return true;
if ((ctype & CharacterType::Whitespace) and is_blank(cp))
return true;
if ((ctype & CharacterType::HorizontalWhitespace) and is_horizontal_blank(cp))
return true;
if ((ctype & CharacterType::NotDigit) and not iswdigit(cp))
return true;
if ((ctype & CharacterType::NotWord) and not is_word(cp))
return true;
if ((ctype & CharacterType::NotWhitespace) and not is_blank(cp))
return true;
if ((ctype & CharacterType::NotHorizontalWhitespace) and not is_horizontal_blank(cp))
return true;
return false;
return ((ctype & CharacterType::Whitespace) and is_blank(cp)) or
((ctype & CharacterType::HorizontalWhitespace) and is_horizontal_blank(cp)) or
((ctype & CharacterType::Digit) and iswdigit(cp)) or
((ctype & CharacterType::Word) and is_word(cp)) or
((ctype & CharacterType::NotWhitespace) and not is_blank(cp)) or
((ctype & CharacterType::NotHorizontalWhitespace) and not is_horizontal_blank(cp)) or
((ctype & CharacterType::NotDigit) and not iswdigit(cp)) or
((ctype & CharacterType::NotWord) and not is_word(cp));
}
namespace

View File

@ -26,13 +26,13 @@ enum class MatchDirection
enum class CharacterType : unsigned char
{
None = 0,
Word = 1 << 0,
Whitespace = 1 << 1,
HorizontalWhitespace = 1 << 2,
Whitespace = 1 << 0,
HorizontalWhitespace = 1 << 1,
Word = 1 << 2,
Digit = 1 << 3,
NotWord = 1 << 4,
NotWhitespace = 1 << 5,
NotHorizontalWhitespace = 1 << 6,
NotWhitespace = 1 << 4,
NotHorizontalWhitespace = 1 << 5,
NotWord = 1 << 6,
NotDigit = 1 << 7
};
constexpr bool with_bit_ops(Meta::Type<CharacterType>) { return true; }