FoldDoubledQuotes (StringTokenizer property)

From m204wiki
Revision as of 17:34, 15 November 2012 by JAL (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Doubled quotes treated as escaped quote char (StringTokenizer class)

[Introduced in Sirius Mods 7.8]


FoldDoubledQuotes provides implicit folding of a doubled Quotes character, which is common in User Language but not the default for the StringTokenizer.

Syntax

%currentBoolean = stringTokenizer:FoldDoubledQuotes stringTokenizer:FoldDoubledQuotes = newBoolean

Syntax terms

%currentBoolean An enumeration object of type Boolean to contain the value of FoldDoubledQuotes. The default value for a new tokenizer instance is False.
stringTokenizer A StringTokenizer object variable.
newBoolean A Boolean enumeration value.

Usage notes

  • The practice of doubling an apostrophe ( ' ) to yield a single apostrophe is common in User Language Print statements. For example, the result of Print 'Please, don''t go' is:

    Please, don't go

    The doubled, or escaped, apostrophe is implicitly folded to a single apostrophe. Similarly, if double quotation marks instead of the apostrophes are used to indicate a quoted string (as is allowed as of Sirius Mods version 7.8): Print "Please, don""t go"

    The result is:

    Please, don"t go

    The escaped double quotation mark is implicitly folded to one double quotation mark.

    The StringTokenizer, however, does not perform this implicit folding if it encounters a doubled Quotes character within a quoted region. For example:

    b %toke is object StringTokenizer %toke = new(quotes='"') %toke:string = '"Please, don""t go"' repeat while %toke:notAtEnd printtext {~} = '{%toke:nextToken}' end repeat end

    The result of this request is:

    %toke:nextToken = 'Please, don' %toke:nextToken = 't go'

    However, if FoldDoubledQuotes is set to True (which is not the default), the tokenizer considers two adjacent Quotes characters within a quoted region that is begun by the same Quotes character to be an escape sequence for a single quotation character, and the result of tokenizing %toke:string = '"Please, don""t go"' from the previous request is:

    Please, don"t go

  • If RemoveQuotes is set to True, folded quotes are removed.

See also