/Guitar

A Cross-Platform String Library Written in Swift.

Primary LanguageSwiftMIT LicenseMIT

Guitar

A Cross-Platform String Library Written in Swift.

BuddyBuild Documentation Platform

CocoaPods Carthage Compatible SwiftPM Compatible CocoaPods CocoaPods

About

This library seeks to add common string manipulation functions that are needed in both mobile and server-side development, but are missing in Swift's Foundation library.

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

Project Status

  • Release Stage: Alpha (until Beta at v0.1.0)
  • API Statbility: Unstable (until Release at v1.0.0)

Features

  • Boolean Functions (isAlpha, isNumeric, isUppercase, etc.)
  • Case Functions (camelCased, pascalCased, kebabCased, etc.)
  • Character Functions (first, length, reverse, etc.)
  • Latinization Functions
  • HTML Manipulation Functions
  • Padding Functions (padLeft, padRight, pad)
  • Regular Expressions / Regex (Pure Swift Implementation)
  • Trimming Functions (trimLeft, trimRight, truncated, etc.)

There's a lot more work in the pipeline, but community contributions are highly encouraged.

Installation Instructions

CocoaPods

pod 'Guitar'

Carthage

github "ArtSabintsev/Guitar"

Swift Package Manager

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

Implemented Functions

Boolean Operations

isAlpha()

let string = "HelloWorld"
string.isAlpha() // True

let string = "Hell0World"
string.isAlpha() // False

isAlphanumeric()

let string = "HelloWorld"
string.isAlphanumeric() // True

let string = "Hell0World"
string.isAlphanumeric() // True

let string = "Hell0 World"
string.isAlphanumeric() // False

isCapitalized()

let string = "Hello World"
string.isCapitalized() // True

let string = "hello World"
string.isCapitalized() // False

let string = "Hello-World"
string.isCapitalized() // True

isDecapitalized()

let string = "hello World"
string.isDecapitalized() // True

let string = "Hello World"
string.isDecapitalized() // False

let string = "hello-World"
string.isDecapitalized() // True

isLowercased()

// Note, Swift treats non-alphabetical characters as Uppercased.

let string = "helloworld"
string.isLowercased() // True

let string = "hello world"
string.isLowercased() // False

let string = "hello-world"
string.isLowercased() // False

isNumeric()

let string = "73110"
string.isNumeric() // True

let string = "73110 1337"
string.isNumeric() // False

let string = "73110World"
string.isNumeric() // False

isUpppercased()

// Note, Swift treats non-alphabetical characters as Uppercased.

let string = "HELLOWORLD"
string.isUpppercased() // True

let string = "HELLO WORLD"
string.isUpppercased() // True

let string = "HELLO-W0RLD"
string.isUpppercased() // True

let string = "HeLLoW0RLD"
string.isUpppercased() // False

Case Operations

camelCased()

let string = "Hello World"
string.camelCased() // "helloWorld"

let string = "hello_world"
string.camelCased() // "helloWorld"

decapitalized()

// Implementation is currently broken.

kebabCased()

let string = "Hello World"
string.kebabCased() // "-Hello-World-"

let string = "hello_world"
string.kebabCased() // "-hello-world-"

pascalCased()

let string = "Hello World"
string.pascalCased() // "HelloWorld"

let string = "hello_world"
string.pascalCased() // "HelloWorld"

slugCased()

let string = "Hello World"
string.slugCased() // "Hello-World"

snakeCased()

let string = "Hello World"
string.snakeCased() // "Hello_World"

swapCased()

let string = "Hello World"
string.swapCased() // "hELLO wORLD"

Character Operations

first()

let string = "Hello World"
string.first() // "H"

last()

let string = "Hello World"
string.last() // "d"

length()

let string = "Hello World"
string.length() // "11"

reversed()

let string = "Hello World"
string.reversed() // "dlroW olleH"

Padding Operations

padLeft()

let string = "Hello World" // 11 Characters
string.padLeft(length: 15) // "    Hello World"

let string = "Hello World" // 11 Characters
string.padLeft(length: 15, withToken: "*") // "****Hello World"

let string = "Hello World" // 11 Characters
string.padLeft(length: 5) // Returns the original string, "Hello World"

padRight()

let string = "Hello World" // 11 Characters
string.padRight(length: 15) // "Hello World    "

let string = "Hello World" // 11 Characters
string.padRight(length: 15, withToken: "*") // "Hello World****"

let string = "Hello World" // 11 Characters
string.padRight(length: 5) // Returns the original string, "Hello World"

pad()

let string = "Hello World" // 11 Characters
string.pad(length: 15) // "  Hello World  "

let string = "Hello World" // 11 Characters
string.pad(length: 5) // Returns the original string, "Hello World"

let string = "Hello World" // 11 Characters
string.pad(length: 15, withToken: "*") // "**Hello World**"

/* Note: If the difference between the final length
 and number of characters in the original string is odd,
 the string is padded extra on the right side.
 */
let string = "Hello World" // 11 Characters
string.pad(length: 16) // "  Hello World   "

let string = "Hello World" // 11 Characters
string.pad(length: 16) // "**Hello World***"

Trimming Operations

trimLeft(byKeeping:)

let string = "Hello World"
string.trimLeft(byKeeping: 7) // "Hello W"

trimRight(byKeeping:)

let string = "Hello World"
string.trimRight(byKeeping: 7) // "o World"

trimLeft(byRemoving:)

let string = "Hello World"
string.trimLeft(byRemoving: 7) // "orld"

trimRight(byRemoving:)

let string = "Hello World"
string.trimRight(byRemoving: 7) // "Hell"

truncated()

let string = "Hello World"
string.truncated(length: 7) // "Hell..." (Appends an ellipsis, ..., to the end of the string.)

Inspiration

This project was inspired by Voca.

Created and maintained by

Arthur Ariel Sabintsev