Debian Codegraph @

strconv/types.ha

raw
1 // SPDX-License-Identifier: MPL-2.0
2 // (c) Hare authors <https://harelang.org>
3
4 // Indicates that the input string doesn't have the requested number format
5 // (integer or float). Contains the index of the first invalid rune.
6 export type invalid = !size;
7
8 // Indicates that the input member can't be represented by the requested data
9 // type.
10 export type overflow = !void;
11
12 // Any error which may be returned from a strconv function.
13 export type error = !(invalid | overflow);
14
15 // The valid numeric bases for numeric conversions.
16 export type base = enum uint {
17 // Default base - decimal
18 DEFAULT = 0,
19
20 // Base 2, binary
21 BIN = 2,
22 // Base 8, octal
23 OCT = 8,
24 // Base 10, decimal
25 DEC = 10,
26 // Base 16, UPPERCASE hexadecimal
27 HEX_UPPER = 16,
28 // Alias for HEX_UPPER
29 HEX = 16,
30 // Base 16, lowercase hexadecimal
31 HEX_LOWER = 17,
32 };
33
34 // Converts an strconv [[error]] into a user-friendly string.
35 export fn strerror(err: error) str = {
36 match (err) {
37 case invalid =>
38 return "Input string doesn't have the requested number format";
39 case overflow =>
40 return "Input number doesn't fit into requested type";
41 };
42 };