Code Monkey home page Code Monkey logo

guitar's Introduction

Guitar ๐ŸŽธ

A Cross-Platform String and Regular Expression Library written in Swift.

BuddyBuild Documentation Platform

CocoaPods Carthage Compatible SwiftPM Compatible CocoaPods CocoaPods

About

This library seeks to add common string manipulation functions, including common regular expression capabilities, that are needed in both mobile and server-side development, but are missing in Swift's Standard Library.

The full documentation can be found at http://www.sabintsev.com/Guitar/.

Guitar is also part of Swift's Source Compatibility Suite.

Features

  • Boolean Functions (isAlpha, isNumeric, isUppercase, etc.)
  • Case Functions (camelCased, pascalCased, kebabCased, etc.)
  • Character Functions (first, length, reversed, etc.)
  • Latinization Functions (.latinized(), .withoutAccents())
  • Padding Functions (padLeft, padRight, pad)
  • Regular Expressions (with Common Patterns Built-in)
  • Trimming Functions (trimLeft, trimRight, truncated, etc.)

Installation Instructions

CocoaPods

pod 'Guitar'

Carthage

github "ArtSabintsev/Guitar"

Swift Package Manager

.Package(url: "https://github.com/ArtSabintsev/Guitar.git", majorVersion: 0)

Usage Examples

Regular Expression

  • Guitar makes it easier to use Regular Expressions to test and evaluate String objects.
  • Guitar.Chord enumerates common regular expressions and they are located in GuitarChord.swift.
  • GuitarCommon.swift contains a list of convenience methods for common regular expression evaluations and tests, such as checking the string to determine if it's a valid email address.

Initialization

Guitar(pattern: String) // A custom regular expression with which to initialize Guitar.

Guitar(chord: Guitar.Chord) // A common regular expression with which to initialize Guitar.

Methods

evaluateForRanges(::) returns an array of ranges, [Range<String.Index>], that match a specific regular expression.

Guitar(chord: .firstCharacter).evaluateForRanges(from: "Hello world") // [Range(Swift.String.CharacterView.Index(_base: Swift.String.UnicodeScalarView.Index(_position: 0), _countUTF16: 1)..<Swift.String.CharacterView.Index(_base: Swift.String.UnicodeScalarView.Index(_position: 1), _countUTF16: 1)), Range(Swift.String.CharacterView.Index(_base: Swift.String.UnicodeScalarView.Index(_position: 6), _countUTF16: 1)..<Swift.String.CharacterView.Index(_base: Swift.String.UnicodeScalarView.Index(_position: 7), _countUTF16: 1))]

evaluateForStrings(::) returns an array of strings, [String], that match a specific regular expression.

Guitar(chord: .firstCharacter).evaluateForStrings(from: "Hello world") // ["H", "w"]

test(::) evaluates a string with a specific regular expression. true is returned if matches are found in the string. Otherwise, false is returned.

Guitar(chord: .email).test(string: "[email protected]") // `true`

String Extension

This library also adds dozens of methods via String extensions that are missing in the Swift Standard Library or not easily accessible on the String class. Examples of each new method can be found in the jazzy-powered documentation.

More specific examples can be found in the tests folder.

Inspiration

Created and maintained by

Arthur Ariel Sabintsev

guitar's People

Contributors

artsabintsev avatar ethanschatzline avatar

Watchers

 avatar  avatar

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.