Static utilities for encoding and markup handling.

Member Details

convert_attribute_names_to_lowercase(attribute_array) static

Routine to add lowercase keys for key-value pairs in the argument map, and delete the respective upercase keys.

Parameters

Name Type Description
attribute_array object.<string, string>
convert_attribute_names_to_uppercase(attribute_array) static

Routine to add uppercase keys for key-value pairs in the argument map, and delete the respective lowercase keys.

Parameters

Name Type Description
attribute_array object.<string, string>
format_for_errormsg(s) static

Returns supplied SGML code text formatted/shortened and quoted for display as quoted token in error messages.

Parameters

Name Type Description
s string
is_not_valid_literal_token(token, role): string static

Checks validity of a string as default attribute value in the concrete syntax, returning an appropriate error message if invalid.

Parameters

Name Type Description
token string

string to check

role string

English language description of the role of the token as text to be printed in error messages (eg. "attribute default value"); can be omitted or left empty if the calling routine merely checks for a non-empty return value, but doesn't use the returned string as message

Returns

string

an error message describing the reason of invalidity, or the empty string if token is valid as attribute default value

is_not_valid_name_token(token, role): string static

Checks validity of a string as name token in the concrete SGML syntax, returning an appropriate error message if invalid.

Parameters

Name Type Description
token string

string to check

role string

English language description of the role of the token as text to be printed in error messages (eg. "name token")

Returns

string

an error message describing the reason of invalidity, or the empty string if token is valid as name token

is_not_valid_xml_literal_token(token): string static

Checks if token is a valid XML literal.

TODO: clarify what this is checking exactly TODO: this just reuses is_not_valid_xml_name_token(), which isn't quite correct, but ok for now

Parameters

Name Type Description
token string

string to check

Returns

string

a non-empty string if token is invalid as XML literal, the empty string otherwise (a HTML/SGML/XML literal may be given unquoted as the value of an attribute)

is_not_valid_xml_name_token(token, role): string static

Checks if token is a valid xml element name (by regexp approximation and some other tests).

Should cover most practical usage of the http://www.w3.org/TR/REC-xml/#NT-Name production.

TODO: get rid of this or use only for XML

Parameters

Name Type Description
token string

the string to check

role string

English language description of the role of the token as text to be printed in error messages (eg. "element name" or "attribute name")

Returns

string

a non-empty string containing an error message if token is valid; the empty string otherwise

sgml_formatattrs(attrarray, force_lowercase): string static

Returns an attribute specification (string serialization) of all the attributes of attrarray, suitable for direct use as the attribute portion of a start-element tag (inverse of parseattrs()).

Attributes are sorted lexicographically for deterministic output order. (TODO: make sorting a compile-time switch, is just for test cases)

Attributes get serialized double-quoted by default; attribute values containing verbatim double quotes get single-quoted, unless they contain both double and single quotes, in which case they get double-quoted and double quote characters get encoded as numeric character references (&#34;).

Parameters

Name Type Description
attrarray Object.<string, string>

attributes map to format

force_lowercase boolean

whether to case-fold attribute names to lowercase

Returns

string

formatted attribute serialization(s)

sgml_index3(str, portion, offset): number static

Returns the position of the first occurence of portion in str at or after offset.

Parameters

Name Type Description
str string

string to search in

portion string

string to search for

offset number

1-based position in str to start search at

Returns

number

1-based position of portion in str relative to the beginning of str

sgml_parseattrs(attrstr, attrarray): number static

Populates attrarray attribute value assignments from a string without direction by attribute declarations.

This works mostly like Tokenizer.parse_attribute_specification() except in the case of token attributes (strings in attrstr that can't be parsed as att=value but have only value): where these are parsed as attribute values by parse.parse_attribute_specification(), this routine puts those as attribute names having the name itself as value. For example, the attributes of <elmt att> are parsed as att=att. This is used by strip_markdown_vocabulary() and for PI attributes where attribute declarations aren't required or material.

TODO: drop support for unquoted and shortform attrs

Parameters

Name Type Description
attrstr string

containing attribute value specification(s)

attrarray Object.<string, string>

map to insert parsed attribute/value assignments into

Returns

number

0 if unsuccesfull, a value != 0 otherwise

sgml_rindex(str, portion): number static

Returns the position of the last occurence of portion in str, or 0 if portion isn't a substring of str.

Parameters

Name Type Description
str string

string to search in

portion string

string to search for

Returns

number
sgml_trim(s): string static

Returns the argument string with leading and trailing whitespace removed.

Parameters

Name Type Description
s string

argument string

Returns

string

s with leading/trailing whitespace removed