v / vlib / toml / util / util.v
30 lines · 26 sloc · 1.07 KB · 5b9358279adc340d042c0255485a53a218bb8b47
Raw
1// Copyright (c) 2021 Lars Pontoppidan. All rights reserved.
2// Use of this source code is governed by an MIT license
3// that can be found in the LICENSE file.
4module util
5
6// is_key_char returns true if the given u8 is a valid key character.
7@[inline]
8pub fn is_key_char(c u8) bool {
9 return c.is_letter() // || c == `_` || c == `-` <- these are identified when tokenizing
10}
11
12// is_ascii_control_character returns true if `byte_char` is an ASCII control character.
13@[inline]
14pub fn is_ascii_control_character(byte_char u8) bool {
15 return (byte_char >= 0 && byte_char <= 0x1f) || byte_char == 0x7f
16}
17
18// is_illegal_ascii_control_character returns true if a `byte_char` ASCII control character
19// is considered "illegal" in TOML .
20@[inline]
21pub fn is_illegal_ascii_control_character(byte_char u8) bool {
22 return byte_char != 0x09 && is_ascii_control_character(byte_char)
23}
24
25// printdbg is a utility function for displaying a key:pair error message
26// when `-d trace_toml` is passed to the compiler.
27@[if trace_toml ?]
28pub fn printdbg(id string, message string) {
29 eprintln(id + ' ' + message)
30}
31