Package dev.omnist.codec
Class Encodability
java.lang.Object
dev.omnist.codec.Encodability
Rule C-9 of omnist-spec section 7.3: every writer fails with
write.unsupported-value, and
unconditionally, on a string value or an edge label that has no UTF-8 encoding. In Java that is a
lone surrogate: a high surrogate not followed by a low one, or a low surrogate not preceded by a
high one. A valid surrogate pair (an astral code point) and U+FFFD are ordinary text.
A writer must not emit such a string in any spelling, raw or as an escape, because a reader of
the output (a UTF-8 sink) could not accept it. The check is a fast pass that builds no path
(allEncodable(dev.omnist.document.Document)); only when it finds a failure does firstFailure(dev.omnist.document.Document) walk the document
again, in document order, to build the Document path of the node holding the string, or, for a
label, of the node holding the edge (a path cannot quote a label).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThrown by a writer that meets an unencodable string while it is writing, so that it needs no separate scan first; the writer catches it and turns it into therefusal(dev.omnist.document.Document)of C-9. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanallEncodable(Document doc) The fast pass: whether every edge label and string value ofdochas a UTF-8 encoding.static booleanWhethershas a UTF-8 encoding, that is, holds no lone surrogate.static WriteExceptionThe C-9 refusal for a document that holds a string value or an edge label with no UTF-8 encoding: aWriteExceptionwhose report has onewrite.unsupported-valueerror at the Document path of the first offending node.
-
Method Details
-
isEncodable
Whethershas a UTF-8 encoding, that is, holds no lone surrogate.- Parameters:
s- the string- Returns:
trueif every surrogate is half of a valid pair
-
allEncodable
The fast pass: whether every edge label and string value ofdochas a UTF-8 encoding. Builds no path and recurses on no Java stack, so a very deep document is safe.- Parameters:
doc- the document- Returns:
trueif nothing in it is unencodable
-
refusal
The C-9 refusal for a document that holds a string value or an edge label with no UTF-8 encoding: aWriteExceptionwhose report has onewrite.unsupported-valueerror at the Document path of the first offending node. Call it only for such a document.- Parameters:
doc- the document that was being written- Returns:
- the exception to throw
-