You are viewing a plain text version of this content. The canonical link for it is here.
Posted to regexp-dev@jakarta.apache.org by bu...@apache.org on 2001/09/28 23:53:40 UTC
DO NOT REPLY [Bug 3877] -
{0,n} matches 0 to n+1 instead of 0 to n times.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=3877>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=3877
{0,n} matches 0 to n+1 instead of 0 to n times.
chriss@calweb.com changed:
What |Removed |Added
----------------------------------------------------------------------------
OS/Version|Solaris |Windows NT/2K
Platform|Sun |PC
Summary|{n} and {n,m} not thread |{0,n} matches 0 to n+1
|safe |instead of 0 to n times.
------- Additional Comments From chriss@calweb.com 2001-09-28 14:53 -------
I fixed the problem in the compiler by changing the method void bracket()...
/**
* Match bracket {m,n} expression put results in bracket member variables
* @exception RESyntaxException Thrown if the regular expression has
invalid syntax.
*/
void bracket() throws RESyntaxException
{
// Current character must be a '{'
if (idx >= len || pattern.charAt(idx++) != '{')
{
internalError();
}
// Next char must be a digit
if (idx >= len || !Character.isDigit(pattern.charAt(idx)))
{
syntaxError("Expected digit");
}
// Get min ('m' of {m,n}) number
StringBuffer number = new StringBuffer();
while (idx < len && Character.isDigit(pattern.charAt(idx)))
{
number.append(pattern.charAt(idx++));
}
try
{
bracketMin[brackets] = Integer.parseInt(number.toString());
}
catch (NumberFormatException e)
{
syntaxError("Expected valid number");
}
// If out of input, fail
if (idx >= len)
{
syntaxError("Expected comma or right bracket");
}
// If end of expr, optional limit is 0
if (pattern.charAt(idx) == '}')
{
if (bracketMin[brackets] < 1)
{
syntaxError("Bad zero range");
}
idx++;
bracketOpt[brackets] = 0;
return;
}
// Must have at least {m,} and maybe {m,n}.
if (idx >= len || pattern.charAt(idx++) != ',')
{
syntaxError("Expected comma");
}
// If out of input, fail
if (idx >= len)
{
syntaxError("Expected comma or right bracket");
}
// If {m,} max is unlimited
if (pattern.charAt(idx) == '}')
{
idx++;
bracketOpt[brackets] = bracketUnbounded;
return;
}
// Next char must be a digit
if (idx >= len || !Character.isDigit(pattern.charAt(idx)))
{
syntaxError("Expected digit");
}
// Get max number
number.setLength(0);
while (idx < len && Character.isDigit(pattern.charAt(idx)))
{
number.append(pattern.charAt(idx++));
}
try
{
bracketOpt[brackets] = Integer.parseInt(number.toString()) -
bracketMin[brackets];
/**/
if (bracketMin[brackets] < 1)
bracketOpt[brackets]--;
/**/
}
catch (NumberFormatException e)
{
syntaxError("Expected valid number");
}
// Optional repetitions must be > 0
/*
if (bracketOpt[brackets] <= 0)
*/
if (bracketOpt[brackets] < 0)
{
syntaxError("Bad range");
}
// Must have close brace
if (idx >= len || pattern.charAt(idx++) != '}')
{
syntaxError("Missing close brace");
}
}