Class QuotedString

java.lang.Object
com.authlete.http.QuotedString
All Implemented Interfaces:
Serializable

public class QuotedString extends Object implements Serializable
This class represents the quoted string as defined in RFC 9110: HTTP Semantics, Section 5.6.4. Quoted Strings.

Definition

 quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE
 qdtext        = HTAB / SP / %x21 / %x23-5B / %x5D-7E / obs-text
 quoted-pair   = "\" ( HTAB / SP / VCHAR / obs-text )
 

Sample Code 1

 // Parse the string as a quoted string. Note that a quoted
 // string must be enclosed with double quotes.
 QuotedString qs = QuotedString.parse("\"qs\"");

 // The string returned from the getValue() method is not
 // enclosed with double quotes.
 assertEquals("qs", qs.getValue());

 // The string returned from the toString() method is
 // enclosed with double quotes.
 assertEquals("\"qs\"", qs.toString());
 

Sample Code 2

 // Parse a quoted string without content.
 QuotedString qs = QuotedString.parse("\"\"");

 // The getValue() method returns an empty string.
 assertEquals("", qs.getValue());

 // The toString() method returns a string containing
 // two double quotes.
 assertEquals("\"\"", qs.toString());
 

Sample Code 3

 // !\!\"\\
 String escaped = "!\\!\\\"\\\\";

 // !!"\
 String unescaped = "!!\"\\";

 // "!\!\"\\"
 String input = new StringBuilder()
     .append('"').append(escaped).append('"').toString();

 // Parse
 QuotedString qs = QuotedString.parse(input);

 // (Escaped) value
 assertEquals(escaped, qs.getValue());

 // Unescaped value
 assertEquals(unescaped, qs.getUnescapedValue());
 
See Also: