You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by kn...@apache.org on 2001/06/05 16:50:34 UTC

cvs commit: xml-xerces/c/src/util/regx RegularExpression.hpp UnionToken.cpp

knoaman     01/06/05 07:50:33

  Modified:    c/src/util/regx RegularExpression.hpp UnionToken.cpp
  Log:
  Fixes to regular expression.
  
  Revision  Changes    Path
  1.5       +19 -16    xml-xerces/c/src/util/regx/RegularExpression.hpp
  
  Index: RegularExpression.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/util/regx/RegularExpression.hpp,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RegularExpression.hpp	2001/05/11 13:26:46	1.4
  +++ RegularExpression.hpp	2001/06/05 14:50:31	1.5
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: RegularExpression.hpp,v 1.4 2001/05/11 13:26:46 tng Exp $
  + * $Id: RegularExpression.hpp,v 1.5 2001/06/05 14:50:31 knoaman Exp $
    */
   
   #if !defined(REGULAREXPRESSION_HPP)
  @@ -88,7 +88,7 @@
       // -----------------------------------------------------------------------
       //  Public Constructors and Destructor
       // -----------------------------------------------------------------------
  -	RegularExpression(const char* const pattern);
  +    RegularExpression(const char* const pattern);
       RegularExpression(const char* const pattern, const char* const options);
       RegularExpression(const XMLCh* const pattern);
       RegularExpression(const XMLCh* const pattern, const XMLCh* const options);
  @@ -125,11 +125,11 @@
       // -----------------------------------------------------------------------
       //  Matching methods
       // -----------------------------------------------------------------------
  -	bool matches(const char* const matchString);
  -	bool matches(const char* const matchString, const int start,
  +    bool matches(const char* const matchString);
  +    bool matches(const char* const matchString, const int start,
                    const int end);
  -	bool matches(const char* const matchString, Match* const pMatch);
  -	bool matches(const char* const matchString, const int start,
  +    bool matches(const char* const matchString, Match* const pMatch);
  +    bool matches(const char* const matchString, const int start,
                    const int end, Match* const pMatch);
   
       bool matches(const XMLCh* const matchString);
  @@ -155,13 +155,13 @@
               bool nextCh(XMLInt32& ch, int& offset, const short direction);
   
               bool      fInUse;
  -			bool      fAdoptMatch;
  +            bool      fAdoptMatch;
               int       fStart;
               int       fLimit;
               int       fLength;
               int       fSize;
               int*      fOffsets;
  -			Match*    fMatch;
  +            Match*    fMatch;
               XMLCh*    fString;
   
               friend class Janitor<Context>;
  @@ -262,9 +262,9 @@
       Op*                fOperations;
       Token*             fTokenTree;
       RangeToken*        fFirstChar;
  -	static RangeToken* fWordRange;
  -	OpFactory          fOpFactory;
  -	XMLMutex           fMutex;
  +    static RangeToken* fWordRange;
  +    OpFactory          fOpFactory;
  +    XMLMutex           fMutex;
       TokenFactory*      fTokenFactory;
   };
   
  @@ -510,15 +510,18 @@
                                            const Op* const op, int offset,
                                            const short direction)
   {
  -    for (int i=0; i<op->getSize(); i++) {
  +    unsigned int opSize = op->getSize();
  +    int ret = -1;
   
  -        int ret = match(context, op->elementAt(i), offset, direction);
  +    for (unsigned int i=0; i < opSize; i++) {
   
  -        if (ret >= 0)
  -            return ret;
  +        ret = match(context, op->elementAt(i), offset, direction);
  +
  +        if (ret > 0)
  +            break;
       }
   
  -    return -1;
  +    return ret;
   }
   
   inline int RegularExpression::matchModifier(Context* const context,
  
  
  
  1.4       +55 -49    xml-xerces/c/src/util/regx/UnionToken.cpp
  
  Index: UnionToken.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/util/regx/UnionToken.cpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- UnionToken.cpp	2001/05/11 13:26:52	1.3
  +++ UnionToken.cpp	2001/06/05 14:50:32	1.4
  @@ -56,6 +56,9 @@
   
   /*
    * $Log: UnionToken.cpp,v $
  + * Revision 1.4  2001/06/05 14:50:32  knoaman
  + * Fixes to regular expression.
  + *
    * Revision 1.3  2001/05/11 13:26:52  tng
    * Copyright update.
    *
  @@ -119,85 +122,88 @@
   
       if (fChildren == 0)
           fChildren = new RefVectorOf<Token>(INITIALSIZE, false);
  -
  -    unsigned short childType = child->getTokenType();
   
  -    if (childType == UNION) {
  +    if (getTokenType() == UNION) {
   
           fChildren->addElement(child);
           return;
       }
   
  +    unsigned short childType = child->getTokenType();
  +    unsigned int   childSize = child->size();
  +
       if (childType == CONCAT) {
   
  -        for (int i = 0; i < child->size(); i++) {
  -            fChildren->addElement(child->getChild(i));
  +        for (unsigned int i = 0; i < childSize; i++) {
  +
  +            addChild(child->getChild(i), tokFactory);
           }
  +
           return;
       }
   
  -	unsigned int childSize = fChildren->size();
  -	if (childSize == 0) {
  +    unsigned int childrenSize = fChildren->size();
  +    if (childrenSize == 0) {
   
           fChildren->addElement(child);
           return;
       }
   
  -	Token* previousTok = fChildren->elementAt(childSize - 1);
  -	unsigned short previousType = previousTok->getTokenType();
  +    Token* previousTok = fChildren->elementAt(childrenSize - 1);
  +    unsigned short previousType = previousTok->getTokenType();
   
  -	if (!((previousType == CHAR || previousType == STRING)
  +    if (!((previousType == CHAR || previousType == STRING)
             && (childType == CHAR || childType == STRING))) {
   
           fChildren->addElement(child);
           return;
       }
  +
  +    // Continue
  +    XMLBuffer stringBuf;
  +
  +    if (previousType == CHAR) {
  +
  +        XMLInt32 ch = previousTok->getChar();
   
  -	// Continue
  -	XMLBuffer stringBuf;
  +        if (ch >= 0x10000) {
   
  -	if (previousType == CHAR) {
  +            XMLCh* chSurrogate = RegxUtil::decomposeToSurrogates(ch);
  +            stringBuf.append(chSurrogate);
  +            delete [] chSurrogate;
  +        }
  +        else {
  +            stringBuf.append((XMLCh) ch);
  +        }
  +
  +        previousTok = tokFactory->createString(0);
  +        fChildren->setElementAt(previousTok, childrenSize - 1);
  +    }
  +    else {
  +        stringBuf.append(previousTok->getString());
  +    }
   
  -		XMLInt32 ch = previousTok->getChar();
  +    if (childType == CHAR) {
   
  -		if (ch >= 0x10000) {
  +        XMLInt32 ch = child->getChar();
   
  -			XMLCh* chSurrogate = RegxUtil::decomposeToSurrogates(ch);
  -			stringBuf.append(chSurrogate);
  -			delete [] chSurrogate;
  -		}
  -		else {
  -			stringBuf.append((XMLCh) ch);
  -		}
  -
  -		previousTok = tokFactory->createString(0);
  -		fChildren->setElementAt(previousTok, childSize - 1);
  -	}
  -	else {
  -		stringBuf.append(previousTok->getString());
  -	}
  -
  -	if (childType == CHAR) {
  -
  -		XMLInt32 ch = child->getChar();
  -
  -		if (ch >= 0x10000) {
  -
  -			XMLCh* chSurrogate = RegxUtil::decomposeToSurrogates(ch);
  -			stringBuf.append(chSurrogate);
  -			delete [] chSurrogate;
  -		}
  -		else {
  -			stringBuf.append((XMLCh) ch);
  -		}
  -	}
  -	else {
  -		stringBuf.append(child->getString());
  -	}
  +        if (ch >= 0x10000) {
  +
  +            XMLCh* chSurrogate = RegxUtil::decomposeToSurrogates(ch);
  +            stringBuf.append(chSurrogate);
  +            delete [] chSurrogate;
  +        }
  +        else {
  +            stringBuf.append((XMLCh) ch);
  +        }
  +    }
  +    else {
  +        stringBuf.append(child->getString());
  +    }
   
  -	((StringToken*) previousTok)->setString(stringBuf.getRawBuffer());
  +    ((StringToken*) previousTok)->setString(stringBuf.getRawBuffer());
   }
   
   /**
  -  *	End of file UnionToken.cpp
  +  * End of file UnionToken.cpp
     */
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org