Function strLitSizeHint [src]

Estimates the size of a string node without parsing it.

Prototype

pub fn strLitSizeHint(tree: Ast, node: Ast.Node.Index) usize

Parameters

tree: Astnode: Ast.Node.Index

Source

pub fn strLitSizeHint(tree: Ast, node: Ast.Node.Index) usize { switch (tree.nodeTag(node)) { // Parsed string literals are typically around the size of the raw strings. .string_literal => { const token = tree.nodeMainToken(node); const raw_string = tree.tokenSlice(token); return raw_string.len; }, // Multiline string literal lengths can be computed exactly. .multiline_string_literal => { const first_tok, const last_tok = tree.nodeData(node).token_and_token; var size = tree.tokenSlice(first_tok)[2..].len; for (first_tok + 1..last_tok + 1) |tok_idx| { size += 1; // Newline size += tree.tokenSlice(@intCast(tok_idx))[2..].len; } return size; }, else => unreachable, } }