Author: amassari
Date: Mon Jan 16 02:16:57 2006
New Revision: 369420
URL: http://svn.apache.org/viewcvs?rev=369420&view=rev
Log:
When evaluating a union in a regular expression, take the branch that matches
the longest part of the input string (jira#1521)
Modified:
xerces/c/trunk/src/xercesc/util/regx/RegularExpression.cpp
xerces/c/trunk/src/xercesc/util/regx/RegularExpression.hpp
Modified: xerces/c/trunk/src/xercesc/util/regx/RegularExpression.cpp
URL:
http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/util/regx/RegularExpression.cpp?rev=369420&r1=369419&r2=369420&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/regx/RegularExpression.cpp (original)
+++ xerces/c/trunk/src/xercesc/util/regx/RegularExpression.cpp Mon Jan 16
02:16:57 2006
@@ -135,6 +135,62 @@
{
}
+RegularExpression::Context::Context(Context* src) :
+ fAdoptMatch(false)
+ , fStart(src->fStart)
+ , fLimit(src->fLimit)
+ , fLength(src->fLength)
+ , fSize(src->fSize)
+ , fStringMaxLen(src->fStringMaxLen)
+ , fOffsets(0)
+ , fMatch(0)
+ , fString(src->fString)
+ , fMemoryManager(src->fMemoryManager)
+{
+ if(src->fOffsets)
+ {
+ fOffsets = (int*) fMemoryManager->allocate(fSize* sizeof(int));
+ for (int i = 0; i< fSize; i++)
+ fOffsets[i] = src->fOffsets[i];
+ }
+ if(src->fMatch)
+ {
+ fMatch=new Match(*src->fMatch);
+ fAdoptMatch=true;
+ }
+}
+
+RegularExpression::Context& RegularExpression::Context::operator= (const
RegularExpression::Context& other)
+{
+ fStart=other.fStart;
+ fLimit=other.fLimit;
+ fLength=other.fLength;
+ fSize=other.fSize;
+ fStringMaxLen=other.fStringMaxLen;
+ fString=other.fString;
+ if (fOffsets)
+ fMemoryManager->deallocate(fOffsets);//delete [] fOffsets;
+ fOffsets=0;
+ if (fAdoptMatch)
+ delete fMatch;
+ fMatch=0;
+ fAdoptMatch=false;
+
+ fMemoryManager=other.fMemoryManager;
+ if(other.fOffsets)
+ {
+ fOffsets = (int*) fMemoryManager->allocate(fSize* sizeof(int));
+ for (int i = 0; i< fSize; i++)
+ fOffsets[i] = other.fOffsets[i];
+ }
+ if(other.fMatch)
+ {
+ fMatch=new Match(*other.fMatch);
+ fAdoptMatch=true;
+ }
+ return *this;
+}
+
RegularExpression::Context::~Context()
{
if (fOffsets)
@@ -1329,6 +1385,29 @@
context->fMatch->setEndPos(-index, save);
return ret;
}
+
+int RegularExpression::matchUnion(Context* const context,
+ const Op* const op, int offset,
+ const short direction)
+{
+ unsigned int opSize = op->getSize();
+
+ Context bestResultContext;
+ int bestResult=-1;
+ for(unsigned int i=0; i < opSize; i++) {
+ Context tmpContext(context);
+ int ret = match(&tmpContext, op->elementAt(i), offset, direction);
+ if (ret >= 0 && ret <= context->fLimit && ret>bestResult)
+ {
+ bestResult=ret;
+ bestResultContext=tmpContext;
+ }
+ }
+ if(bestResult!=-1)
+ *context=bestResultContext;
+ return bestResult;
+}
+
bool RegularExpression::matchCondition(Context* const context,
const Op* const op, int offset,
Modified: xerces/c/trunk/src/xercesc/util/regx/RegularExpression.hpp
URL:
http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/util/regx/RegularExpression.hpp?rev=369420&r1=369419&r2=369420&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/regx/RegularExpression.hpp (original)
+++ xerces/c/trunk/src/xercesc/util/regx/RegularExpression.hpp Mon Jan 16
02:16:57 2006
@@ -158,8 +158,10 @@
{
public :
Context(MemoryManager* const manager =
XMLPlatformUtils::fgMemoryManager);
+ Context(Context* src);
~Context();
+ Context& operator= (const Context& other);
inline const XMLCh* getString() const { return fString; }
void reset(const XMLCh* const string, const int stringLen,
const int start, const int limit, const int noClosures);
@@ -546,24 +548,6 @@
}
return ret;
- }
-
- inline int RegularExpression::matchUnion(Context* const context,
- const Op* const op, int offset,
- const short direction)
- {
- unsigned int opSize = op->getSize();
- int ret = -1;
-
- for (unsigned int i=0; i < opSize; i++) {
-
- ret = match(context, op->elementAt(i), offset, direction);
-
- if (ret >= 0 && ret <= context->fLimit)
- return ret;
- }
-
- return -1;
}
inline int RegularExpression::matchModifier(Context* const context,
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]