~sircmpwn/hare-dev

hare: strconv: Add base::DEFAULT instead of base::DEC being equal 0 v1 SUPERSEDED

Alexey Yerin: 1
 strconv: Add base::DEFAULT instead of base::DEC being equal 0

 5 files changed, 12 insertions(+), 9 deletions(-)
#1059419 alpine.yml failed
#1059420 freebsd.yml failed
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/hare-dev/patches/44845/mbox | git am -3
Learn more about email & git

[PATCH hare] strconv: Add base::DEFAULT instead of base::DEC being equal 0 Export this patch

Signed-off-by: Alexey Yerin <yyp@disroot.org>
---
 strconv/itos.ha  | 4 ++--
 strconv/stoi.ha  | 4 ++--
 strconv/stou.ha  | 4 ++--
 strconv/types.ha | 7 +++++--
 strconv/utos.ha  | 2 +-
 5 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/strconv/itos.ha b/strconv/itos.ha
index 8ce80640..0e5947dc 100644
--- a/strconv/itos.ha
+++ b/strconv/itos.ha
@@ -11,8 +11,8 @@ use strings;
// duplicate the result.
export fn i64tosb(i: i64, b: base) const str = {
	static assert(types::I64_MAX == 9223372036854775807);
	if (b == base::DEC) {
		b = 10;
	if (b == base::DEFAULT) {
		b = base::DEC;
	};

	if (i >= 0) return u64tosb(i: u64, b);
diff --git a/strconv/stoi.ha b/strconv/stoi.ha
index 72732343..1a43fc22 100644
--- a/strconv/stoi.ha
+++ b/strconv/stoi.ha
@@ -23,8 +23,8 @@ export fn stoi64b(s: str, base: base) (i64 | invalid | overflow) = {
	} else if (b[0] == '+') {
		start = 1;
	};
	if (base == base::DEC) {
		base = 10;
	if (base == base::DEFAULT) {
		base = base::DEC;
	};
	let u = stou64b(strings::fromutf8_unsafe(b[start..]), base);
	let n = u?;
diff --git a/strconv/stou.ha b/strconv/stou.ha
index 34822b7e..6fa0d1c7 100644
--- a/strconv/stou.ha
+++ b/strconv/stou.ha
@@ -20,8 +20,8 @@ fn rune_to_integer(r: rune) (u64 | void) = {
// non-numeric characters, or if it's empty, [[invalid]] is returned. If the
// number is too large to be represented by a u64, [[overflow]] is returned.
export fn stou64b(s: str, base: base) (u64 | invalid | overflow) = {
	if (base == base::DEC) {
		base = 10;
	if (base == base::DEFAULT) {
		base = base::DEC;
	};
	assert(base == 2 || base == 8 || base == 10 || base == 16);

diff --git a/strconv/types.ha b/strconv/types.ha
index a62e0ff0..ac57259a 100644
--- a/strconv/types.ha
+++ b/strconv/types.ha
@@ -16,12 +16,15 @@ 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 (default)
	DEC = 0,
	// Base 10, decimal
	DEC = 10,
	// Base 16, UPPERCASE hexadecimal
	HEX_UPPER = 16,
	// Alias for HEX_UPPER
diff --git a/strconv/utos.ha b/strconv/utos.ha
index d55af8f9..429a25e1 100644
--- a/strconv/utos.ha
+++ b/strconv/utos.ha
@@ -24,7 +24,7 @@ export fn u64tosb(u: u64, b: base) const str = {
		yield &lut_lower;
	};

	const b: uint = if (b == base::DEC) 10 else b;
	const b: uint = if (b == base::DEFAULT) base::DEC else b;

	let s = types::string { data = &buf, ... };
	if (u == 0) {
-- 
2.42.0
hare/patches: FAILED in 2m10s

[strconv: Add base::DEFAULT instead of base::DEC being equal 0][0] from [Alexey Yerin][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/44845
[1]: mailto:yyp@disroot.org

✗ #1059420 FAILED hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/1059420
✗ #1059419 FAILED hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/1059419