Class XmlRegexp
java.lang.Object
org.libxmq.imp.xml.XmlRegexp
XML Schemas (Part 2, Appendix F) regular expressions, the automata used to build
content models and their progressive execution, a port of xml_regexp.c (libxml2
xmlregexp.c: xmlRegexp*, xmlAutomata* and xmlRegExec*). An instance is a compiled
regular expression or automata (libxml2 xmlRegexp), all functions are static.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceReceives each compile error (XmlRegexpErrorFunc), message is the libxml2 error message ("failed to compile: ...static interfaceCalled when a transition is taken by regExecPushString(2) (XmlRegExecCallbacks). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe automata flag used by RELAX NG (libxml2 AM_AUTOMATA_RNG): string atoms are compared by pointer when computing determinism.static final intInternal error.static final intInternal limit reached.static final intInvalid UTF-8.static final intNot found.static final intNo error.static final intOut of memory. -
Method Summary
Modifier and TypeMethodDescriptionstatic XmlRegexpPort of xmlAutomataCompile.static voidPort of xmlFreeAutomata.static XmlAutomataStatePort of xmlAutomataGetInitState.static intPort of xmlAutomataIsDeterminist.static XmlAutomataPort of xmlNewAutomata.static XmlAutomataStateautomataNewAllTrans(XmlAutomata am, XmlAutomataState from, XmlAutomataState to, int lax) Port of xmlAutomataNewAllTrans.static XmlAutomataStateautomataNewCountedTrans(XmlAutomata am, XmlAutomataState from, XmlAutomataState to, int counter) Port of xmlAutomataNewCountedTrans.static intautomataNewCounter(XmlAutomata am, int min, int max) Port of xmlAutomataNewCounter.static XmlAutomataStateautomataNewCounterTrans(XmlAutomata am, XmlAutomataState from, XmlAutomataState to, int counter) Port of xmlAutomataNewCounterTrans.static XmlAutomataStateautomataNewCountTrans(XmlAutomata am, XmlAutomataState from, XmlAutomataState to, String token, int min, int max, Object data) Port of xmlAutomataNewCountTrans.static XmlAutomataStateautomataNewCountTrans2(XmlAutomata am, XmlAutomataState from, XmlAutomataState to, String token, String token2, int min, int max, Object data) Port of xmlAutomataNewCountTrans2.static XmlAutomataStateautomataNewEpsilon(XmlAutomata am, XmlAutomataState from, XmlAutomataState to) Port of xmlAutomataNewEpsilon.static XmlAutomataStateautomataNewNegTrans(XmlAutomata am, XmlAutomataState from, XmlAutomataState to, String token, String token2, Object data) Port of xmlAutomataNewNegTrans.static XmlAutomataStateautomataNewOnceTrans(XmlAutomata am, XmlAutomataState from, XmlAutomataState to, String token, int min, int max, Object data) Port of xmlAutomataNewOnceTrans.static XmlAutomataStateautomataNewOnceTrans2(XmlAutomata am, XmlAutomataState from, XmlAutomataState to, String token, String token2, int min, int max, Object data) Port of xmlAutomataNewOnceTrans2.static XmlAutomataStatePort of xmlAutomataNewState.static XmlAutomataStateautomataNewTransition(XmlAutomata am, XmlAutomataState from, XmlAutomataState to, String token, Object data) Port of xmlAutomataNewTransition.static XmlAutomataStateautomataNewTransition2(XmlAutomata am, XmlAutomataState from, XmlAutomataState to, String token, String token2, Object data) Port of xmlAutomataNewTransition2.static voidautomataSetErrorFunc(XmlAutomata am, XmlRegexp.ErrorFunc error_func, Object error_data) Set the function receiving the errors raised while building the automata (libxml2 raises them on the global error handler).static intautomataSetFinalState(XmlAutomata am, XmlAutomataState state) Port of xmlAutomataSetFinalState.static voidautomataSetFlags(XmlAutomata am, int flags) Port of xmlAutomataSetFlags.static voidPort of xmlRegExecClearErrors.static intregExecErrInfo(XmlRegExecCtxt exec, String[] string, int[] nbval, int[] nbneg, String[] values, int[] terminal) Port of xmlRegExecErrInfo.static voidregExecFree(XmlRegExecCtxt exec) Port of xmlRegFreeExecCtxt.static XmlRegExecCtxtregExecNew(XmlRegexp comp, XmlRegexp.ExecCallback callback, Object data) Port of xmlRegNewExecCtxt.static intregExecNextValues(XmlRegExecCtxt exec, int[] nbval, int[] nbneg, String[] values, int[] terminal) Port of xmlRegExecNextValues.static intregExecPushString(XmlRegExecCtxt exec, String value, Object data) Port of xmlRegExecPushString.static intregExecPushString2(XmlRegExecCtxt exec, String value, String value2, Object data) Port of xmlRegExecPushString2.static XmlRegexpregexpCompile(String regexp) Port of xmlRegexpCompile, the compile errors are not reported.static XmlRegexpregexpCompileWithErrors(String regexp, XmlRegexp.ErrorFunc error_func, Object error_data) Port of xmlRegexpCompile.static intregexpExec(XmlRegexp comp, String content) Port of xmlRegexpExec.static voidregexpFree(XmlRegexp regexp) Port of xmlRegFreeRegexp.static intregexpIsDeterminist(XmlRegexp comp) Port of xmlRegexpIsDeterminist.static voidregexpPrint(PrintStream output, XmlRegexp regexp) Port of xmlRegexpPrint.
-
Field Details
-
XML_REGEXP_OK
public static final int XML_REGEXP_OKNo error.- See Also:
-
XML_REGEXP_NOT_FOUND
public static final int XML_REGEXP_NOT_FOUNDNot found.- See Also:
-
XML_REGEXP_INTERNAL_ERROR
public static final int XML_REGEXP_INTERNAL_ERRORInternal error.- See Also:
-
XML_REGEXP_OUT_OF_MEMORY
public static final int XML_REGEXP_OUT_OF_MEMORYOut of memory.- See Also:
-
XML_REGEXP_INTERNAL_LIMIT
public static final int XML_REGEXP_INTERNAL_LIMITInternal limit reached.- See Also:
-
XML_REGEXP_INVALID_UTF8
public static final int XML_REGEXP_INVALID_UTF8Invalid UTF-8.- See Also:
-
XML_AUTOMATA_RNG
public static final int XML_AUTOMATA_RNGThe automata flag used by RELAX NG (libxml2 AM_AUTOMATA_RNG): string atoms are compared by pointer when computing determinism.- See Also:
-
-
Method Details
-
regExecNew
public static XmlRegExecCtxt regExecNew(XmlRegexp comp, XmlRegexp.ExecCallback callback, Object data) Port of xmlRegNewExecCtxt. Build a context used for progressive evaluation of a regexp.- Parameters:
comp- a precompiled regular expressioncallback- a callback function used for handling progresses in the automata matching phasedata- the context data associated to the callback in this context- Returns:
- the new context
-
regExecFree
Port of xmlRegFreeExecCtxt. Free the structures associated to a regular expression evaluation context.- Parameters:
exec- a regular expression evaluation context
-
regExecPushString
Port of xmlRegExecPushString. Push one input token in the execution context- Parameters:
exec- a regexp execution context or null to indicate the endvalue- a string token inputdata- data associated to the token to reuse in callbacks- Returns:
- 1 if the regexp reached a final state, 0 if non-final, and a negative value in case of error.
-
regExecPushString2
Port of xmlRegExecPushString2. Push one input token in the execution context- Parameters:
exec- a regexp execution context or null to indicate the endvalue- the first string token inputvalue2- the second string token inputdata- data associated to the token to reuse in callbacks- Returns:
- 1 if the regexp reached a final state, 0 if non-final, and a negative value in case of error.
-
regExecNextValues
public static int regExecNextValues(XmlRegExecCtxt exec, int[] nbval, int[] nbneg, String[] values, int[] terminal) Port of xmlRegExecNextValues. Extract information from the regexp execution. The parameter `values` must point to an array of `nbval` string pointers on return nbval will contain the number of possible strings in that state and the `values` array will be updated with them.- Parameters:
exec- a regexp execution contextnbval- pointer to the number of accepted values IN/OUTnbneg- return number of negative transitionsvalues- pointer to the array of acceptable valuesterminal- return value if this was a terminal state- Returns:
- 0 in case of success or -1 in case of error.
-
regExecErrInfo
public static int regExecErrInfo(XmlRegExecCtxt exec, String[] string, int[] nbval, int[] nbneg, String[] values, int[] terminal) Port of xmlRegExecErrInfo. Extract error information from the regexp execution. The parameter `string` will be updated with the value pushed and not accepted, the parameter `values` must point to an array of `nbval` string pointers on return nbval will contain the number of possible strings in that state and the `values` array will be updated with them.- Parameters:
exec- a regexp execution context generating an errorstring- return value for the error stringnbval- pointer to the number of accepted values IN/OUTnbneg- return number of negative transitionsvalues- pointer to the array of acceptable valuesterminal- return value if this was a terminal state- Returns:
- 0 in case of success or -1 in case of error.
-
regExecClearErrors
Port of xmlRegExecClearErrors. Clear errors in the context, allowing to recover from errors on specific scenarios- Parameters:
exec- a regexp execution context
-
regexpPrint
Port of xmlRegexpPrint. No-op since 2.14.0.- Parameters:
output- the file for the output debugregexp- the compiled regexp
-
regexpCompileWithErrors
public static XmlRegexp regexpCompileWithErrors(String regexp, XmlRegexp.ErrorFunc error_func, Object error_data) Port of xmlRegexpCompile. Parses a regular expression conforming to XML Schemas Part 2 Datatype Appendix F and builds an automata suitable for testing strings against that regular expression.- Parameters:
regexp- a regular expression stringerror_func- called for each compile error, or nullerror_data- passed to error_func- Returns:
- the compiled expression or null in case of error
-
regexpCompile
-
regexpExec
Port of xmlRegexpExec. Check if the regular expression matches a string.- Parameters:
comp- the compiled regular expressioncontent- the value to check against the regular expression- Returns:
- 1 if it matches, 0 if not and a negative value in case of error
-
regexpIsDeterminist
Port of xmlRegexpIsDeterminist. Check if the regular expression is deterministic. DTD and XML Schemas require a deterministic content model, so the automaton compiled from the regex must be a DFA. The runtime of this function is quadratic in the number of outgoing edges, causing serious worst-case performance issues.- Parameters:
comp- the compiled regular expression- Returns:
- 1 if it yes, 0 if not and a negative value in case of error
-
regexpFree
Port of xmlRegFreeRegexp.- Parameters:
regexp- the regexp
-
automataNew
Port of xmlNewAutomata. Create a new automata- Returns:
- the new object or null in case of failure
-
automataFree
Port of xmlFreeAutomata.- Parameters:
am- an automata
-
automataSetFlags
Port of xmlAutomataSetFlags. Set some flags on the automata- Parameters:
am- an automataflags- a set of internal flags
-
automataSetErrorFunc
public static void automataSetErrorFunc(XmlAutomata am, XmlRegexp.ErrorFunc error_func, Object error_data) Set the function receiving the errors raised while building the automata (libxml2 raises them on the global error handler).- Parameters:
am- an automataerror_func- called for each error, or nullerror_data- passed to error_func
-
automataGetInitState
Port of xmlAutomataGetInitState. Initial state lookup- Parameters:
am- an automata- Returns:
- the initial state of the automata
-
automataSetFinalState
Port of xmlAutomataSetFinalState. Makes that state a final state- Parameters:
am- an automatastate- a state in this automata- Returns:
- 0 or -1 in case of error
-
automataNewTransition
public static XmlAutomataState automataNewTransition(XmlAutomata am, XmlAutomataState from, XmlAutomataState to, String token, Object data) Port of xmlAutomataNewTransition. If `to` is null, this creates first a new target state in the automata and then adds a transition from the `from` state to the target state activated by the value of `token`- Parameters:
am- an automatafrom- the starting point of the transitionto- the target point of the transition or nulltoken- the input string associated to that transitiondata- data passed to the callback function if the transition is activated- Returns:
- the target state or null in case of error
-
automataNewTransition2
public static XmlAutomataState automataNewTransition2(XmlAutomata am, XmlAutomataState from, XmlAutomataState to, String token, String token2, Object data) Port of xmlAutomataNewTransition2. If `to` is null, this creates first a new target state in the automata and then adds a transition from the `from` state to the target state activated by the value of `token`- Parameters:
am- an automatafrom- the starting point of the transitionto- the target point of the transition or nulltoken- the first input string associated to that transitiontoken2- the second input string associated to that transitiondata- data passed to the callback function if the transition is activated- Returns:
- the target state or null in case of error
-
automataNewNegTrans
public static XmlAutomataState automataNewNegTrans(XmlAutomata am, XmlAutomataState from, XmlAutomataState to, String token, String token2, Object data) Port of xmlAutomataNewNegTrans. If `to` is null, this creates first a new target state in the automata and then adds a transition from the `from` state to the target state activated by any value except (`token`,`token2`) Note that if `token2` is not null, then (X, null) won't match to follow the semantic of XSD ##other- Parameters:
am- an automatafrom- the starting point of the transitionto- the target point of the transition or nulltoken- the first input string associated to that transitiontoken2- the second input string associated to that transitiondata- data passed to the callback function if the transition is activated- Returns:
- the target state or null in case of error
-
automataNewCountTrans2
public static XmlAutomataState automataNewCountTrans2(XmlAutomata am, XmlAutomataState from, XmlAutomataState to, String token, String token2, int min, int max, Object data) Port of xmlAutomataNewCountTrans2. If `to` is null, this creates first a new target state in the automata and then adds a transition from the `from` state to the target state activated by a succession of input of value `token` and `token2` and whose number is between `min` and `max`- Parameters:
am- an automatafrom- the starting point of the transitionto- the target point of the transition or nulltoken- the input string associated to that transitiontoken2- the second input string associated to that transitionmin- the minimum successive occurrences of tokenmax- the maximum successive occurrences of tokendata- data associated to the transition- Returns:
- the target state or null in case of error
-
automataNewCountTrans
public static XmlAutomataState automataNewCountTrans(XmlAutomata am, XmlAutomataState from, XmlAutomataState to, String token, int min, int max, Object data) Port of xmlAutomataNewCountTrans. If `to` is null, this creates first a new target state in the automata and then adds a transition from the `from` state to the target state activated by a succession of input of value `token` and whose number is between `min` and `max`- Parameters:
am- an automatafrom- the starting point of the transitionto- the target point of the transition or nulltoken- the input string associated to that transitionmin- the minimum successive occurrences of tokenmax- the maximum successive occurrences of tokendata- data associated to the transition- Returns:
- the target state or null in case of error
-
automataNewOnceTrans2
public static XmlAutomataState automataNewOnceTrans2(XmlAutomata am, XmlAutomataState from, XmlAutomataState to, String token, String token2, int min, int max, Object data) Port of xmlAutomataNewOnceTrans2. If `to` is null, this creates first a new target state in the automata and then adds a transition from the `from` state to the target state activated by a succession of input of value `token` and `token2` and whose number is between `min` and `max`, moreover that transition can only be crossed once.- Parameters:
am- an automatafrom- the starting point of the transitionto- the target point of the transition or nulltoken- the input string associated to that transitiontoken2- the second input string associated to that transitionmin- the minimum successive occurrences of tokenmax- the maximum successive occurrences of tokendata- data associated to the transition- Returns:
- the target state or null in case of error
-
automataNewOnceTrans
public static XmlAutomataState automataNewOnceTrans(XmlAutomata am, XmlAutomataState from, XmlAutomataState to, String token, int min, int max, Object data) Port of xmlAutomataNewOnceTrans. If `to` is null, this creates first a new target state in the automata and then adds a transition from the `from` state to the target state activated by a succession of input of value `token` and whose number is between `min` and `max`, moreover that transition can only be crossed once.- Parameters:
am- an automatafrom- the starting point of the transitionto- the target point of the transition or nulltoken- the input string associated to that transitionmin- the minimum successive occurrences of tokenmax- the maximum successive occurrences of tokendata- data associated to the transition- Returns:
- the target state or null in case of error
-
automataNewState
Port of xmlAutomataNewState. Create a new disconnected state in the automata- Parameters:
am- an automata- Returns:
- the new state or null in case of error
-
automataNewEpsilon
public static XmlAutomataState automataNewEpsilon(XmlAutomata am, XmlAutomataState from, XmlAutomataState to) Port of xmlAutomataNewEpsilon. If `to` is null, this creates first a new target state in the automata and then adds an epsilon transition from the `from` state to the target state- Parameters:
am- an automatafrom- the starting point of the transitionto- the target point of the transition or null- Returns:
- the target state or null in case of error
-
automataNewAllTrans
public static XmlAutomataState automataNewAllTrans(XmlAutomata am, XmlAutomataState from, XmlAutomataState to, int lax) Port of xmlAutomataNewAllTrans. If `to` is null, this creates first a new target state in the automata and then adds a an ALL transition from the `from` state to the target state. That transition is an epsilon transition allowed only when all transitions from the `from` node have been activated.- Parameters:
am- an automatafrom- the starting point of the transitionto- the target point of the transition or nulllax- allow to transition if not all all transitions have been activated- Returns:
- the target state or null in case of error
-
automataNewCounter
Port of xmlAutomataNewCounter. Create a new counter- Parameters:
am- an automatamin- the minimal value on the countermax- the maximal value on the counter- Returns:
- the counter number or -1 in case of error
-
automataNewCountedTrans
public static XmlAutomataState automataNewCountedTrans(XmlAutomata am, XmlAutomataState from, XmlAutomataState to, int counter) Port of xmlAutomataNewCountedTrans. If `to` is null, this creates first a new target state in the automata and then adds an epsilon transition from the `from` state to the target state which will increment the counter provided- Parameters:
am- an automatafrom- the starting point of the transitionto- the target point of the transition or nullcounter- the counter associated to that transition- Returns:
- the target state or null in case of error
-
automataNewCounterTrans
public static XmlAutomataState automataNewCounterTrans(XmlAutomata am, XmlAutomataState from, XmlAutomataState to, int counter) Port of xmlAutomataNewCounterTrans. If `to` is null, this creates first a new target state in the automata and then adds an epsilon transition from the `from` state to the target state which will be allowed only if the counter is within the right range.- Parameters:
am- an automatafrom- the starting point of the transitionto- the target point of the transition or nullcounter- the counter associated to that transition- Returns:
- the target state or null in case of error
-
automataCompile
Port of xmlAutomataCompile. Compile the automata into a Reg Exp ready for being executed. The automata should be free after this point.- Parameters:
am- an automata- Returns:
- the compiled regexp or null in case of error
-
automataIsDeterminist
Port of xmlAutomataIsDeterminist. Checks if an automata is determinist.- Parameters:
am- an automata- Returns:
- 1 if true, 0 if not, and -1 in case of error
-