Skip to main content

Module java

Module java 

Source
Expand description

java string literal encoder.

encodes untrusted strings for safe embedding in java string literals.

  • for_java — safe for java string and char literal contexts

§encoding rules

  • named escapes: \b, \t, \n, \f, \r, \", \', \\
  • other C0 controls and DEL → octal escapes (shortest form, or 3-digit when the next character is an octal digit to avoid ambiguity)
  • U+2028, U+2029 → \u2028, \u2029 (java line terminators)
  • supplementary plane characters (U+10000+) → UTF-16 surrogate pairs (\uHHHH\uHHHH)
  • unicode non-characters → space

Functions§

for_java
encodes input for safe embedding in a java string literal.
write_java
writes the java-encoded form of input to out.