Author: julien_viet
Date: 2010-11-24 11:27:38 -0500 (Wed, 24 Nov 2010)
New Revision: 5252
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/PatternBuilder.java
Log:
discovered Pattern.quote method
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/PatternBuilder.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/PatternBuilder.java 2010-11-24
15:54:30 UTC (rev 5251)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/PatternBuilder.java 2010-11-24
16:27:38 UTC (rev 5252)
@@ -49,11 +49,22 @@
public PatternBuilder litteral(String s, int from, int to)
{
- for (int i = from;i < to;i++)
+ if (from < 0)
{
- char c = s.charAt(i);
- litteral(c);
+ throw new IllegalArgumentException("No negative from argument");
}
+ if (to > s.length())
+ {
+ throw new IllegalArgumentException("No to argument greater than the string
length");
+ }
+ if (from > to)
+ {
+ throw new IllegalArgumentException("The to argument cannot be greater than
the from argument");
+ }
+ if (from < to)
+ {
+ buffer.append(Pattern.quote(s.substring(from, to)));
+ }
return this;
}
@@ -69,27 +80,7 @@
public PatternBuilder litteral(char c)
{
- switch (c)
- {
- case '*':
- case '[':
- case '\\':
- case '^':
- case '$':
- case '.':
- case '|':
- case '?':
- case '+':
- case '(':
- case ')':
- buffer.append("\\");
- buffer.append(c);
- break;
- default:
- buffer.append(c);
- break;
- }
- return this;
+ return litteral(Character.toString(c));
}
public Pattern build()
Show replies by date