Interface MatchContext

All Known Subinterfaces:
MatchContext.ChatMatchContext

public interface MatchContext
This is the core of the matcher system.

A MatchContext is made out of some input string with forInput(java.lang.String). It's then given to each matcher, which can parse it however it sees fit and add new matches on a given range.

  • Method Details

    • forInput

      static MatchContext forInput(String inputText)
      Creates a MatchContext with the given input as its base.
      Parameters:
      inputText -
      Returns:
      a MatchContext for the input.
    • forTextInput

      static MatchContext forTextInput(net.minecraft.text.Text inputText)
    • isFrozen

      boolean isFrozen()
      If this context is 'frozen', meaning it no longer accepts new matches.
      Returns:
      if this context is read-only or not.
    • freeze

      void freeze()
      Freeze this context so that it no longer accepts new matches.
    • getOriginalText

      String getOriginalText()
      Gets the raw input
      Returns:
      the original text being matched against.
    • getMatchableText

      String getMatchableText(char redactedChar)
      Gets the input but with already matched characters being replaced with redactedChar
      Parameters:
      redactedChar - character to replace already matched characters with
      Returns:
      the redacted input
    • addMatch

      boolean addMatch(int start, int end, InlineMatch match)
      Attaches the given match to all characters in the range.

      Note that the same match object repeated consecutively will be treated as a single match until it's interrupted.

      Parameters:
      start - start of range inclusive
      end - end of range exclusive
      match - match to assign
      Returns:
      whether the match was successfully added. will return false if any character in this range is already matched or if the context is frozen.
    • getUnmatchedSequences

      Map<Integer,String> getUnmatchedSequences()
      Gets all unmatched segments.

      For example, with the input string texta :emote: textb, if the :emote: is matched, then this returns a map with:

      map.size() == 2, map.get(0) == "texta ", and map.get(13) == " textb"

      Returns:
      a map with unmatched segments as entries, their starting index as the key and the segment string as the value
    • getFinalText

      String getFinalText()
      Gets the text with all matched characters replaced by placeholders for the length of the match. This is mostly for internal use.

      For example, "texta :emote: textb" with a single length match on ":emote:" would return "texta . textb"

      Returns:
    • getFinalStyledText

      net.minecraft.text.Text getFinalStyledText()
      Gets the final text with the style baked into it already. This is mostly for internal use.
      Returns:
    • getFinalMatches

      Map<Integer,InlineMatch> getFinalMatches()
      Gets a map of all matches added. The key is the start index of the match in the string returned by getFinalText(), the value is the match. This is mostly for internal use.

      Note again that the same match object on consecutive characters will count as a single match.

      Returns:
    • getMatches

      Map<Integer,InlineMatch> getMatches()
      Gets a map of all matches added. The key is the start index of the match in the original string input, the value is the match.
      Returns:
    • origToFinal

      int origToFinal(int orig)
      Converts the given index from its position in the original string to the corresponding position in the final string returned by getFinalText()
      Parameters:
      orig - index to convert
      Returns:
      the index in the final string.
    • finalToOrig

      int finalToOrig(int fin)
      Converts the given index from its position in the final string returned by getFinalText() to the corresponding position in the original string.
      Parameters:
      fin - index to convert
      Returns:
      the index in the original string. If fin is a match then it returns the index of the first character matched in the original.