README

#Strconv

Deprecated compatibility package. Use the matching APIs in @string instead: parse_bool, parse_int, parse_int64, parse_uint, parse_uint64, parse_double, and from_str.

#Parsing Integers

Parse integers in various bases:

///|
#warnings("-deprecated")
test "parse_int" {
inspect(@strconv.parse_int("42"), content="42")
inspect(@strconv.parse_int("101", base=2), content="5")
inspect(@strconv.parse_int("ff", base=16), content="255")
}

Parse 64-bit integers and unsigned integers:

///|
#warnings("-deprecated")
test "parse_int64_uint" {
inspect(
@strconv.parse_int64("9223372036854775807"),
content="9223372036854775807",
)
inspect(@strconv.parse_uint("42"), content="42")
inspect(
@strconv.parse_uint64("18446744073709551615"),
content="18446744073709551615",
)
}

#Parsing Other Types

///|
#warnings("-deprecated")
test "parse_other" {
inspect(@strconv.parse_bool("true"), content="true")
inspect(@strconv.parse_double("3.14"), content="3.14")
}

#FromStr Trait

Types implementing FromStr can be parsed using from_str. Use @string.from_str in new code.

///|
#warnings("-deprecated")
test "from_str" {
let i : Int = @strconv.from_str("123")
inspect(i, content="123")
let b : Bool = @strconv.from_str("false")
inspect(b, content="false")
let d : Double = @strconv.from_str("2.718")
inspect(d, content="2.718")
}

FromStr is implemented for Bool, Int, Int64, UInt, UInt64, and Double. Prefer @string.FromStr in new code.

#Error Handling

Parse functions raise StrConvError on invalid input. Use the @string versions in new code.

///|
#warnings("-deprecated")
test "error_handling" {
let result : Result[Int, _] = try! @strconv.parse_int("abc")
inspect(result is Err(_), content="true")
}

#
FromStr

#deprecated("use `@string.FromStr` instead")
pub(open) trait FromStr {
#deprecated("use `@string.from_str` instead")
#as_free_fn
fn from_str(StringView) -> Self raise StrConvError = _
#deprecated("use `@string.from_str` instead")
fn from_string(String) -> Self raise StrConvError = _
}

Trait for parsing values from textual input.

Implement either from_str (preferred) or legacy from_string.
impl FromStr for Bool
impl FromStr for Int
impl FromStr for Int64
impl FromStr for UInt
impl FromStr for UInt64
impl FromStr for Double

#
StrConvError

#deprecated("use `@string` parsing APIs instead")
pub(all) suberror StrConvError {
StrConvError(String)
} derive(
Debug
)

Error type StrConvError.

#
StrConvError::to_string

fn StrConvError::to_string(self : StrConvError) -> String

#
Decimal

#deprecated("use `@string.parse_double` instead")
type Decimal derive(
Debug
)

High Precision Decimal structure for "Simple Decimal Conversion" algorithm. Developed by Ken. Thompson, Russ Cox, Robert Griesemer, Nigel Tao.

reference:
impl Show for Decimal

#
Decimal::from_int64

#deprecated("use `@string.parse_double` instead")
fn Decimal::from_int64(v : Int64) -> Decimal

Create a decimal with an Int64 value.

#
Decimal::new

#deprecated("use `@string.parse_double` instead")
fn Decimal::new() -> Decimal

Create a zero decimal.

#
Decimal::parse_decimal

#deprecated("use `@string.parse_double` instead")
fn Decimal::parse_decimal(str : StringView) -> Decimal raise StrConvError

Function parse_decimal.

#
Decimal::shift

#deprecated("use `@string.parse_double` instead")
fn Decimal::shift(self : Decimal, s : Int) -> Unit

Binary shift left (s > 0) or right (s < 0). The shift count must not larger than the max_shift to avoid overflow.

#
Decimal::to_double

#deprecated("use `@string.parse_double` instead")
fn Decimal::to_double(self : Decimal) -> Double raise StrConvError

Convert the decimal to Double.

#
Decimal::to_string

fn Decimal::to_string(self : Decimal) -> String

#
parse

#deprecated("use `@string.from_str` instead")
fn[A : FromStr] parse(str : StringView) -> A raise StrConvError

Parse input into this package's structured value.

#
parse_bool

