The following example shows two implementations of some code that unquotes a string a classical implementation and an implementation with a state pattern.
A quoted string starts and ends with a double-quote character ("). Any occurrence of a double-quote character in a string is represented by two occurrences of that character. The following table shows a few examples of strings that have been converted into a quoted form:
String | Quoted string |
Delphi | "Delphi" |
Delphi and patterns | "Delphi and patterns" |
Delphi "ROCKS!" | "Delphi ""Rocks!""" |
An unquoting algorithm takes the quoted string (for example, "quoted ""quoted""") and converts it into its original form (quoted "quoted"). Its behavior can be represented with ...