2021-09-24 21:13:52 +03:00
|
|
|
// Copyright (c) 2021 Lars Pontoppidan. All rights reserved.
|
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
module util
|
|
|
|
|
2022-11-22 20:45:12 +03:00
|
|
|
// is_key_char returns true if the given u8 is a valid key character.
|
2021-09-24 21:13:52 +03:00
|
|
|
[inline]
|
2022-04-15 18:25:45 +03:00
|
|
|
pub fn is_key_char(c u8) bool {
|
2021-09-24 21:13:52 +03:00
|
|
|
return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`) // || c == `_` || c == `-` <- these are identified when tokenizing
|
|
|
|
}
|
|
|
|
|
2021-10-22 19:57:32 +03:00
|
|
|
// is_ascii_control_character returns true if `byte_char` is an ASCII control character.
|
|
|
|
[inline]
|
2022-04-15 18:25:45 +03:00
|
|
|
pub fn is_ascii_control_character(byte_char u8) bool {
|
2021-10-22 19:57:32 +03:00
|
|
|
return (byte_char >= 0 && byte_char <= 0x1f) || byte_char == 0x7f
|
|
|
|
}
|
|
|
|
|
|
|
|
// is_illegal_ascii_control_character returns true if a `byte_char` ASCII control character
|
|
|
|
// is considered "illegal" in TOML .
|
|
|
|
[inline]
|
2022-04-15 18:25:45 +03:00
|
|
|
pub fn is_illegal_ascii_control_character(byte_char u8) bool {
|
2021-10-22 19:57:32 +03:00
|
|
|
return byte_char != 0x09 && is_ascii_control_character(byte_char)
|
|
|
|
}
|
|
|
|
|
2022-11-22 20:45:12 +03:00
|
|
|
// printdbg is a utility function for displaying a key:pair error message
|
|
|
|
// when `-d trace_toml` is passed to the compiler.
|
2021-09-24 21:13:52 +03:00
|
|
|
[if trace_toml ?]
|
|
|
|
pub fn printdbg(id string, message string) {
|
|
|
|
eprintln(id + ' ' + message)
|
|
|
|
}
|