multilineString
Like value, but always serializes to a multiline string literal.
Returns error.InnerCarriageReturn if val contains a CR not followed by a newline,
since multiline strings cannot represent CR without a following newline.
Function parameters
Parameters
- self:*Serializer
- val:[]const u8
Type definitions in this namespace
Types
- ContainerOptions
- Options for manual serialization of container types.
- ValueOptions
- Options for serialization of an individual value.
- EmitCodepointLiterals
- Determines when to emit Unicode code point literals as opposed to integer literals.
- MultilineStringOptions
- Options for formatting multiline strings.
- Tuple
- Writes ZON tuples field by field.
- Struct
- Writes ZON structs field by field.
Serialize a value, similar to `serialize`.
Functions
- value
- Serialize a value, similar to `serialize`.
- valueMaxDepth
- Serialize a value, similar to `serializeMaxDepth`.
- valueArbitraryDepth
- Serialize a value, similar to `serializeArbitraryDepth`.
- int
- Serialize an integer.
- float
- Serialize a float.
- ident
- Serialize `name` as an identifier prefixed with `.`.
- codePoint
- Serialize `val` as a Unicode codepoint.
- tuple
- Like `value`, but always serializes `val` as a tuple.
- tupleMaxDepth
- Like `tuple`, but recursive types are allowed.
- tupleArbitraryDepth
- Like `tuple`, but recursive types are allowed.
- string
- Like `value`, but always serializes `val` as a string.
- multilineString
- Like `value`, but always serializes to a multiline string literal.
- beginStruct
- Create a `Struct` for writing ZON structs field by field.
- beginTuple
- Creates a `Tuple` for writing ZON tuples field by field.
Error sets in this namespace
Error Sets
Source
Implementation
pub fn multilineString(
self: *Serializer,
val: []const u8,
options: MultilineStringOptions,
) MultilineStringError!void {
// Make sure the string does not contain any carriage returns not followed by a newline
var i: usize = 0;
while (i < val.len) : (i += 1) {
if (val[i] == '\r') {
if (i + 1 < val.len) {
if (val[i + 1] == '\n') {
i += 1;
continue;
}
}
return error.InnerCarriageReturn;
}
}
if (!options.top_level) {
try self.newline();
try self.indent();
}
try self.writer.writeAll("\\\\");
for (val) |c| {
if (c != '\r') {
try self.writer.writeByte(c); // We write newlines here even if whitespace off
if (c == '\n') {
try self.indent();
try self.writer.writeAll("\\\\");
}
}
}
if (!options.top_level) {
try self.writer.writeByte('\n'); // Even if whitespace off
try self.indent();
}
}