encodeStringAsIdentifier
java.lang.String encodeStringAsIdentifier(java.lang.String prefix,
java.lang.String s)
Returns a legal identifier that uniquely characterizes string 's'.
We want the identifier to be a function of the string value because that
makes the identifiers stable as the program is changed.
The digits of a good hash function would be adequate, but for short
strings the following algorithm is easier to work with for unit tests.
ASCII alphanumerics are mapped to themselves. Other characters are
mapped to $XXX or $XXX_ where XXX is a variable number of hex digits.
The underscore is inserted as necessary to avoid ambiguity when the
character following is a hex digit. E.g. '\n1' maps to '$a_1',
distinguished by the underscore from 'ยก' which maps to '$a1'.
If the string is short enough, this is sufficient. Longer strings are
truncated after encoding an initial prefix and appended with a hash
value.