append_snippet

func append_snippet(mut buf: [Byte], view: UTF8View, start: Int, end: Int) -> Void

Appends a diagnostic snippet for a short, single-line byte range.

Empty, multi-line, or longer-than-40-byte ranges are omitted. Quotes, backslashes, tabs, and returns are escaped so the validation dump remains one deterministic line; offsets are raw UTF-8 bytes.

View Source
pub func append_snippet(mut buf: [Byte], view: UTF8View, start: Int, end: Int) -> Void {
	if end <= start || end - start > 40 {
		return ()
	}
	let j = start
	loop j < end {
		if view.at(index: j)._toInt() == newline_byte {
			return ()
		}
		j = j + 1
	}
	append(buf: buf, text: " \"")
	let k = start
	loop k < end {
		let c = view.at(index: k)._toInt()
		if c == backslash_byte {
			append(buf: buf, text: "\\\\")
		} else {
			if c == quote_byte {
				append(buf: buf, text: "\\\"")
			} else {
				if c == tab_byte {
					append(buf: buf, text: "\\t")
				} else {
					if c == return_byte {
						append(buf: buf, text: "\\r")
					} else {
						buf.push(view.at(index: k))
					}
				}
			}
		}
		k = k + 1
	}
	append(buf: buf, text: "\"")
}