#deprecated("use `@string.parse_bool` instead")
fn parse_bool(str : StringView) -> Bool raise StrConvError

Parse a string and return the represented boolean value or an error.

#
parse_decimal

#deprecated("use `@string.parse_double` instead")
fn parse_decimal(str : StringView) -> Decimal raise StrConvError

Function parse_decimal.

#
parse_double

#deprecated("use `@string.parse_double` instead")
fn parse_double(str : StringView) -> Double raise StrConvError

Parse a string into a double precision floating point number. The string must contain at least one of:
  • An integer part (decimal digits)
  • A decimal point followed by a fractional part (decimal digits)
  • An exponent part ('e' or 'E' followed by an optional sign and decimal digits)

The string may optionally start with a sign ('+' or '-'). For readability, underscores may appear between digits.

Examples:
#warnings("-deprecated")
test {
inspect(@strconv.parse_double("123"), content="123")
inspect(@strconv.parse_double("12.34"), content="12.34")
inspect(@strconv.parse_double(".123"), content="0.123")
inspect(@strconv.parse_double("1e5"), content="100000")
inspect(@strconv.parse_double("1.2e-3"), content="0.0012")
inspect(@strconv.parse_double("1_234.5"), content="1234.5")
}

An exponent value exp scales the mantissa (significand) by 10^exp. For example, "1.23e2" represents 1.23 × 10² = 123.

#
parse_int

#deprecated("use `@string.parse_int` instead")
fn parse_int(str : StringView, base? : Int) -> Int raise StrConvError

Parse a string in the given base (0, 2 to 36), return a Int number or an error. If the ~base argument is 0, the base will be inferred by the prefix.

#
parse_int64

#deprecated("use `@string.parse_int64` instead")
fn parse_int64(str : StringView, base? : Int) -> Int64 raise StrConvError

Parses a string into an Int64 number using the specified base, or returns an error. The base must be 0 or between 2 and 36 (inclusive). If base is 0, it will be inferred from the string prefix:
  • "0x" or "0X" for base 16 (hex)
  • "0o" or "0O" for base 8 (octal)
  • "0b" or "0B" for base 2 (binary)
  • Default is base 10 (decimal) For readability, underscores may appear after base prefixes or between digits. These underscores do not affect the value. Examples:
#warnings("-deprecated")
test {
inspect(@strconv.parse_int64("123"), content="123")
inspect(@strconv.parse_int64("0xff", base=0), content="255")
inspect(@strconv.parse_int64("0o10"), content="8")
inspect(@strconv.parse_int64("0b1010"), content="10")
inspect(@strconv.parse_int64("1_234"), content="1234")
inspect(@strconv.parse_int64("-123"), content="-123")
inspect(@strconv.parse_int64("ff", base=16), content="255")
inspect(@strconv.parse_int64("zz", base=36), content="1295")
}

#
parse_uint

#deprecated("use `@string.parse_uint` instead")
fn parse_uint(str : StringView, base? : Int) -> UInt raise StrConvError

Parse a string in the given base (0, 2 to 36), return an UInt number or an error. If the ~base argument is 0, the base will be inferred by the prefix.

#
parse_uint64

#deprecated("use `@string.parse_uint64` instead")
fn parse_uint64(str : StringView, base? : Int) -> UInt64 raise StrConvError

Parses a string into a UInt64 number using the specified base, or returns an error. The base must be 0 or between 2 and 36 (inclusive). If base is 0, it will be inferred from the string prefix:
  • "0x" or "0X" for base 16 (hex)
  • "0o" or "0O" for base 8 (octal)
  • "0b" or "0B" for base 2 (binary)
  • Default is base 10 (decimal) For readability, underscores may appear after base prefixes or between digits. These underscores do not affect the value. Examples:
#warnings("-deprecated")
test {
inspect(@strconv.parse_uint64("123"), content="123")
inspect(@strconv.parse_uint64("0xff", base=0), content="255")
inspect(@strconv.parse_uint64("0o10"), content="8")
inspect(@strconv.parse_uint64("0b1010"), content="10")
inspect(@strconv.parse_uint64("1_234"), content="1234")
inspect(@strconv.parse_uint64("ff", base=16), content="255")
inspect(@strconv.parse_uint64("zz", base=36), content="1295")
}