You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by eb...@apache.org on 2009/05/29 12:23:41 UTC

svn commit: r779915 [1/3] - in /commons/proper/jxpath/trunk/src: java/org/apache/commons/jxpath/ri/ java/org/apache/commons/jxpath/ri/compiler/ java/org/apache/commons/jxpath/ri/parser/ test/org/apache/commons/jxpath/ri/ test/org/apache/commons/jxpath/...

Author: ebourg
Date: Fri May 29 10:23:40 2009
New Revision: 779915

URL: http://svn.apache.org/viewvc?rev=779915&view=rev
Log:
Implemented the ends-with function (JXPATH-132)

Modified:
    commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/Compiler.java
    commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java
    commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/parser/XPath.html
    commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/parser/XPath.jj
    commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/parser/XPathParser.java
    commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/parser/XPathParserConstants.java
    commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/parser/XPathParserTokenManager.java
    commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/parser/jcc.bat
    commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/JXPathCompiledExpressionTest.java
    commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/CoreFunctionTest.java

Modified: commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/Compiler.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/Compiler.java?rev=779915&r1=779914&r2=779915&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/Compiler.java (original)
+++ commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/Compiler.java Fri May 29 10:23:40 2009
@@ -96,6 +96,8 @@
     public static final int FUNCTION_NULL = 28;
     public static final int FUNCTION_KEY = 29;
     public static final int FUNCTION_FORMAT_NUMBER = 30;
