Coder Social home page Coder Social logo

xvii's Introduction

XVII

Crates.io documentation (docs.rs) Build Status

...Pronounced any way you like, including "seventeen."

This library provides parsing and formatting for Roman numerals. According to my (probably extremely suspect) benchmarks, this is the best-performing library of its kind available on crates.io (you know, as of St. Patrick's Day, 2017 when I did the tests), so you should definitely employ it in your high-availability NAAS (numerals-as-a-service) project.

(Seriously, though, read the license--no warranties implied!)

Also, if you have a high-availability NAAS project, you need to have your head examined. I don't know if that was clear when I originally wrote this readme, so I'm adding it now.

Usage

Parsing

Parsing is provided through Rust's ordinary FromStr trait, meaning you can create Roman values same as you create any other number--albeit with slightly simpler error cases, since the only possible errors are "Hey, that letter can't go in there," or "Dude, they go from 1 to 4999 and that's it!"

let seventeen: Roman = "XVII".parse().unwrap();

Formatting

There are several formatting options. Roman implements Display, which means that it'll work fine with println!("{}") et al., but for maximum efficiency (stop laughing!) I also provide two other functions: to_lowercase() and to_uppercase(). These skip the Display piping and just go straight into a new string. Lastly, the format() method builds a lazy formatter in either upper or lowercase mode.

Changelog

  • v0.4.1 Upgrade to rust edition 2018, support for no-std usage (thanks to WaffleLapkin!), plenty of cleanup (also thanks to him, really).
  • v0.2.2 Upgrade parsing to use some kind of whacky state machine in order to permit numbers up to the commonly accepted ceiling of 4999, or MMMMCMXCIX, thereby avoiding a potential Y4K bug. Your thousand year reich is now safe with me.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

xvii's People

Contributors

archer884 avatar wafflelapkin avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

xvii's Issues

`no_std` support?

It seems like xvii can work in no_std context too - the only methods that require std are to_{uppercase,lowercase} (and there can be replacement that uses fmt::Display instead of converting to string)

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.