Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ArtSabintsev/Guitar

A Cross-Platform String and Regular Expression Library written in Swift.
https://github.com/ArtSabintsev/Guitar

carthage cocoapods cross-platform ios latinization macos padding regex regular-expression string-manipulation swift swift-package-manager swift-server trimming tvos watchos

Last synced: 6 days ago
JSON representation

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

Awesome Lists containing this project

README

        

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

[![Build Status](https://travis-ci.org/ArtSabintsev/Guitar.svg?branch=master)](https://travis-ci.org/ArtSabintsev/Guitar) [![Platform](https://img.shields.io/badge/Platforms-iOS%20%7c%20macOS%20%7c%20tvOS%20%7c%20watchOS%20%7c%20Linux%20-lightgray.svg?style=flat)](http://sabintsev/com/Guitar)

![Swift Support](https://img.shields.io/badge/Swift-5.3-orange.svg) [![CocoaPods](https://img.shields.io/cocoapods/v/Guitar.svg)](https://cocoapods.org/pods/Guitar) [![SwiftPM Compatible](https://img.shields.io/badge/SwiftPM-Compatible-brightgreen.svg)](https://swift.org/package-manager/)

## 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](https://swift.org/source-compatibility/#current-list-of-projects).

## Features
- [x] Boolean Functions (`isAlpha`, `isNumeric`, `isUppercase`, etc.)
- [x] Case Functions (`camelCased`, `pascalCased`, `kebabCased`, etc.)
- [x] Latinization Functions (`.latinized()`, `.withoutAccents()`)
- [x] Padding Functions (`padLeft`, `padRight`, `pad`)
- [x] Regular Expressions (with Common Patterns Built-in)

### Sherlocked

A small set of functions offered by Guitar were removed in v0.3.0 of the library as Apple added many of these features to the Swift 4 language (aka, [Sherlocking](http://www.urbandictionary.com/define.php?term=sherlocked)). The functions that were removed were: `first, last, length, prefixed, suffixed, trimLeft, trimRight, truncated`. The `reversed` function was renamed to `reversedString` as it acts slightly differently than Swift's built-in `reversed` function.

## Installation Instructions

| Swift Version | Branch Name | Will Continue to Receive Updates?
| ------------- | ------------- | -------------
| 5.1+ | master | **Yes**
| 5.0 | swift5.0 | No
| 4.2 | swift4.2 | No
| 4.1 | swift4.1 | No
| 3.2 | swift3.2 | No
| 3.1 | swift3.1 | No

### CocoaPods
```ruby
pod 'Guitar' # Swift 5.1+
pod 'Guitar', :git => 'https://github.com/ArtSabintsev/Guitar.git', :branch => 'swift5.0' # Swift 5.0
pod 'Guitar', :git => 'https://github.com/ArtSabintsev/Guitar.git', :branch => 'swift4.2' # Swift 4.2
pod 'Guitar', :git => 'https://github.com/ArtSabintsev/Guitar.git', :branch => 'swift4.1' # Swift 4.1
pod 'Guitar', :git => 'https://github.com/ArtSabintsev/Guitar.git', :branch => 'swift3.2' # Swift 3.2
pod 'Guitar', :git => 'https://github.com/ArtSabintsev/Guitar.git', :branch => 'swift3.1' # Swift 3.1
```

### Swift Package Manager
```swift
.Package(url: "https://github.com/ArtSabintsev/Guitar.git", majorVersion: 1)
```

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

```swift
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]`, that match a specific regular expression.
```swift
Guitar(chord: .firstCharacter).evaluateForRanges(from: "Hello world") // [Range(Swift.String.CharacterView.Index(_base: Swift.String.UnicodeScalarView.Index(_position: 0), _countUTF16: 1)..