Giter Site home page Giter Site logo

cluatoi's Introduction

Atoi

Build Status Apache licensed crates.io Documentation

Parsing the byte sequence of the ascii characters and safely converting them to integers.

Capabilities:

  1. Convert ASCII byte sequences to integer primitives Rust.
  2. Protection against overflow of numbers
  3. Accounting for the features of signed, unsigned primitives
  4. Return of the transfer in case of an error
  5. Using IterByteArray

Use:

#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
}

Russian:

Разбор байтовой последовательности символов ascii и безопасное преобразование их в целые числа.

Возможности:

  1. Преобразование ASCII byte последовательности в целочисленные примитивы Rust.
  2. Защита предотвращяющяя переполнения чисел
  3. Учет особенностей signed, unsigned примитивов
  4. Возврат перечисления в случае ошибки
  5. Использование IterByteArray

License

Copyright 2018 #UlinProject Денис Котляров

Licensed under the Apache License, Version 2.0

cluatoi's People

Contributors

denisandroid avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

cluatoi's Issues

Specifying offset and size

atoi_end does not allow you to specify the offset size, which limits the scope
New API Example:

fn main() {

	let array_end = b"xza1245ssfsadfasdasd";

	let my_int = u64::atoi_end(array_end, 3u16, 4u16).unwrap(); //1245u64

}

Using cluAtoi to convert 16-digit numbers

I suggest adding conversion support for 16-digit numbers.
API Example:

extern crate cluatoi;
use cluatoi::Atoi;

fn main() {

	let array = b"-0xFF";
	let isize = isize::atoi16(array).unwrap(); //  255isize

	let usize = usize::atoi16(array).unwrap();  //  AtoiErr(ByteUnk(b'-'))

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.