File: types.ha

package info (click to toggle)
hare 0.25.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,948 kB
  • sloc: asm: 1,264; makefile: 123; sh: 114; lisp: 101
file content (42 lines) | stat: -rw-r--r-- 1,115 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// SPDX-License-Identifier: MPL-2.0
// (c) Hare authors <https://harelang.org>

// Indicates that the input string doesn't have the requested number format
// (integer or float). Contains the index of the first invalid rune.
export type invalid = !size;

// Indicates that the input member can't be represented by the requested data
// type.
export type overflow = !void;

// Any error which may be returned from a strconv function.
export type error = !(invalid | overflow);

// The valid numeric bases for numeric conversions.
export type base = enum uint {
	// Default base - decimal
	DEFAULT = 0,

	// Base 2, binary
	BIN = 2,
	// Base 8, octal
	OCT = 8,
	// Base 10, decimal
	DEC = 10,
	// Base 16, UPPERCASE hexadecimal
	HEX_UPPER = 16,
	// Alias for HEX_UPPER
	HEX = 16,
	// Base 16, lowercase hexadecimal
	HEX_LOWER = 17,
};

// Converts an strconv [[error]] into a user-friendly string.
export fn strerror(err: error) str = {
	match (err) {
	case invalid =>
		return "Input string doesn't have the requested number format";
	case overflow =>
		return "Input number doesn't fit into requested type";
	};
};