#ascii-byte #byte-sequences #clucompany #atoi #convert-bytes #parse-bytes

cluatoi

解析 ASCII 字符的字节序列并将它们安全地转换为整数

9 个版本

使用旧的 Rust 2015

0.2.1 2018 年 10 月 23 日
0.2.0 2018 年 7 月 28 日
0.1.9 2018 年 5 月 14 日
0.1.8 2018 年 4 月 16 日

#1520 in 开发工具

Download history 5/week @ 2024-04-01 60/week @ 2024-07-01

60 每月下载次数

Apache-2.0

26KB
441

Atoi

Build Status Apache licensed Documentation

解析 ASCII 字符的字节序列并将它们安全地转换为整数。

功能

  1. 将 ASCII 字节序列转换为 Rust 整数原始类型。
  2. 防止数字溢出
  3. 考虑有符号和无符号原始类型的特性
  4. 发生错误时返回转移
  5. 使用 IterByteArray

使用

#1

extern crate cluatoi;
use cluatoi::Atoi;

fn main() {
    let isize = isize::atoi(b"-1245").unwrap(); 		
    //-1245isize

    let usize = usize::atoi(b"1245").unwrap();
    //1245usize

    let my_int = u64::atoi_stop(b"1245T", b'T').unwrap(); 	
    //1245u64

    let my_int = u64::atoi_iter(b"1245".iter()).unwrap(); 	
    //1245u64
}

#2

extern crate cluatoi;
use cluatoi::Atoi;

fn main() {
    let array = b"1024!18446744073709551610!-1!X";
    let mut array_iter = array.iter();


    let num_0 = u64::atoi_iter_wait_stop(&mut array_iter, b'!').unwrap(); 
    //1024u64

    let num_1 = u64::atoi_iter_wait_stop(&mut array_iter, b'!').unwrap(); 
    //18446744073709551610u64

    let num_err = usize::atoi_iter_wait_stop(&mut array_iter, b'!');
    //ERROR, ISIZE VALUE + USIZE TYPE
    //Err(ByteUnk(45))

    let end_byte = array_iter.next().unwrap();
    //X

    println!("{}!{}!{:?}!{}", num_0, num_1, num_err, end_byte);
    //1024!18446744073709551610!Err(ByteUnk(45))!88
}

俄语

解析 ascii 字符的序列和将它们安全转换为整数。

功能

  1. 将 ASCII 字节序列转换为 Rust 整数原始类型。
  2. 防止数字溢出
  3. 考虑有符号和无符号原始类型的特性
  4. 发生错误时返回转移
  5. 使用 IterByteArray

许可证

版权 2018 #UlinProject 丹尼斯·科特利亚罗夫

根据 Apache License,版本 2.0 许可

没有运行时依赖