parseString

Parse and validate a string from an iopipe. This functions serves several purposes. First, it determines how long the string actually is, so it can be properly parsed out. Second, it verifies any escapes inside the string. Third, if requested, it can replace any escapes with the actual characters in-place, so the string result can just be used. Note that this does not verify any UTF code units are valid. However, any unicode escapes using the \uXXXX sequence are validated.

int
parseString
(
bool replaceEscapes = true
Chain
)
(
ref Chain c
,
ref size_t pos
,)

Parameters

replaceEscapes

If true, then any encountered escapes will be replaced with the actual utf characters they represent, properly encoded for the given element type.

c Chain

The iopipe to parse the string from. If the end of the string is not present in the current window, it will be extended until the end is found.

pos size_t

Upon calling, this should be the position in the stream window where the first quotation mark is for this string. Upon exit, if successfully parsed, pos is updated to the position just after the final quotation mark. If an error occurs, pos should be at the spot where the invalid sequence occurred.

hint JSONParseHint

Set to InPlace if the string no longer contains escapes (either there weren't any, or they have been replaced). Set to Escapes if the string still contains escapes that need to be properly parsed.

Return Value

Type: int

number of elements in the resulting string if successfully parsed, or -1 if there is an error. Note that if escapes are not replaced, then this number includes the escape character sequences as-is.

Meta