Module strconv stdlib

strconv
Version:
0.3.3
License:
MIT
Dependencies from vmod:
0
Imports:
3
Imported by:
13
Repository:
OS-specific
Show selected OS-specific symbols.
Backend-specific
Show selected Backend-specific symbols.

Dependencies defined in v.mod

This section is empty.

Imports

Overview

strconv provides functions for converting strings to numbers and numbers to strings.

Aliases

This section is empty.

Constants

#constant single_plus_zero

single_plus_zero      = u32(0x0000_0000)

f32 constants

#constant single_minus_zero

single_minus_zero     = u32(0x8000_0000)

f32 constants

#constant single_plus_infinity

single_plus_infinity  = u32(0x7F80_0000)

f32 constants

#constant single_minus_infinity

single_minus_infinity = u32(0xFF80_0000)

f32 constants

#constant digits

digits                = 18

f64 constants

#constant double_plus_zero

double_plus_zero      = u64(0x0000000000000000)

f64 constants

#constant double_minus_zero

double_minus_zero     = u64(0x8000000000000000)

f64 constants

#constant double_plus_infinity

double_plus_infinity  = u64(0x7FF0000000000000)

f64 constants

#constant double_minus_infinity

double_minus_infinity = u64(0xFFF0000000000000)

f64 constants

#constant c_dpoint

c_dpoint = `.`

char constants

#constant c_plus

c_plus   = `+`

char constants

#constant c_minus

c_minus  = `-`

char constants

#constant c_zero

c_zero   = `0`

char constants

#constant c_nine

c_nine   = `9`

char constants

#constant c_ten

c_ten    = u32(10)

char constants

Sum types

This section is empty.

Functions

#fn atof64

JavaScript
fn atof64(s string) !f64

atof64 return a f64 from a string doing a parsing operation

#fn atof64

fn atof64(s string) !f64

atof64 parses the string s, and if possible, converts it into a f64 number

#fn atof_quick

direct_array_access
fn atof_quick(s string) f64

atof_quick return a f64 number from a string in a quick way

#fn atoi

direct_array_access
fn atoi(s string) !int

atoi is equivalent to parse_int(s, 10, 0), converted to type int.

#fn byte_to_lower

inline
fn byte_to_lower(c u8) u8

#fn common_parse_int

direct_array_access
fn common_parse_int(_s string, base int, _bit_size int, error_on_non_digit bool, error_on_high_digit bool) !i64

common_parse_int is called by parse int and allows the parsing to stop on non or invalid digit characters and return with an error

#fn common_parse_uint

fn common_parse_uint(s string, _base int, _bit_size int, error_on_non_digit bool, error_on_high_digit bool) !u64

common_parse_uint is called by parse_uint and allows the parsing to stop on non or invalid digit characters and return with an error

#fn common_parse_uint2

direct_array_access
fn common_parse_uint2(s string, _base int, _bit_size int) (u64, int)

the first returned value contains the parsed value, the second returned value contains the error code (0 = OK, >1 = index of first non-parseable character + 1, -1 = wrong base, -2 = wrong bit size, -3 = overflow)

#fn dec_digits

fn dec_digits(n u64) int

dec_digits return the number of decimal digit of an u64

#fn f32_to_str

fn f32_to_str(f f32, n_digit int) string

f32_to_str returns a string in scientific notation with max n_digit after the dot.

#fn f32_to_str_l

manualfree
fn f32_to_str_l(f f32) string

TODO: Investigate precision issues f32_to_str_l returns f as a string in decimal notation with a maximum of 6 digits after the dot.

Example:

assert strconv.f32_to_str_l(34.1234567) == '34.12346'

#fn f32_to_str_l_with_dot

manualfree
fn f32_to_str_l_with_dot(f f32) string

f32_to_str_l_with_dot returns f as a string in decimal notation with a maximum of 6 digits after the dot.

If the decimal digits after the dot are zero, a '.0' is appended for clarity.

Example:

assert strconv.f32_to_str_l_with_dot(34.) == '34.0'

#fn f32_to_str_pad

fn f32_to_str_pad(f f32, n_digit int) string

f32_to_str_pad returns a string in scientific notation with max n_digit after the dot.

#fn f64_to_str

fn f64_to_str(f f64, n_digit int) string

f64_to_str returns f as a string in scientific notation with max n_digit digits after the dot.

#fn f64_to_str_l

manualfree
fn f64_to_str_l(f f64) string

f64_to_str_l returns f as a string in decimal notation with a maximum of 18 digits after the dot.

Example:

assert strconv.f64_to_str_l(123.1234567891011121) == '123.12345678910111'

#fn f64_to_str_l_with_dot

manualfree
fn f64_to_str_l_with_dot(f f64) string

f64_to_str_l_with_dot returns f as a string in decimal notation with a maximum of 18 digits after the dot.

If the decimal digits after the dot are zero, a '.0' is appended for clarity.

Example:

assert strconv.f64_to_str_l_with_dot (34.) == '34.0'

#fn f64_to_str_lnd1

direct_array_accessmanualfree
fn f64_to_str_lnd1(f f64, dec_digit int) string

f64_to_str_lnd1 formats a f64 to a string with dec_digit digits after the dot.

#fn f64_to_str_pad

fn f64_to_str_pad(f f64, n_digit int) string

f64_to_str returns f as a string in scientific notation with max n_digit digits after the dot.

#fn format_dec_old

manualfree
fn format_dec_old(d u64, p BF_param) string

max int64 9223372036854775807

#fn format_dec_sb

