You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mu...@apache.org on 2024/06/21 07:05:14 UTC

(xalan-java) branch xalan-j_xslt3.0 updated: committing implementation of xpath3.1 function fn:analyze-string, with few working related conformance test cases. doing little bit of code refactoring as well.

This is an automated email from the ASF dual-hosted git repository.

mukulg pushed a commit to branch xalan-j_xslt3.0
in repository https://gitbox.apache.org/repos/asf/xalan-java.git


The following commit(s) were added to refs/heads/xalan-j_xslt3.0 by this push:
     new f89441f2 committing implementation of xpath3.1 function fn:analyze-string, with few working related conformance test cases. doing little bit of code refactoring as well.
f89441f2 is described below

commit f89441f29169a9d80b1fa9492e179045fc24ec31
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Fri Jun 21 12:35:02 2024 +0530

    committing implementation of xpath3.1 function fn:analyze-string, with few working related conformance test cases. doing little bit of code refactoring as well.
---
 .../apache/xalan/templates/ElemAnalyzeString.java  |   2 +-
 src/org/apache/xalan/templates/FuncRegexGroup.java |   2 +-
 src/org/apache/xpath/compiler/FunctionTable.java   |   9 +-
 src/org/apache/xpath/compiler/Keywords.java        |   3 +
 .../apache/xpath/functions/FuncAnalyzeString.java  | 339 +++++++++++++++++++++
 src/org/apache/xpath/functions/FuncMatches.java    |   2 +-
 src/org/apache/xpath/functions/FuncReplace.java    |   2 +-
 src/org/apache/xpath/functions/FuncTokenize.java   |   2 +-
 .../xpath/functions/RegexEvaluationSupport.java    |  10 +-
 tests/fn_analyze_string/gold/test1.out             |   3 +
 tests/fn_analyze_string/gold/test2.out             |  14 +
 tests/fn_analyze_string/gold/test3.out             |   8 +
 tests/fn_analyze_string/gold/test4.out             |  11 +
 tests/fn_analyze_string/gold/test5.out             |  11 +
 tests/fn_analyze_string/test1.xsl                  |  34 +++
 tests/fn_analyze_string/test2.xsl                  |  34 +++
 tests/fn_analyze_string/test3.xsl                  |  34 +++
 tests/fn_analyze_string/test4.xsl                  |  34 +++
 tests/fn_analyze_string/test5.xml                  |   2 +
 tests/fn_analyze_string/test5.xsl                  |  36 +++
 .../apache/xalan/xpath3/FnAnalyzeStringTests.java  | 102 +++++++
 tests/org/apache/xalan/xslt3/Xsl3TestSuite1.java   |   3 +-
 22 files changed, 687 insertions(+), 10 deletions(-)

diff --git a/src/org/apache/xalan/templates/ElemAnalyzeString.java b/src/org/apache/xalan/templates/ElemAnalyzeString.java
index 98ac76c7..143fd99b 100644
--- a/src/org/apache/xalan/templates/ElemAnalyzeString.java
+++ b/src/org/apache/xalan/templates/ElemAnalyzeString.java
@@ -253,7 +253,7 @@ public class ElemAnalyzeString extends ElemTemplateElement implements Expression
 
        String effectiveRegexStrValue = m_regex.evaluate(xctxt, xctxt.getContextNode(), this);
        