+    
+    public static final int FUNCTION_ENDS_WITH = 31;
 
     /**
      * Produces an EXPRESSION object that represents a numeric constant.

Modified: commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java?rev=779915&r1=779914&r2=779915&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java (original)
+++ commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java Fri May 29 10:23:40 2009
@@ -89,6 +89,8 @@
                 return "concat";
             case Compiler.FUNCTION_STARTS_WITH :
                 return "starts-with";
+            case Compiler.FUNCTION_ENDS_WITH :
+                return "ends-with";
             case Compiler.FUNCTION_CONTAINS :
                 return "contains";
             case Compiler.FUNCTION_SUBSTRING_BEFORE :
@@ -199,6 +201,7 @@
             case Compiler.FUNCTION_ID:
             case Compiler.FUNCTION_CONCAT:
             case Compiler.FUNCTION_STARTS_WITH:
+            case Compiler.FUNCTION_ENDS_WITH:
             case Compiler.FUNCTION_CONTAINS:
             case Compiler.FUNCTION_SUBSTRING_BEFORE:
             case Compiler.FUNCTION_SUBSTRING_AFTER:
@@ -263,6 +266,8 @@
                 return functionConcat(context);
             case Compiler.FUNCTION_STARTS_WITH :
                 return functionStartsWith(context);
+            case Compiler.FUNCTION_ENDS_WITH :
+                return functionEndsWith(context);
             case Compiler.FUNCTION_CONTAINS :
                 return functionContains(context);
             case Compiler.FUNCTION_SUBSTRING_BEFORE :
@@ -543,6 +548,19 @@
     }
 
     /**
+     * ends-with() implementation.
+     * @param context evaluation context
+     * @return Boolean
+     * @since 1.4
+     */
+    protected Object functionEndsWith(EvalContext context) {
+        assertArgCount(2);
+        String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context));
+        String s2 = InfoSetUtil.stringValue(getArg2().computeValue(context));
+        return s1.endsWith(s2) ? Boolean.TRUE : Boolean.FALSE;
+    }
+
+    /**
      * contains() implementation.
      * @param context evaluation context
      * @return Boolean

Modified: commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/parser/XPath.html
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/parser/XPath.html?rev=779915&r1=779914&r2=779915&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/parser/XPath.html (original)
+++ commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/parser/XPath.html Fri May 29 10:23:40 2009
@@ -26,7 +26,7 @@
 <TR>
 <TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod1">NCName</A></TD>
 <TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
-<TD ALIGN=LEFT VALIGN=BASELINE>( <A HREF="#prod2">NCName_Without_CoreFunctions</A> | &lt;NODE&gt; | &lt;TEXT&gt; | &lt;COMMENT&gt; | &lt;PI&gt; | &lt;FUNCTION_LAST&gt; | &lt;FUNCTION_POSITION&gt; | &lt;FUNCTION_COUNT&gt; | &lt;FUNCTION_ID&gt; | &lt;FUNCTION_LOCAL_NAME&gt; | &lt;FUNCTION_NAMESPACE_URI&gt; | &lt;FUNCTION_NAME&gt; | &lt;FUNCTION_STRING&gt; | &lt;FUNCTION_CONCAT&gt; | &lt;FUNCTION_STARTS_WITH&gt; | &lt;FUNCTION_CONTAINS&gt; | &lt;FUNCTION_SUBSTRING_BEFORE&gt; | &lt;FUNCTION_SUBSTRING_AFTER&gt; | &lt;FUNCTION_SUBSTRING&gt; | &lt;FUNCTION_STRING_LENGTH&gt; | &lt;FUNCTION_NORMALIZE_SPACE&gt; | &lt;FUNCTION_TRANSLATE&gt; | &lt;FUNCTION_BOOLEAN&gt; | &lt;FUNCTION_NOT&gt; | &lt;FUNCTION_TRUE&gt; | &lt;FUNCTION_FALSE&gt; | &lt;FUNCTION_NULL&gt; | &lt;FUNCTION_LANG&gt; | &lt;FUNCTION_NUMBER&gt; | &lt;FUNCTION_SUM&gt; | &lt;FUNCTION_FLOOR&gt; | &lt;FUNCTION_CEILING&gt; | &lt;FUNCTION_ROUND&gt; | &lt;FUNCTION_KEY&gt; | &lt;FUNCTION_FORMAT_NUMBER&gt; )</TD>
+<TD ALIGN=LEFT VALIGN=BASELINE>( <A HREF="#prod2">NCName_Without_CoreFunctions</A> | &lt;NODE&gt; | &lt;TEXT&gt; | &lt;COMMENT&gt; | &lt;PI&gt; | &lt;FUNCTION_LAST&gt; | &lt;FUNCTION_POSITION&gt; | &lt;FUNCTION_COUNT&gt; | &lt;FUNCTION_ID&gt; | &lt;FUNCTION_LOCAL_NAME&gt; | &lt;FUNCTION_NAMESPACE_URI&gt; | &lt;FUNCTION_NAME&gt; | &lt;FUNCTION_STRING&gt; | &lt;FUNCTION_CONCAT&gt; | &lt;FUNCTION_STARTS_WITH&gt; | &lt;FUNCTION_ENDS_WITH&gt; | &lt;FUNCTION_CONTAINS&gt; | &lt;FUNCTION_SUBSTRING_BEFORE&gt; | &lt;FUNCTION_SUBSTRING_AFTER&gt; | &lt;FUNCTION_SUBSTRING&gt; | &lt;FUNCTION_STRING_LENGTH&gt; | &lt;FUNCTION_NORMALIZE_SPACE&gt; | &lt;FUNCTION_TRANSLATE&gt; | &lt;FUNCTION_BOOLEAN&gt; | &lt;FUNCTION_NOT&gt; | &lt;FUNCTION_TRUE&gt; | &lt;FUNCTION_FALSE&gt; | &lt;FUNCTION_NULL&gt; | &lt;FUNCTION_LANG&gt; | &lt;FUNCTION_NUMBER&gt; | &lt;FUNCTION_SUM&gt; | &lt;FUNCTION_FLOOR&gt; | &lt;FUNCTION_CEILING&gt; | &lt;FUNCTION_ROUND&gt; | &lt;FUNCTION_KEY&gt; | &lt;FUNCTION_FORMAT_NUMB
 ER&gt; )</TD>
 </TR>
 <TR>
 <TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod2">NCName_Without_CoreFunctions</A></TD>
@@ -36,7 +36,7 @@
 <TR>
 <TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod3">CoreFunctionName</A></TD>
 <TD ALIGN=CENTER VALIGN=BASELINE>::=</TD>
-<TD ALIGN=LEFT VALIGN=BASELINE>( &lt;FUNCTION_LAST&gt; | &lt;FUNCTION_POSITION&gt; | &lt;FUNCTION_COUNT&gt; | &lt;FUNCTION_ID&gt; | &lt;FUNCTION_LOCAL_NAME&gt; | &lt;FUNCTION_NAMESPACE_URI&gt; | &lt;FUNCTION_NAME&gt; | &lt;FUNCTION_STRING&gt; | &lt;FUNCTION_CONCAT&gt; | &lt;FUNCTION_STARTS_WITH&gt; | &lt;FUNCTION_CONTAINS&gt; | &lt;FUNCTION_SUBSTRING_BEFORE&gt; | &lt;FUNCTION_SUBSTRING_AFTER&gt; | &lt;FUNCTION_SUBSTRING&gt; | &lt;FUNCTION_STRING_LENGTH&gt; | &lt;FUNCTION_NORMALIZE_SPACE&gt; | &lt;FUNCTION_TRANSLATE&gt; | &lt;FUNCTION_BOOLEAN&gt; | &lt;FUNCTION_NOT&gt; | &lt;FUNCTION_TRUE&gt; | &lt;FUNCTION_FALSE&gt; | &lt;FUNCTION_NULL&gt; | &lt;FUNCTION_LANG&gt; | &lt;FUNCTION_NUMBER&gt; | &lt;FUNCTION_SUM&gt; | &lt;FUNCTION_FLOOR&gt; | &lt;FUNCTION_CEILING&gt; | &lt;FUNCTION_ROUND&gt; | &lt;FUNCTION_KEY&gt; | &lt;FUNCTION_FORMAT_NUMBER&gt; )</TD>
+<TD ALIGN=LEFT VALIGN=BASELINE>( &lt;FUNCTION_LAST&gt; | &lt;FUNCTION_POSITION&gt; | &lt;FUNCTION_COUNT&gt; | &lt;FUNCTION_ID&gt; | &lt;FUNCTION_LOCAL_NAME&gt; | &lt;FUNCTION_NAMESPACE_URI&gt; | &lt;FUNCTION_NAME&gt; | &lt;FUNCTION_STRING&gt; | &lt;FUNCTION_CONCAT&gt; | &lt;FUNCTION_STARTS_WITH&gt; | &lt;FUNCTION_ENDS_WITH&gt; | &lt;FUNCTION_CONTAINS&gt; | &lt;FUNCTION_SUBSTRING_BEFORE&gt; | &lt;FUNCTION_SUBSTRING_AFTER&gt; | &lt;FUNCTION_SUBSTRING&gt; | &lt;FUNCTION_STRING_LENGTH&gt; | &lt;FUNCTION_NORMALIZE_SPACE&gt; | &lt;FUNCTION_TRANSLATE&gt; | &lt;FUNCTION_BOOLEAN&gt; | &lt;FUNCTION_NOT&gt; | &lt;FUNCTION_TRUE&gt; | &lt;FUNCTION_FALSE&gt; | &lt;FUNCTION_NULL&gt; | &lt;FUNCTION_LANG&gt; | &lt;FUNCTION_NUMBER&gt; | &lt;FUNCTION_SUM&gt; | &lt;FUNCTION_FLOOR&gt; | &lt;FUNCTION_CEILING&gt; | &lt;FUNCTION_ROUND&gt; | &lt;FUNCTION_KEY&gt; | &lt;FUNCTION_FORMAT_NUMBER&gt; )</TD>
 </TR>
 <TR>
 <TD ALIGN=RIGHT VALIGN=BASELINE><A NAME="prod4">QName</A></TD>

Modified: commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/parser/XPath.jj
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/parser/XPath.jj?rev=779915&r1=779914&r2=779915&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/parser/XPath.jj (original)
+++ commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/parser/XPath.jj Fri May 29 10:23:40 2009
@@ -281,6 +281,7 @@
 |   <FUNCTION_STRING: "string">
 |   <FUNCTION_CONCAT: "concat">
 |   <FUNCTION_STARTS_WITH: "starts-with">
+|   <FUNCTION_ENDS_WITH: "ends-with">
 |   <FUNCTION_CONTAINS: "contains">
 |   <FUNCTION_SUBSTRING_BEFORE: "substring-before">
 |   <FUNCTION_SUBSTRING_AFTER: "substring-after">
@@ -326,6 +327,7 @@
     |   <FUNCTION_STRING>
     |   <FUNCTION_CONCAT>
     |   <FUNCTION_STARTS_WITH>
+    |   <FUNCTION_ENDS_WITH>
     |   <FUNCTION_CONTAINS>
     |   <FUNCTION_SUBSTRING_BEFORE>
     |   <FUNCTION_SUBSTRING_AFTER>
@@ -383,6 +385,7 @@
     |   <FUNCTION_STRING>           { code = Compiler.FUNCTION_STRING; }
     |   <FUNCTION_CONCAT>           { code = Compiler.FUNCTION_CONCAT; }
     |   <FUNCTION_STARTS_WITH>      { code = Compiler.FUNCTION_STARTS_WITH; }
+    |   <FUNCTION_ENDS_WITH>        { code = Compiler.FUNCTION_ENDS_WITH; }
     |   <FUNCTION_CONTAINS>         { code = Compiler.FUNCTION_CONTAINS; }
     |   <FUNCTION_SUBSTRING_BEFORE> { code = Compiler.FUNCTION_SUBSTRING_BEFORE; }
     |   <FUNCTION_SUBSTRING_AFTER>  { code = Compiler.FUNCTION_SUBSTRING_AFTER; }