Class StringPiece


public class StringPiece extends ExpressionPiece
Reads a string with escape sequences until it meets an end character (typically double or single quote).
  • Constructor Details

    • StringPiece

      public StringPiece(FilePointer ptr, char end)
      Construct a String Piece.
      Parameters:
      ptr - Creation pointer.
      end - Character that the string will end with. Does not have to be same as opening character.
  • Method Details

    • read

      public PieceResult read(char c, FilePointer ptr)
      Description copied from class: ExpressionPiece
      Parse a character by this piece.
      Specified by:
      read in class ExpressionPiece
      Parameters:
      c - Character to parse.
      ptr - Character position in file.
      Returns:
      PieceResult
    • content

      public String content()
      Get content of the string stored in this piece.
      Returns:
      String value.
    • toString

      public String toString()
      Content wrapped with start and end characters.
      Overrides:
      toString in class Object
      Returns:
      start + escape(CharSequence) + end
    • escape

      public static String escape(char c)
      Escape a character (replace by an associated code with escape prefix, for example '\n' -> "\\n").
      Parameters:
      c - Character to escape.
      Returns:
      Escaped character.
    • escape

      public static String escape(CharSequence s)
      Escape characters in the string.
      Parameters:
      s - String to escape.
      Returns:
      Escaped string.