Seamless Roman numeral conversion in Swift

Related tags

Text Roman
Overview

Roman Banner

Platform Swift Package Manager CocoaPods Carthage MIT License

InstallationUsageLicenseDocumentation

Roman is a Swift framework that allows for seamless Roman numeral conversion.

Installation

Compatibility:

  • Platforms:
    • OS X
    • iOS
    • watchOS
    • tvOS
    • Linux
  • Language:
    • Swift 2.1+

Install Using Swift Package Manager

The Swift Package Manager is a decentralized dependency manager for Swift.

  1. Add the project to your Package.swift.

    import PackageDescription
    
    let package = Package(
        name: "MyAwesomeProject",
        dependencies: [
            .Package(url: "https://github.com/nvzqz/Roman.git",
                     majorVersion: 1)
        ]
    )
  2. Import the Roman module.

    import Roman

Install Using CocoaPods

CocoaPods is a centralized dependency manager for Objective-C and Swift. Go here to learn more.

  1. Add the project to your Podfile.

    use_frameworks!
    
    pod 'Roman', '~> 1.1.0'
  2. Run pod install and open the .xcworkspace file to launch Xcode.

  3. Import the Roman framework.

    import Roman

Install Using Carthage

Carthage is a decentralized dependency manager for Objective-C and Swift.

  1. Add the project to your Cartfile.

    github "nvzqz/Roman"
    
  2. Run carthage update and follow the additional steps in order to add Roman to your project.

  3. Import the Roman framework.

    import Roman

Install Manually

Simply add the Roman.swift file into your project.

Usage

String

A Roman numeral string can be created from an instance of a type that conforms to IntegerType.

String(roman: 1478)  // "MCDLXXVIII"
String(roman: 2743)  // "MMDCCXLIII"
String(roman: 1226)  // "MCCXXVI"
String(roman: 0)     // nil
String(roman: -42)   // nil

IntegerType

All types that conform to IntegerType can be initialized from a Roman numeral string.

The input string is case insensitive.

Int(roman: "III")  // 3
Int(roman: "MIV")  // 1004
Int(roman: "CdV")  // 405

Roman even supports irregular numerals that don't use a short form.

Each of the following evaluates to true:

Int(roman: "IV") == Int(roman: "IIII")
Int(roman: "XX") == Int(roman: "VVVV")
Int(roman: "CD") == Int(roman: "CCCC")

Invalid strings return nil.

Int(roman: "hello") == nil
Int(roman: "IIIXX") == nil
Int(roman: "XYZ")   == nil

FloatingPointType

All types that conform to FloatingPointType can be initialized from a Roman numeral string.

Creating instances from Roman numerals works the same way as with IntegerType.

License

Roman is released under the MIT License.

All assets are released under the Creative Commons Attribution-ShareAlike 4.0 International License and can be found in the Assets folder.

You might also like...
SwiftVerbalExpressions is a Swift library that helps to construct difficult regular expressions

SwiftVerbalExpressions Swift Regular Expressions made easy SwiftVerbalExpressions is a Swift library that helps to construct difficult regular express

A Swift framework for parsing, formatting and validating international phone numbers. Inspired by Google's libphonenumber.
A Swift framework for parsing, formatting and validating international phone numbers. Inspired by Google's libphonenumber.

PhoneNumberKit Swift 5.3 framework for parsing, formatting and validating international phone numbers. Inspired by Google's libphonenumber. Features F

A comprehensive, lightweight string extension for Swift

SwiftString SwiftString is a lightweight string extension for Swift. This library was motivated by having to search StackOverflow for common string op

A Swift Formatter Kit
A Swift Formatter Kit

Format A Swift formatter kit. Simple formatting syntax for decimal numbers, currency, mass, addresses, ordinal numbers and hexadecimal colors. Usage I

🌭 Mustard is a Swift library for tokenizing strings when splitting by whitespace doesn't cut it.

Mustard 🌭 Mustard is a Swift library for tokenizing strings when splitting by whitespace doesn't cut it. Quick start using character sets Foundation

Automatic summarizer text in Swift
Automatic summarizer text in Swift

Overview Reductio is a tool used to extract keywords and phrases using an implementation of the algorithm TextRank. Installation Swift Package Manager

OysterKit is a framework that provides a native Swift scanning, lexical analysis, and parsing capabilities. In addition it provides a language that can be used to rapidly define the rules used by OysterKit called STLR

OysterKit A Swift Framework for Tokenizing, Parsing, and Interpreting Languages OysterKit enables native Swift scanning, lexical analysis, and parsing

Swift markdown library
Swift markdown library

Markdown ![Swift version](https://img.shields.io/badge/Swift-2.1 | 2.2-blue.svg) ![GitHub license](https://img.shields.io/badge/license-LGPL v3-green.

Regex class for Swift. Wraps NSRegularExpression.

Regex.swift install Use CocoaPods. Add to your Podfile: pod 'Regex' And then run pod install from the shell: $ pod install usage Simple use cases: Str

Releases(v1.1.0)
Owner
Nikolai Vazquez
conducts curses, breaks things, and uses the oxford comma
Nikolai Vazquez
Croc is a swift emoji string parsing library

Croc is a library for parsing emojis on iOS. It provides a simple and lightweight interface for detecting, generating, categorizing and managing emoji characters, making emoji-powered features an easy task for developers.

Joe Kalash 127 Nov 20, 2022
Fully open source text editor for iOS written in Swift.

Edhita Fully open source text editor for iOS written in Swift. http://edhita.bornneet.com/ What Edhita means? Edhita (Romaji) == エディタ (Katakana) == Ed

Tatsuya Tobioka 1.2k Jan 1, 2023
A simple and customizable Markdown Parser for Swift

MarkdownKit MarkdownKit is a customizable and extensible Markdown parser for iOS and macOS. It supports many of the standard Markdown elements through

Bruno Oliveira 687 Dec 18, 2022
Marky Mark is a parser written in Swift that converts markdown into native views.

Marky Mark is a parser written in Swift that converts markdown into native views. The way it looks it highly customizable and the supported markdown syntax is easy to extend.

M2mobi 287 Nov 29, 2022
Swift Parser Combinators

Parsey Swift Parser Combinator Framework In addition to simple combinators, Parsey supports source location/range tracking, backtracking prevention, a

Richard Wei 56 Jun 30, 2022
Great Swift String Pluralize Extension

Pluralize.swift Great Swift String Pluralize Extension case-insensitive tons of rules for irregular nouns (plural form) supports uncountable nouns all

Joshua Arvin Lat 193 Nov 8, 2022
An NSPredicate DSL for iOS, OSX, tvOS, & watchOS. Inspired by SnapKit and lovingly written in Swift.

PrediKit A Swift NSPredicate DSL for iOS & OS X inspired by SnapKit, lovingly written in Swift, and created by that weird dude at KrakenDev. If you're

Hector Matos 542 Sep 24, 2022
PySwiftyRegex - Easily deal with Regex in Swift in a Pythonic way

PySwiftyRegex Easily deal with Regex in Swift in a Pythonic way.

Ce Zheng 232 Oct 12, 2022
Regular expressions for swift

Regex Advanced regular expressions for Swift Goals Regex library was mainly introduced to fulfill the needs of Swift Express - web application server

Crossroad Labs 328 Nov 20, 2022
👩‍🎨 Elegant Attributed String composition in Swift sauce

Elegant Attributed String composition in Swift sauce SwiftRichString is a lightweight library which allows to create and manipulate attributed strings

Daniele Margutti 2.9k Jan 5, 2023