Class UtilParseQuote

java.lang.Object
org.libxmq.imp.UtilQuote
org.libxmq.imp.UtilParseQuote

public class UtilParseQuote extends UtilQuote
Utility for parsing xmq quotes.
  • Constructor Details

    • UtilParseQuote

      protected UtilParseQuote(String b, int start, int stop)
      Creates a quote parser.
      Parameters:
      b - The buffer to parse.
      start - The start index of the quote.
      stop - The stop index of the quote.
  • Method Details

    • findQuoteStartStop

      public static Pair<Integer,Integer> findQuoteStartStop(String b, int start, int stop)
      Expects an xmq quote and removes the surrounding single or double quote chars. For example: '' -> (1,1)
      Parameters:
      b - The buffer to search.
      start - The start index of the quote.
      stop - The stop index of the quote.
      Returns:
      The (start,stop) pair of the inner content.
    • findCommentStartStop

      public static Pair<Integer,Integer> findCommentStartStop(String b, int start, int stop)
      Expects an xmq comment "// " or "/∗ ... ∗/" or "////∗ ∗////" or a comment continuation "∗ .... ∗/"
      Parameters:
      b - The buffer to search.
      start - The start index of the comment.
      stop - The stop index of the comment.
      Returns:
      The (start,stop) pair of the inner content.
    • trimQuote

      public static String trimQuote(String b, int start, int stop)
      Trims a quote according to xmq quoting rules.
      Parameters:
      b - The buffer to parse.
      start - The start index of the quote.
      stop - The stop index of the quote.
      Returns:
      The trimmed content.
    • countSame

      protected int countSame(int start, int stop)
      Look at the char at index start and count how many identical chars there are forward. Used to count identical quotes in a sequence or count number of spaces used for indentation.
      Overrides:
      countSame in class UtilQuote
      Parameters:
      start - The index of the character to count from.
      stop - The stop index of the counting.
      Returns:
      The number of identical characters.
    • findLeadingNewlines

      protected void findLeadingNewlines()
      Scans q_ for leading newline ('\n') and space (' ') characters.

      The method identifies sequences of newlines and spaces at the start of the string and determines the index of the last newline that precedes a line with non-space content.

      Example

      q_ = " \n  \n   Hello World";
      findLeadingNewlines();
      
      // num_leading_nl_ = 2
      // last_leading_nl_ = 4
      
      Overrides:
      findLeadingNewlines in class UtilQuote
    • findEndingNewlines

      protected void findEndingNewlines()
      Scans the buffer for trailing newlines and spaces.
      Overrides:
      findEndingNewlines in class UtilQuote
    • analyzeForParse

      public void analyzeForParse()
      Analyzes the quote for parsing.
    • parseQuote

      protected String parseQuote()
      Parses the quote into its content.
      Returns:
      The parsed content.