Refine ComponentClass::class_empty

ComponentClass::class_empty should only be used on finalized classes to
determine whether a given class contains any elements; it should not
take the cr_ucp or cps_ucp into account, as they have been folden in by
the finalize call.

Fixes our failure to identify that the pattern /[^\D\d]/8W can never
match.
This commit is contained in:
Justin Viiret 2015-11-09 12:59:36 +11:00 committed by Matthew Barr
parent c68bfe05d8
commit 9cffa7666f
5 changed files with 11 additions and 5 deletions

View File

@ -52,7 +52,8 @@ AsciiComponentClass *AsciiComponentClass::clone() const {
} }
bool AsciiComponentClass::class_empty(void) const { bool AsciiComponentClass::class_empty(void) const {
return cr.none() && cr_ucp.none(); assert(finalized);
return cr.none();
} }
void AsciiComponentClass::createRange(unichar to) { void AsciiComponentClass::createRange(unichar to) {

View File

@ -441,7 +441,6 @@ void ComponentClass::addDash(void) {
} }
void ComponentClass::negate() { void ComponentClass::negate() {
assert(class_empty());
m_negate = true; m_negate = true;
} }

View File

@ -232,8 +232,12 @@ public:
Component *accept(ComponentVisitor &v) override = 0; Component *accept(ComponentVisitor &v) override = 0;
void accept(ConstComponentVisitor &v) const override = 0; void accept(ConstComponentVisitor &v) const override = 0;
/** True iff we have already started adding members to the class. This is /** \brief True if the class contains no members (i.e. it will not match
* a different concept to Component::empty */ * against anything). This function can only be called on a finalized
* class.
*
* Note: This is a different concept to Component::empty.
*/
virtual bool class_empty(void) const = 0; virtual bool class_empty(void) const = 0;
virtual void add(PredefinedClass c, bool negated) = 0; virtual void add(PredefinedClass c, bool negated) = 0;

View File

@ -484,7 +484,8 @@ UTF8ComponentClass *UTF8ComponentClass::clone() const {
} }
bool UTF8ComponentClass::class_empty(void) const { bool UTF8ComponentClass::class_empty(void) const {
return cps.none() && cps_ucp.none(); assert(finalized);
return cps.none();
} }
void UTF8ComponentClass::createRange(unichar to) { void UTF8ComponentClass::createRange(unichar to) {

View File

@ -132,3 +132,4 @@
132:/[a[==]]/ #Unsupported POSIX collating element at index 2. 132:/[a[==]]/ #Unsupported POSIX collating element at index 2.
133:/[a[.\].]]/ #Unsupported POSIX collating element at index 2. 133:/[a[.\].]]/ #Unsupported POSIX collating element at index 2.
134:/[a[=\]=]]/ #Unsupported POSIX collating element at index 2. 134:/[a[=\]=]]/ #Unsupported POSIX collating element at index 2.
135:/[^\D\d]/8W #Pattern can never match.