JavaScriptdirect_array_access
fn format_dec_sb(d u64, p BF_param, mut res &strings.Builder)

format_dec_sb format a u64

#fn format_dec_sb

direct_array_access
fn format_dec_sb(d u64, p BF_param, mut res &strings.Builder)

format_dec_sb formats an u64 using a strings.Builder.

#fn format_es

direct_array_accessmanualfree
fn format_es(f f64, p BF_param) string

format_es returns a f64 as a string formatted according to the options set in p.

#fn format_fl

direct_array_accessmanualfree
fn format_fl(f f64, p BF_param) string

format_fl is a strings.Builder version of format_fl.

#fn format_fl_old

direct_array_accessmanualfree
fn format_fl_old(f f64, p BF_param) string

strings.Builder version of format_fl

#fn format_int

direct_array_accessmanualfree
fn format_int(n i64, radix int) string

format_int returns the string representation of the number n in base radix for digit values > 10, this function uses the small latin leters a-z.

#fn format_str

manualfree
fn format_str(s string, p BF_param) string

format_str returns a string formatted according to the options set in p.

#fn format_str_sb

JavaScript
fn format_str_sb(s string, p BF_param, mut sb &strings.Builder)

#fn format_str_sb

fn format_str_sb(s string, p BF_param, mut sb &strings.Builder)

#fn format_uint

direct_array_accessmanualfree
fn format_uint(n u64, radix int) string

format_uint returns the string representation of the number n in base radix for digit values > 10, this function uses the small latin leters a-z.

#fn ftoa_32

inline
fn ftoa_32(f f32) string

ftoa_32 returns a string in scientific notation with max 8 digits after the dot.

Example:

assert strconv.ftoa_32(34.1234567) == '3.4123455e+01'

#fn ftoa_64

inline
fn ftoa_64(f f64) string

ftoa_64 returns a string in scientific notation with max 17 digits after the dot.

Example:

assert strconv.ftoa_64(123.1234567891011121) == '1.2312345678910111e+02'

#fn ftoa_long_32

inline
fn ftoa_long_32(f f32) string

ftoa_long_32 returns f as a string in decimal notation with a maximum of 6 digits after the dot.

Example:

assert strconv.ftoa_long_32(34.1234567) == '34.12346'

#fn ftoa_long_64

inline
fn ftoa_long_64(f f64) string

ftoa_long_64 returns f as a string in decimal notation with a maximum of 17 digits after the dot.

Example:

assert strconv.f64_to_str_l(123.1234567891011121) == '123.12345678910111'

#fn fxx_to_str_l_parse

direct_array_accessmanualfree
fn fxx_to_str_l_parse(s string) string

fxx_to_str_l_parse returns a string in decimal notation converted from a floating-point string in scientific notation.

Example:

assert strconv.fxx_to_str_l_parse('34.22e+00') == '34.22'

#fn fxx_to_str_l_parse_with_dot

direct_array_accessmanualfree
fn fxx_to_str_l_parse_with_dot(s string) string

fxx_to_str_l_parse_with_dot returns a string in decimal notation converted from a floating-point string in scientific notation.

If the decimal digits after the dot are zero, a '.0' is appended for clarity.

Example:

assert strconv.fxx_to_str_l_parse_with_dot ('34.e+01') == '340.0'

#fn parse_int

fn parse_int(_s string, base int, _bit_size int) !i64

parse_int interprets a string s in the given base (0, 2 to 36) and bit size (0 to 64) and returns the corresponding value i.

If the base argument is 0, the true base is implied by the string's prefix: 2 for "0b", 8 for "0" or "0o", 16 for "0x", and 10 otherwise.

Also, for argument base 0 only, underscore characters are permitted as defined by the Go syntax for integer literals.

The bitSize argument specifies the integer type that the result must fit into. Bit sizes 0, 8, 16, 32, and 64 correspond to int, int8, int16, int32, and int64.

If bitSize is below 0 or above 64, an error is returned.

#fn parse_uint

fn parse_uint(s string, _base int, _bit_size int) !u64

parse_uint is like parse_int but for unsigned numbers.

#fn remove_tail_zeros

direct_array_access
fn remove_tail_zeros(s string) string

remove_tail_zeros strips traling zeros from s and return the resulting string.

#fn v_sprintf

deprecated:use string interpolation insteaddeprecated_after:2023-06-30direct_array_accessmanualfree
fn v_sprintf(str string, pt []voidptr) string

v_sprintf returns a sprintf-like formated string.

Example:

 x := 3.141516
 assert strconv.v_sprintf('aaa %G', x) == 'aaa 3.141516'

Structs

#struct BF_param

pub struct BF_param {
pub mut:
	pad_ch       u8   = u8(` `) // padding char
	len0         int  = -1 // default len for whole the number or string
	len1         int  = 6 // number of decimal digits, if needed
	positive     bool = true // mandatory: the sign of the number passed
	sign_flag    bool       // flag for print sign as prefix in padding
	allign       Align_text = .right // alignment of the string
	rm_tail_zero bool       // remove the tail zeros from floats
}

#struct PrepNumber

pub struct PrepNumber {
pub mut:
	negative bool // 0 if positive number, 1 if negative
	exponent int  // power of 10 exponent
	mantissa u64  // integer mantissa
}

The structure is filled by parser, then given to converter.

#union Float64u

pub union Float64u {
pub mut:
	f f64
	u u64
}

#union Float32u

pub union Float32u {
pub mut:
	f f32
	u u32
}

Interfaces

This section is empty.

Enums

#enum Align_text

pub enum Align_text {
	right = 0
	left
	center
}