Class XmlRegexp

java.lang.Object
org.libxmq.imp.xml.XmlRegexp

public final class XmlRegexp extends Object
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.
  • Field Details

    • XML_REGEXP_OK

      public static final int XML_REGEXP_OK
      No error.
      See Also:
    • XML_REGEXP_NOT_FOUND

      public static final int XML_REGEXP_NOT_FOUND
      Not found.
      See Also:
    • XML_REGEXP_INTERNAL_ERROR

      public static final int XML_REGEXP_INTERNAL_ERROR
      Internal error.
      See Also:
    • XML_REGEXP_OUT_OF_MEMORY

      public static final int XML_REGEXP_OUT_OF_MEMORY
      Out of memory.
      See Also:
    • XML_REGEXP_INTERNAL_LIMIT

      public static final int XML_REGEXP_INTERNAL_LIMIT
      Internal limit reached.
      See Also:
    • XML_REGEXP_INVALID_UTF8

      public static final int XML_REGEXP_INVALID_UTF8
      Invalid UTF-8.
      See Also:
    • XML_AUTOMATA_RNG

      public static final int XML_AUTOMATA_RNG
      The 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 expression
      callback - a callback function used for handling progresses in the automata matching phase
      data - the context data associated to the callback in this context
      Returns:
      the new context
    • regExecFree

      public static void regExecFree(XmlRegExecCtxt exec)
      Port of xmlRegFreeExecCtxt. Free the structures associated to a regular expression evaluation context.
      Parameters:
      exec - a regular expression evaluation context
    • regExecPushString

      public static int regExecPushString(XmlRegExecCtxt exec, String value, Object data)
      Port of xmlRegExecPushString. Push one input token in the execution context
      Parameters:
      exec - a regexp execution context or null to indicate the end
      value - a string token input
      data - 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

      public static int regExecPushString2(XmlRegExecCtxt exec, String value, String value2, Object data)
      Port of xmlRegExecPushString2. Push one input token in the execution context
      Parameters:
      exec - a regexp execution context or null to indicate the end
      value - the first string token input
      value2 - the second string token input
      data - 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 context
      nbval - pointer to the number of accepted values IN/OUT
      nbneg - return number of negative transitions
      values - pointer to the array of acceptable values
      terminal - 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 error
      string - return value for the error string
      nbval - pointer to the number of accepted values IN/OUT
      nbneg - return number of negative transitions
      values - pointer to the array of acceptable values
      terminal - return value if this was a terminal state
      Returns:
      0 in case of success or -1 in case of error.
    • regExecClearErrors

      public static void regExecClearErrors(XmlRegExecCtxt exec)
      Port of xmlRegExecClearErrors. Clear errors in the context, allowing to recover from errors on specific scenarios
      Parameters:
      exec - a regexp execution context
    • regexpPrint

      public static void regexpPrint(PrintStream output, XmlRegexp regexp)
      Port of xmlRegexpPrint. No-op since 2.14.0.
      Parameters:
      output - the file for the output debug
      regexp - 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 string
      error_func - called for each compile error, or null
      error_data - passed to error_func
      Returns:
      the compiled expression or null in case of error
    • regexpCompile

      public static XmlRegexp regexpCompile(String regexp)
      Port of xmlRegexpCompile, the compile errors are not reported.
      Parameters:
      regexp - a regular expression string
      Returns:
      the compiled expression or null in case of error
    • regexpExec

      public static int regexpExec(XmlRegexp comp, String content)
      Port of xmlRegexpExec. Check if the regular expression matches a string.
      Parameters:
      comp - the compiled regular expression
      content - 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

      public static int regexpIsDeterminist(XmlRegexp comp)
      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

      public static void regexpFree(XmlRegexp regexp)
      Port of xmlRegFreeRegexp.
      Parameters:
      regexp - the regexp
    • automataNew

      public static XmlAutomata automataNew()
      Port of xmlNewAutomata. Create a new automata
      Returns:
      the new object or null in case of failure
    • automataFree

      public static void automataFree(XmlAutomata am)
      Port of xmlFreeAutomata.
      Parameters:
      am - an automata
    • automataSetFlags

      public static void automataSetFlags(XmlAutomata am, int flags)
      Port of xmlAutomataSetFlags. Set some flags on the automata
      Parameters:
      am - an automata
      flags - 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 automata
      error_func - called for each error, or null
      error_data - passed to error_func
    • automataGetInitState

      public static XmlAutomataState automataGetInitState(XmlAutomata am)
      Port of xmlAutomataGetInitState. Initial state lookup
      Parameters:
      am - an automata
      Returns:
      the initial state of the automata
    • automataSetFinalState

      public static int automataSetFinalState(XmlAutomata am, XmlAutomataState state)
      Port of xmlAutomataSetFinalState. Makes that state a final state
      Parameters:
      am - an automata
      state - 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 automata
      from - the starting point of the transition
      to - the target point of the transition or null
      token - the input string associated to that transition
      data - 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 automata
      from - the starting point of the transition
      to - the target point of the transition or null
      token - the first input string associated to that transition
      token2 - the second input string associated to that transition
      data - 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 automata
      from - the starting point of the transition
      to - the target point of the transition or null
      token - the first input string associated to that transition
      token2 - the second input string associated to that transition
      data - 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 automata
      from - the starting point of the transition
      to - the target point of the transition or null
      token - the input string associated to that transition
      token2 - the second input string associated to that transition
      min - the minimum successive occurrences of token
      max - the maximum successive occurrences of token
      data - 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 automata
      from - the starting point of the transition
      to - the target point of the transition or null
      token - the input string associated to that transition
      min - the minimum successive occurrences of token
      max - the maximum successive occurrences of token
      data - 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 automata
      from - the starting point of the transition
      to - the target point of the transition or null
      token - the input string associated to that transition
      token2 - the second input string associated to that transition
      min - the minimum successive occurrences of token
      max - the maximum successive occurrences of token
      data - 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 automata
      from - the starting point of the transition
      to - the target point of the transition or null
      token - the input string associated to that transition
      min - the minimum successive occurrences of token
      max - the maximum successive occurrences of token
      data - data associated to the transition
      Returns:
      the target state or null in case of error
    • automataNewState

      public static XmlAutomataState automataNewState(XmlAutomata am)
      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 automata
      from - the starting point of the transition
      to - 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 automata
      from - the starting point of the transition
      to - the target point of the transition or null
      lax - allow to transition if not all all transitions have been activated
      Returns:
      the target state or null in case of error
    • automataNewCounter

      public static int automataNewCounter(XmlAutomata am, int min, int max)
      Port of xmlAutomataNewCounter. Create a new counter
      Parameters:
      am - an automata
      min - the minimal value on the counter
      max - 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 automata
      from - the starting point of the transition
      to - the target point of the transition or null
      counter - 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 automata
      from - the starting point of the transition
      to - the target point of the transition or null
      counter - the counter associated to that transition
      Returns:
      the target state or null in case of error
    • automataCompile

      public static XmlRegexp automataCompile(XmlAutomata am)
      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

      public static int automataIsDeterminist(XmlAutomata am)
      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