-       Matcher regexMatcher = RegexEvaluationSupport.compileAndExecute(RegexEvaluationSupport.trfPatternStrForSubtraction(
+       Matcher regexMatcher = RegexEvaluationSupport.compileAndExecute(RegexEvaluationSupport.transformRegexStrForSubtractionOp(
                                                                                     effectiveRegexStrValue), m_regex_flags, strToBeAnalyzed);
        
        ElemTemplateElement templateElem1 = this.m_firstChild;
diff --git a/src/org/apache/xalan/templates/FuncRegexGroup.java b/src/org/apache/xalan/templates/FuncRegexGroup.java
index 5faddcca..6e75c98f 100644
--- a/src/org/apache/xalan/templates/FuncRegexGroup.java
+++ b/src/org/apache/xalan/templates/FuncRegexGroup.java
@@ -90,7 +90,7 @@ public class FuncRegexGroup extends FunctionOneArg
         String regex = customDataMap.get(ElemMatchingSubstring.REGEX);
         String regexFlags = customDataMap.get(ElemMatchingSubstring.REGEX_FLAGS);
         
-        Matcher regexMatcher = RegexEvaluationSupport.compileAndExecute(RegexEvaluationSupport.trfPatternStrForSubtraction(
+        Matcher regexMatcher = RegexEvaluationSupport.compileAndExecute(RegexEvaluationSupport.transformRegexStrForSubtractionOp(
                                                                                    regex), regexFlags, strValue);
         String regexGrpStr = null;
         if (regexMatcher.matches()) {
diff --git a/src/org/apache/xpath/compiler/FunctionTable.java b/src/org/apache/xpath/compiler/FunctionTable.java
index 2806e258..ebf10b18 100644
--- a/src/org/apache/xpath/compiler/FunctionTable.java
+++ b/src/org/apache/xpath/compiler/FunctionTable.java
@@ -513,6 +513,9 @@ public class FunctionTable
   
   /** The 'json-doc()' id. */
   public static final int FUNC_JSON_DOC = 163;
+  
+  /** The 'analyze-string()' id. */
+  public static final int FUNC_ANALYZE_STRING = 164;
 
   // Proprietary
 
@@ -606,7 +609,7 @@ public class FunctionTable
    * Number of built in functions. Be sure to update this as
    * built-in functions are added.
    */
-  private static final int NUM_BUILT_IN_FUNCS = 164;
+  private static final int NUM_BUILT_IN_FUNCS = 165;
 
   /**
    * Number of built-in functions that may be added.
@@ -701,6 +704,8 @@ public class FunctionTable
       org.apache.xalan.templates.FuncRegexGroup.class;
     m_functions[FUNC_TOKENIZE] = 
       org.apache.xpath.functions.FuncTokenize.class;
+    m_functions[FUNC_ANALYZE_STRING] = 
+      org.apache.xpath.functions.FuncAnalyzeString.class;
     m_functions[FUNC_UNPARSED_TEXT] = 
       org.apache.xpath.functions.FuncUnparsedText.class;
     m_functions[FUNC_STRING_JOIN] = 
@@ -972,6 +977,8 @@ public class FunctionTable
                           new Integer(FunctionTable.FUNC_REGEX_GROUP));
           m_functionID.put(Keywords.FUNC_TOKENIZE,
                           new Integer(FunctionTable.FUNC_TOKENIZE));
+          m_functionID.put(Keywords.FUNC_ANALYZE_STRING,
+                          new Integer(FunctionTable.FUNC_ANALYZE_STRING));
           m_functionID.put(Keywords.FUNC_UNPARSED_TEXT,
                           new Integer(FunctionTable.FUNC_UNPARSED_TEXT));
           m_functionID.put(Keywords.FUNC_STRING_JOIN,
diff --git a/src/org/apache/xpath/compiler/Keywords.java b/src/org/apache/xpath/compiler/Keywords.java
index 6bd29de7..77c0674c 100644
--- a/src/org/apache/xpath/compiler/Keywords.java
+++ b/src/org/apache/xpath/compiler/Keywords.java
@@ -247,6 +247,9 @@ public class Keywords
   /** tokenize function string. */
   public static final String FUNC_TOKENIZE = "tokenize";
   
+  /** analyze-string function string. */
+  public static final String FUNC_ANALYZE_STRING = "analyze-string";
+  
   /** unparsed-text function string. */
   public static final String FUNC_UNPARSED_TEXT = "unparsed-text";
   
diff --git a/src/org/apache/xpath/functions/FuncAnalyzeString.java b/src/org/apache/xpath/functions/FuncAnalyzeString.java
new file mode 100644
index 00000000..8d4dde24
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncAnalyzeString.java
@@ -0,0 +1,339 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.xpath.functions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.SourceLocator;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.dom.DOMSource;
+
+import org.apache.xalan.res.XSLMessages;
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.dtm.DTMManager;
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.compiler.FunctionTable;
+import org.apache.xpath.objects.XNodeSet;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.regex.Matcher;
+import org.apache.xpath.res.XPATHErrorResources;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Text;
+
+import xml.xpath31.processor.types.XSString;
+
+/**
+ * Implementation of the fn:analyze-string function.
+ * 
+ * @author Mukul Gandhi <mu...@apache.org>
+ * 
+ * @xsl.usage advanced
+ */
+public class FuncAnalyzeString extends FunctionMultiArgs {
+
+	private static final long serialVersionUID = -1559008263985308212L;
+	
+	/**
+     * The number of arguments passed to the fn:analyze-string function 
+     * call.
+     */
+    private int fNumOfArgs = 0;
+    
+    /**
+     * Implementation of the function. The function must return a valid object.
+     * 
+     * @param xctxt The current execution context.
+     * @return A valid XObject.
+     *
+     * @throws javax.xml.transform.TransformerException
+     */
+    public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
+        
+        XObject result = null;
+        
+        SourceLocator srcLocator = xctxt.getSAXLocator();
+        
+        XObject arg0XObj = m_arg0.execute(xctxt);        
+        XObject arg1XObj = m_arg1.execute(xctxt);                                
+        
+        // Get 'string value' of string to be analyzed by fn:analyze-string 
+        // function call.
+        String strToBeAnalyzed = null;
+        if (arg0XObj instanceof XSString) {
+           strToBeAnalyzed = ((XSString)arg0XObj).stringValue();
+        }
+        else {
+     	   strToBeAnalyzed = arg0XObj.str();      	   
+        }
+        
+        // Get 'string value' of regex argument of fn:analyze-string 
+        // function call.
+        String regexStr = null;
+        if (arg1XObj instanceof XSString) {
+           regexStr = ((XSString)arg1XObj).stringValue();
+        }
+        else {
+           regexStr = arg1XObj.str();      	   
+        }
+        
+        String flagsStr = null;
+        if (m_arg2 != null) {
+           // Get 'string value' of flags argument of fn:analyze-string 
+           // function call.
+           XObject arg2XObj = m_arg2.execute(xctxt);
+           if (arg2XObj instanceof XSString) {
+        	  flagsStr = ((XSString)arg2XObj).stringValue();
+           }
+           else {
+              flagsStr = arg2XObj.str();      	   
+           }
+           
+           if (!RegexEvaluationSupport.isFlagStrValid(flagsStr)) {
+              throw new javax.xml.transform.TransformerException("XTDE1145 : Invalid regex flag value(s) is specified, "
+              		                                           + "as an argument to function call fn:analyze-string. XPath "
+              		                                           + "regex valid flag charcaters are : s, m, i, x, q.", srcLocator);    
+           }
+        }
+        
+        Document document = createEmptyXmlDom(srcLocator);
+        
+        Element analyzeStrResultElem = document.createElement("analyze-string-result");
+        analyzeStrResultElem.setAttribute("xmlns", FunctionTable.XPATH_BUILT_IN_FUNCS_NS_URI);
+        document.appendChild(analyzeStrResultElem);
+        
+        if (strToBeAnalyzed.length() > 0) {
+        	Matcher regexMatcher = RegexEvaluationSupport.compileAndExecute(
+        			                                    RegexEvaluationSupport.transformRegexStrForSubtractionOp(regexStr), 
+        			                                    flagsStr, strToBeAnalyzed);
+
+        	List<RegexMatchInfo> regexMatchInfoList = new ArrayList<RegexMatchInfo>();
+
+        	while (regexMatcher.find()) {
+        		int idx1 = regexMatcher.start();
+        		int idx2 = regexMatcher.end();
+        		RegexMatchInfo regexMatchInfo = new RegexMatchInfo();
+        		regexMatchInfo.setStartIdx(idx1);
+        		regexMatchInfo.setEndIdx(idx2);
+        		regexMatchInfoList.add(regexMatchInfo);
+        	}
+        	
+        	regexMatcher.reset();
+
+        	RegexMatchInfo firstRegexMatchInfo = regexMatchInfoList.get(0);
+        	int startIdx1 = firstRegexMatchInfo.getStartIdx();
+        	if (startIdx1 == 0) {
+        		// The string to be analyzed, starts with a 'match' node     		
+        		for (int idx = 0; idx < regexMatchInfoList.size(); idx++) {
+        			RegexMatchInfo matchInfo = regexMatchInfoList.get(idx);
+        			int idx1 = matchInfo.getStartIdx();
+        			int idx2 = matchInfo.getEndIdx();
+        			String matchStr = strToBeAnalyzed.substring(idx1, idx2);
+        			createMatchNodeToResult(document, analyzeStrResultElem, matchStr); 
+        			
+        			if (isNonMatchingStringAvailable(strToBeAnalyzed, idx2)) {
+        				String nonMatchStr = null;
+        				if ((idx + 1) == regexMatchInfoList.size()) {
+        					nonMatchStr = strToBeAnalyzed.substring(idx2);
+        				}
+        				else {
+        					RegexMatchInfo matchInfoNext = regexMatchInfoList.get(idx+1);
+        					nonMatchStr = strToBeAnalyzed.substring(idx2, matchInfoNext.getStartIdx());   
+        				}                    	                    	
+        				createNonMatchNodeToResult(document, analyzeStrResultElem, nonMatchStr);
+        			}        		
+        		 }	
+        	}
+        	else if (startIdx1 > 0) {
+        		// The string to be analyzed, starts with a 'non-match' node        		
+        		RegexMatchInfo pof1 = regexMatchInfoList.get(0);
+        		String nonMatchStr = strToBeAnalyzed.substring(0, pof1.getStartIdx());
+ 			    createNonMatchNodeToResult(document, analyzeStrResultElem, nonMatchStr);
+ 			    
+        		for (int idx = 0; idx < regexMatchInfoList.size(); idx++) {
+        			RegexMatchInfo matchInfo = regexMatchInfoList.get(idx);
+        			int idx1 = matchInfo.getStartIdx();
+        			int idx2 = matchInfo.getEndIdx();
+        			String matchStr = strToBeAnalyzed.substring(idx1, idx2);
+        			createMatchNodeToResult(document, analyzeStrResultElem, matchStr);
+
+        			if (isNonMatchingStringAvailable(strToBeAnalyzed, idx2)) {
+        				if ((idx + 1) == regexMatchInfoList.size()) {
+        					nonMatchStr = strToBeAnalyzed.substring(idx2);
+        				}
+        				else {
+        					RegexMatchInfo matchInfoNext = regexMatchInfoList.get(idx+1);
+        					nonMatchStr = strToBeAnalyzed.substring(idx2, matchInfoNext.getStartIdx());   
+        				}                    	                    	        				
+        				createNonMatchNodeToResult(document, analyzeStrResultElem, nonMatchStr);
+        			}        			
+        		}
+        	}
+        }
+        
+        DTMManager dtmMgr = xctxt.getDTMManager();             
+        DTM dtm = dtmMgr.getDTM(new DOMSource(document), true, null, false, false);            
+        result = new XNodeSet(dtm.getDocument(), dtmMgr); 
+            
+        return result;
+    }
+    
+    /**
+     * Check that the number of arguments passed to this function is correct.
+     *
+     * @param argNum The number of arguments that is being passed to the function.
+     *
+     * @throws WrongNumberArgsException
+     */
+    public void checkNumberArgs(int argNum) throws WrongNumberArgsException
+    {
+       if (!((argNum == 2) || (argNum == 3))) {
+          reportWrongNumberArgs();
+       }
+       else {
+          fNumOfArgs = argNum;   
+       }
+    }
+    
+    /**
+     * Constructs and throws a WrongNumberArgException with the appropriate
+     * message for this function object.
+     *
+     * @throws WrongNumberArgsException
+     */
+    protected void reportWrongNumberArgs() throws WrongNumberArgsException {
+        throw new WrongNumberArgsException(XSLMessages.createXPATHMessage(
+                                                                     XPATHErrorResources.ER_TWO_OR_THREE, null));
+    }
+    
+    /**
+     * A class representing, a pair of string index values,
+     * for a substring that matched with the fn:analyze-string 
+     * function's regex argument.
+     * 
+     * The result of function call fn:analyze-string, shall be
+     * determined by a list of objects of this class.
+     */
+    class RegexMatchInfo {    	
+    	private int startIdx;
+    	
+    	private int endIdx;
+    	
+    	/**
+    	 * Class constructor.
+    	 */
+    	public RegexMatchInfo() {
+    	    // NO OP
+    	}
+
+		public int getStartIdx() {
+			return startIdx;
+		}
+
+		public void setStartIdx(int startIdx) {
+			this.startIdx = startIdx;
+		}
+
+		public int getEndIdx() {
+			return endIdx;
+		}
+
+		public void setEndIdx(int endIdx) {
+			this.endIdx = endIdx;
+		}
+    }
+    
+    /**
+     * This method, checks whether an XML "non-match" element can be appended at 
+     * certain places within the result of function call fn:analyze-string. 
+     * 
+     * @param strToBeAnalyzed    this is an original string that is analyzed by 
+     *                           the function call fn:analyze-string. 
+     * @param idx2               an end index of a particular regex match
+     * @return                   true, or false result, indicating whether an
+     *                           XML "non-match" element can be constructed.
+     */
+    private boolean isNonMatchingStringAvailable(String strToBeAnalyzed, int idx2) {
+		boolean isNonMatchAvailable;
+		try {
+			isNonMatchAvailable = (strToBeAnalyzed.charAt(idx2) != -1);
+		}
+		catch (IndexOutOfBoundsException ex) {
+			isNonMatchAvailable = false;
+		}
+		return isNonMatchAvailable;
+	}
+
+	/**
+	 * Method to create an XML "non-match" element, and append to the result. 
+	 * 
+	 * @param document                    XML document node
+	 * @param analyzeStrResultElem        XML result element, that is appended with more information
+	 * @param nonMatchStr                 text value that is appended as child of XML "non-match" element 
+	 */
+	private void createNonMatchNodeToResult(Document document, Element analyzeStrResultElem, String nonMatchStr) {
+		Element nonMatchElem = document.createElement("non-match");
+		Text txtNode2 = document.createTextNode(nonMatchStr);
+		nonMatchElem.appendChild(txtNode2);
+		analyzeStrResultElem.appendChild(nonMatchElem);
+	}
+
+	/**
+	 * Method to create an XML "match" element, and append to the result. 
+	 * 
+	 * @param document                    XML document node
+	 * @param analyzeStrResultElem        XML result element, that is appended with more information
+	 * @param matchStr                    text value that is appended as child of XML "match" element 
+	 */
+	private void createMatchNodeToResult(Document document, Element analyzeStrResultElem, String matchStr) {
+		Element matchElem = document.createElement("match");
+		
+		Text txtNode1 = document.createTextNode(matchStr);
+		matchElem.appendChild(txtNode1);
+		analyzeStrResultElem.appendChild(matchElem);
+	}
+
+    /**
+     * Method to create an empty XML DOM document node.
+     * 
+     * @param srcLocator   XSL transformation sourceLocator object
+     * @return an empty DOM document node
+     */
+	private Document createEmptyXmlDom(SourceLocator srcLocator) throws TransformerException {
+		Document document = null;
+		
+		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
+        
+        DocumentBuilder dBuilder = null;		
+        try {
+		   dBuilder = dbf.newDocumentBuilder();
+		} catch (ParserConfigurationException ex) {
+		   throw new javax.xml.transform.TransformerException("FOJS0001 : An error occured, within an XML parser "
+		   		                                                      + "library.", srcLocator);
+		}
+		
+        document = dBuilder.newDocument();
+        
+		return document;
+	}
+
+}
diff --git a/src/org/apache/xpath/functions/FuncMatches.java b/src/org/apache/xpath/functions/FuncMatches.java
index bd703215..33417200 100644
--- a/src/org/apache/xpath/functions/FuncMatches.java
+++ b/src/org/apache/xpath/functions/FuncMatches.java
@@ -76,7 +76,7 @@ public class FuncMatches extends Function3Args {
         boolean result = false;
         
         try {                
-            Matcher matcher = RegexEvaluationSupport.regex(RegexEvaluationSupport.trfPatternStrForSubtraction(pattern.toString()), 
+            Matcher matcher = RegexEvaluationSupport.regex(RegexEvaluationSupport.transformRegexStrForSubtractionOp(pattern.toString()), 
                                                             flags != null ? flags.toString() : null, inputStr.toString());
             while (matcher.find()) {
                result = true;
diff --git a/src/org/apache/xpath/functions/FuncReplace.java b/src/org/apache/xpath/functions/FuncReplace.java
index 064e709f..3600966b 100644
--- a/src/org/apache/xpath/functions/FuncReplace.java
+++ b/src/org/apache/xpath/functions/FuncReplace.java
@@ -78,7 +78,7 @@ public class FuncReplace extends Function4Args {
         String resultStr = null;
         
         try {
-            Matcher matcher = RegexEvaluationSupport.regex(RegexEvaluationSupport.trfPatternStrForSubtraction(pattern.toString()), 
+            Matcher matcher = RegexEvaluationSupport.regex(RegexEvaluationSupport.transformRegexStrForSubtractionOp(pattern.toString()), 
                                                            flags != null ? flags.toString() : null, inputStr.toString());
             resultStr = matcher.replaceAll(replacement.toString());
         }
diff --git a/src/org/apache/xpath/functions/FuncTokenize.java b/src/org/apache/xpath/functions/FuncTokenize.java
index 08040996..6c25bc60 100644
--- a/src/org/apache/xpath/functions/FuncTokenize.java
+++ b/src/org/apache/xpath/functions/FuncTokenize.java
@@ -175,7 +175,7 @@ public class FuncTokenize extends Function3Args {
       Matcher regexMatcher = null;
 
       try {
-          regexMatcher = RegexEvaluationSupport.regex(RegexEvaluationSupport.trfPatternStrForSubtraction(
+          regexMatcher = RegexEvaluationSupport.regex(RegexEvaluationSupport.transformRegexStrForSubtractionOp(
                                                   pattern.toString()), flags != null ? flags.toString() : 
                                                                                   null, inputStr.toString());
       }
diff --git a/src/org/apache/xpath/functions/RegexEvaluationSupport.java b/src/org/apache/xpath/functions/RegexEvaluationSupport.java
index 1d72638a..060bfcd1 100644
--- a/src/org/apache/xpath/functions/RegexEvaluationSupport.java
+++ b/src/org/apache/xpath/functions/RegexEvaluationSupport.java
@@ -34,13 +34,17 @@ import org.apache.xpath.regex.Pattern;
  */
 public class RegexEvaluationSupport {
 	
-    private static final String validRegexflags = "smixq";
+	/**
+	 * Variable indicating that, XPath regex valid flag 
+	 * characters are : s, m, i, x, q.
+	 */
+    private static final String VALID_REGEX_FLAG_CHARS = "smixq";
 	
 	/*
 	 * Transform regex pattern input string, to resolve differences between, 
 	 * XML Schema regex subtraction operator and Java regex subtraction operator. 
 	 */
-	public static String trfPatternStrForSubtraction(String pattern) {
+	public static String transformRegexStrForSubtractionOp(String pattern) {
 		String transformedPatternStr = pattern;
 		
 		int indx1 = transformedPatternStr.indexOf("-[");
@@ -66,7 +70,7 @@ public class RegexEvaluationSupport {
        
        if (flags.length() > 0) {
     	  for (int idx = 0; idx < flags.length(); idx++) {
-    		 if (validRegexflags.indexOf(flags.charAt(idx)) == -1) {
+    		 if (VALID_REGEX_FLAG_CHARS.indexOf(flags.charAt(idx)) == -1) {
     			flagStrValid = false;
     			break;
     		 }
diff --git a/tests/fn_analyze_string/gold/test1.out b/tests/fn_analyze_string/gold/test1.out
new file mode 100644
index 00000000..01137211
--- /dev/null
+++ b/tests/fn_analyze_string/gold/test1.out
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?><analyze-string-result xmlns="http://www.w3.org/2005/xpath-functions">
+  <match>abcde</match>
+</analyze-string-result>
diff --git a/tests/fn_analyze_string/gold/test2.out b/tests/fn_analyze_string/gold/test2.out
new file mode 100644
index 00000000..5f686bb6
--- /dev/null
+++ b/tests/fn_analyze_string/gold/test2.out
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?><analyze-string-result xmlns="http://www.w3.org/2005/xpath-functions">
+  <match>The</match>
+  <non-match> </non-match>
+  <match>cat</match>
+  <non-match> </non-match>
+  <match>sat</match>
+  <non-match> </non-match>
+  <match>on</match>
+  <non-match> </non-match>
+  <match>the</match>
+  <non-match> </non-match>
+  <match>mat</match>
+  <non-match>.</non-match>
+</analyze-string-result>
diff --git a/tests/fn_analyze_string/gold/test3.out b/tests/fn_analyze_string/gold/test3.out
new file mode 100644
index 00000000..bf71b754
--- /dev/null
+++ b/tests/fn_analyze_string/gold/test3.out
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?><analyze-string-result xmlns="http://www.w3.org/2005/xpath-functions">
+  <non-match>??</non-match>
+  <match>The</match>
+  <non-match> </non-match>
+  <match>cat</match>
+  <non-match> </non-match>
+  <match>sat</match>
+</analyze-string-result>
diff --git a/tests/fn_analyze_string/gold/test4.out b/tests/fn_analyze_string/gold/test4.out
new file mode 100644
index 00000000..f2b7130c
--- /dev/null
+++ b/tests/fn_analyze_string/gold/test4.out
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?><analyze-string-result xmlns="http://www.w3.org/2005/xpath-functions">
+  <non-match>hi</non-match>
+  <match> | </match>
+  <non-match>there</non-match>
+  <match> | </match>
+  <non-match>its</non-match>
+  <match> | </match>
+  <non-match>good</non-match>
+  <match> | </match>
+  <non-match>here</non-match>
+</analyze-string-result>
diff --git a/tests/fn_analyze_string/gold/test5.out b/tests/fn_analyze_string/gold/test5.out
new file mode 100644
index 00000000..049e2f25
--- /dev/null
+++ b/tests/fn_analyze_string/gold/test5.out
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?><analyze-string-result xmlns="http://www.w3.org/2005/xpath-functions">
+  <non-match>hi</non-match>
+  <match>|</match>
+  <non-match>there</non-match>
+  <match>|</match>
+  <non-match>its</non-match>
+  <match>|</match>
+  <non-match>good</non-match>
+  <match>|</match>
+  <non-match>here</non-match>
+</analyze-string-result>
diff --git a/tests/fn_analyze_string/test1.xsl b/tests/fn_analyze_string/test1.xsl
new file mode 100644
index 00000000..6146de60
--- /dev/null
+++ b/tests/fn_analyze_string/test1.xsl
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version="3.0">
+                
+    <!-- Author: mukulg@apache.org -->
+    
+    <!-- An XSLT test case, to test XPath 3.1 function call 
+         fn:analyze-string. -->                              
+    
+    <xsl:output method="xml" indent="yes"/>
+    
+    <xsl:template match="/">
+      <xsl:copy-of select="analyze-string('abcde','abcde')"/> 
+    </xsl:template>
+    
+    <!--
+      * Licensed to the Apache Software Foundation (ASF) under one
+      * or more contributor license agreements. See the NOTICE file
+      * distributed with this work for additional information
+      * regarding copyright ownership. The ASF licenses this file
+      * to you under the Apache License, Version 2.0 (the  "License");
+      * you may not use this file except in compliance with the License.
+      * You may obtain a copy of the License at
+      *
+      *     http://www.apache.org/licenses/LICENSE-2.0
+      *
+      * Unless required by applicable law or agreed to in writing, software
+      * distributed under the License is distributed on an "AS IS" BASIS,
+      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+      * See the License for the specific language governing permissions and
+      * limitations under the License.
+    -->
+    
+</xsl:stylesheet>
diff --git a/tests/fn_analyze_string/test2.xsl b/tests/fn_analyze_string/test2.xsl
new file mode 100644
index 00000000..4aeb69fb
--- /dev/null
+++ b/tests/fn_analyze_string/test2.xsl
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version="3.0">
+                
+    <!-- Author: mukulg@apache.org -->
+    
+    <!-- An XSLT test case, to test XPath 3.1 function call 
+         fn:analyze-string. -->                               
+    
+    <xsl:output method="xml" indent="yes"/>
+    
+    <xsl:template match="/">
+      <xsl:copy-of select="analyze-string('The cat sat on the mat.', '\w+')"/> 
+    </xsl:template>
+    
+    <!--
+      * Licensed to the Apache Software Foundation (ASF) under one
+      * or more contributor license agreements. See the NOTICE file
+      * distributed with this work for additional information
+      * regarding copyright ownership. The ASF licenses this file
+      * to you under the Apache License, Version 2.0 (the  "License");
+      * you may not use this file except in compliance with the License.
+      * You may obtain a copy of the License at
+      *
+      *     http://www.apache.org/licenses/LICENSE-2.0
+      *
+      * Unless required by applicable law or agreed to in writing, software
+      * distributed under the License is distributed on an "AS IS" BASIS,
+      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+      * See the License for the specific language governing permissions and
+      * limitations under the License.
+    -->
+    
+</xsl:stylesheet>
diff --git a/tests/fn_analyze_string/test3.xsl b/tests/fn_analyze_string/test3.xsl
new file mode 100644
index 00000000..e35126a9
--- /dev/null
+++ b/tests/fn_analyze_string/test3.xsl
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version="3.0">
+                
+    <!-- Author: mukulg@apache.org -->
+    
+    <!-- An XSLT test case, to test XPath 3.1 function call 
+         fn:analyze-string. -->                                
+    
+    <xsl:output method="xml" indent="yes"/>
+    
+    <xsl:template match="/">
+      <xsl:copy-of select="analyze-string('??The cat sat', '\w+')"/> 
+    </xsl:template>
+    
+    <!--
+      * Licensed to the Apache Software Foundation (ASF) under one
+      * or more contributor license agreements. See the NOTICE file
+      * distributed with this work for additional information
+      * regarding copyright ownership. The ASF licenses this file
+      * to you under the Apache License, Version 2.0 (the  "License");
+      * you may not use this file except in compliance with the License.
+      * You may obtain a copy of the License at
+      *
+      *     http://www.apache.org/licenses/LICENSE-2.0
+      *
+      * Unless required by applicable law or agreed to in writing, software
+      * distributed under the License is distributed on an "AS IS" BASIS,
+      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+      * See the License for the specific language governing permissions and
+      * limitations under the License.
+    -->
+    
+</xsl:stylesheet>
diff --git a/tests/fn_analyze_string/test4.xsl b/tests/fn_analyze_string/test4.xsl
new file mode 100644
index 00000000..5e28e6e2
--- /dev/null
+++ b/tests/fn_analyze_string/test4.xsl
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version="3.0">
+                
+    <!-- Author: mukulg@apache.org -->
+    
+    <!-- An XSLT test case, to test XPath 3.1 function call 
+         fn:analyze-string. -->                                
+    
+    <xsl:output method="xml" indent="yes"/>
+    
+    <xsl:template match="/">
+      <xsl:copy-of select="analyze-string('hi | there | its | good | here', '\s*\|\s*')"/> 
+    </xsl:template>
+    
+    <!--
+      * Licensed to the Apache Software Foundation (ASF) under one
+      * or more contributor license agreements. See the NOTICE file
+      * distributed with this work for additional information
+      * regarding copyright ownership. The ASF licenses this file
+      * to you under the Apache License, Version 2.0 (the  "License");
+      * you may not use this file except in compliance with the License.
+      * You may obtain a copy of the License at
+      *
+      *     http://www.apache.org/licenses/LICENSE-2.0
+      *
+      * Unless required by applicable law or agreed to in writing, software
+      * distributed under the License is distributed on an "AS IS" BASIS,
+      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+      * See the License for the specific language governing permissions and
+      * limitations under the License.
+    -->
+    
+</xsl:stylesheet>
diff --git a/tests/fn_analyze_string/test5.xml b/tests/fn_analyze_string/test5.xml
new file mode 100644
index 00000000..aa328e74
--- /dev/null
+++ b/tests/fn_analyze_string/test5.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<info>hi|there|its|good|here</info>
diff --git a/tests/fn_analyze_string/test5.xsl b/tests/fn_analyze_string/test5.xsl
new file mode 100644
index 00000000..adb85f7b
--- /dev/null
+++ b/tests/fn_analyze_string/test5.xsl
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version="3.0">
+                
+    <!-- Author: mukulg@apache.org -->
+    
+    <!-- use with test5.xml -->
+    
+    <!-- An XSLT test case, to test XPath 3.1 function call 
+         fn:analyze-string. -->    				 
+    
+    <xsl:output method="xml" indent="yes"/>
+    
+    <xsl:template match="/">
+       <xsl:copy-of select="analyze-string(info, '\|')"/>
+    </xsl:template>
+    
+    <!--
+      * Licensed to the Apache Software Foundation (ASF) under one
+      * or more contributor license agreements. See the NOTICE file
+      * distributed with this work for additional information
+      * regarding copyright ownership. The ASF licenses this file
+      * to you under the Apache License, Version 2.0 (the  "License");
+      * you may not use this file except in compliance with the License.
+      * You may obtain a copy of the License at
+      *
+      *     http://www.apache.org/licenses/LICENSE-2.0
+      *
+      * Unless required by applicable law or agreed to in writing, software
+      * distributed under the License is distributed on an "AS IS" BASIS,
+      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+      * See the License for the specific language governing permissions and
+      * limitations under the License.
+    -->
+    
+</xsl:stylesheet>
diff --git a/tests/org/apache/xalan/xpath3/FnAnalyzeStringTests.java b/tests/org/apache/xalan/xpath3/FnAnalyzeStringTests.java
new file mode 100644
index 00000000..72b0b2b8
--- /dev/null
+++ b/tests/org/apache/xalan/xpath3/FnAnalyzeStringTests.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.xalan.xpath3;
+
+import org.apache.xalan.util.XSLConstants;
+import org.apache.xalan.util.XSLTransformTestsUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * XPath 3.1 function fn:analyze-string test cases.
+ * 
+ * @author Mukul Gandhi <mu...@apache.org>
+ * 
+ * @xsl.usage advanced
+ */
+public class FnAnalyzeStringTests extends XSLTransformTestsUtil {        
+    
+    private static final String XSL_TRANSFORM_INPUT_DIRPATH = XSLConstants.XSL_TRANSFORM_INPUT_DIRPATH_PREFIX 
+    		 																						+ "fn_analyze_string/";
+    
+    private static final String XSL_TRANSFORM_GOLD_DIRPATH = XSLConstants.XSL_TRANSFORM_GOLD_DIRPATH_PREFIX 
+    																								+ "fn_analyze_string/gold/";
+
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        // no op
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() throws Exception {        
+        xmlDocumentBuilderFactory = null;
+        xmlDocumentBuilder = null;
+        xslTransformerFactory = null;
+    }
+
+    @Test
+    public void xslFnAnalyzeStringTest1() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1.xsl"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test1.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+    
+    @Test
+    public void xslFnAnalyzeStringTest2() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test2.xsl"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test2.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test2.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+    
+    @Test
+    public void xslFnAnalyzeStringTest3() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test3.xsl"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test3.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test3.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+    
+    @Test
+    public void xslFnAnalyzeStringTest4() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test4.xsl"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test4.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test4.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+    
+    @Test
+    public void xslFnAnalyzeStringTest5() {
+        String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test5.xml"; 
+        String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test5.xsl";
+        
+        String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test5.out";                
+        
+        runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+    }
+
+}
diff --git a/tests/org/apache/xalan/xslt3/Xsl3TestSuite1.java b/tests/org/apache/xalan/xslt3/Xsl3TestSuite1.java
index ffc9a72b..d5d2f9f9 100644
--- a/tests/org/apache/xalan/xslt3/Xsl3TestSuite1.java
+++ b/tests/org/apache/xalan/xslt3/Xsl3TestSuite1.java
@@ -17,6 +17,7 @@
 package org.apache.xalan.xslt3;
 
 import org.apache.xalan.xpath3.FnAbsTests;
+import org.apache.xalan.xpath3.FnAnalyzeStringTests;
 import org.apache.xalan.xpath3.FnBaseUriTests;
 import org.apache.xalan.xpath3.FnDataTests;
 import org.apache.xalan.xpath3.FnDateTimeTests;
@@ -71,7 +72,7 @@ import org.junit.runners.Suite.SuiteClasses;
                 FnQNameTests.class, XPathMapTests.class, XPathArrayTests.class, FnLangTests.class, 
                 FnRootTests.class, XPathCastTests.class, XPathArrowOpTests.class, FnMapMerge.class,
                 FnParseJsonTests.class, FnJsonDocTests.class, FnJsonToXmlTests.class,
-                FnXmlToJsonTests.class })
+                FnXmlToJsonTests.class, FnAnalyzeStringTests.class })
 public class Xsl3TestSuite1 {
 
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org