Class Utils

java.lang.Object
com.github.rjeschke.txtmark.Utils

class Utils extends Object
Utilities.
  • Field Details

    • RND

      private static int RND
      Random number generator value.
  • Constructor Details

    • Utils

      Utils()
  • Method Details

    • rnd

      public static final int rnd()
      LCG random number generator.
      Returns:
      A pseudo random number between 0 and 1023
    • skipSpaces

      public static final int skipSpaces(String in, int start)
      Skips spaces in the given String.
      Parameters:
      in - Input String.
      start - Starting position.
      Returns:
      The new position or -1 if EOL has been reached.
    • escape

      public static final int escape(StringBuilder out, char ch, int pos)
      Processed the given escape sequence.
      Parameters:
      out - The StringBuilder to write to.
      ch - The character.
      pos - Current parsing position.
      Returns:
      The new position.
    • readUntil

      public static final int readUntil(StringBuilder out, String in, int start, char... end)
      Reads characters until any 'end' character is encountered.
      Parameters:
      out - The StringBuilder to write to.
      in - The Input String.
      start - Starting position.
      end - End characters.
      Returns:
      The new position or -1 if no 'end' char was found.
    • readUntil

      public static final int readUntil(StringBuilder out, String in, int start, char end)
      Reads characters until the 'end' character is encountered.
      Parameters:
      out - The StringBuilder to write to.
      in - The Input String.
      start - Starting position.
      end - End characters.
      Returns:
      The new position or -1 if no 'end' char was found.
    • readMdLink

      public static final int readMdLink(StringBuilder out, String in, int start)
      Reads a markdown link.
      Parameters:
      out - The StringBuilder to write to.
      in - Input String.
      start - Starting position.
      Returns:
      The new position or -1 if this is no valid markdown link.
    • readMdLinkId

      public static final int readMdLinkId(StringBuilder out, String in, int start)
      Reads a markdown link ID.
      Parameters:
      out - The StringBuilder to write to.
      in - Input String.
      start - Starting position.
      Returns:
      The new position or -1 if this is no valid markdown link ID.
    • readRawUntil

      public static final int readRawUntil(StringBuilder out, String in, int start, char... end)
      Reads characters until any 'end' character is encountered, ignoring escape sequences.
      Parameters:
      out - The StringBuilder to write to.
      in - The Input String.
      start - Starting position.
      end - End characters.
      Returns:
      The new position or -1 if no 'end' char was found.
    • readRawUntil

      public static final int readRawUntil(StringBuilder out, String in, int start, char end)
      Reads characters until the end character is encountered, taking care of HTML/XML strings.
      Parameters:
      out - The StringBuilder to write to.
      in - The Input String.
      start - Starting position.
      end - End characters.
      Returns:
      The new position or -1 if no 'end' char was found.
    • readXMLUntil

      public static final int readXMLUntil(StringBuilder out, String in, int start, char... end)
      Reads characters until any 'end' character is encountered, ignoring escape sequences.
      Parameters:
      out - The StringBuilder to write to.
      in - The Input String.
      start - Starting position.
      end - End characters.
      Returns:
      The new position or -1 if no 'end' char was found.
    • appendCode

      public static final void appendCode(StringBuilder out, String in, int start, int end)
      Appends the given string encoding special HTML characters.
      Parameters:
      out - The StringBuilder to write to.
      in - Input String.
      start - Input String starting position.
      end - Input String end position.
    • appendValue

      public static final void appendValue(StringBuilder out, String in, int start, int end)
      Appends the given string encoding special HTML characters (used in HTML attribute values).
      Parameters:
      out - The StringBuilder to write to.
      in - Input String.
      start - Input String starting position.
      end - Input String end position.
    • appendDecEntity

      public static final void appendDecEntity(StringBuilder out, char value)
      Append the given char as a decimal HTML entity.
      Parameters:
      out - The StringBuilder to write to.
      value - The character.
    • appendHexEntity

      public static final void appendHexEntity(StringBuilder out, char value)
      Append the given char as a hexadecimal HTML entity.
      Parameters:
      out - The StringBuilder to write to.
      value - The character.
    • appendMailto

      public static final void appendMailto(StringBuilder out, String in, int start, int end)
      Appends the given mailto link using obfuscation.
      Parameters:
      out - The StringBuilder to write to.
      in - Input String.
      start - Input String starting position.
      end - Input String end position.
    • getXMLTag

      public static final void getXMLTag(StringBuilder out, StringBuilder in)
      Extracts the tag from an XML element.
      Parameters:
      out - The StringBuilder to write to.
      in - Input StringBuilder.
    • getXMLTag

      public static final void getXMLTag(StringBuilder out, String in)
      Extracts the tag from an XML element.
      Parameters:
      out - The StringBuilder to write to.
      in - Input String.
    • readXML

      public static final int readXML(StringBuilder out, String in, int start, boolean safeMode)
      Reads an XML element.
      Parameters:
      out - The StringBuilder to write to.
      in - Input String.
      start - Starting position.
      safeMode - Whether to escape unsafe HTML tags or not
      Returns:
      The new position or -1 if this is no valid XML element.
    • codeEncode

      public static final void codeEncode(StringBuilder out, String value, int offset)
      Appends the given string to the given StringBuilder, replacing '&', '<' and '>' by their respective HTML entities.
      Parameters:
      out - The StringBuilder to append to.
      value - The string to append.
      offset - The character offset into value from where to start
    • getMetaFromFence

      public static final String getMetaFromFence(String fenceLine)
      Removes trailing ` or ~ and trims spaces.
      Parameters:
      fenceLine - Fenced code block starting line
      Returns:
      Rest of the line after trimming and backtick or tilde removal
      Since:
      0.7