-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #275 from Raizlabs/feature/26-string-transforms
String transforms
- Loading branch information
Showing
9 changed files
with
362 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// Transform.swift | ||
// BonMot | ||
// | ||
// Created by Zev Eisenberg on 3/24/17. | ||
// Copyright © 2017 Raizlabs. All rights reserved. | ||
// | ||
|
||
#if os(OSX) | ||
import AppKit | ||
#else | ||
import UIKit | ||
#endif | ||
|
||
public enum Transform { | ||
|
||
public typealias TransformFunction = (String) -> String | ||
|
||
case lowercase | ||
case uppercase | ||
case capitalized | ||
|
||
case lowercaseWithLocale(Locale) | ||
case uppercaseWithLocale(Locale) | ||
case capitalizedWithLocale(Locale) | ||
case custom(TransformFunction) | ||
|
||
var transformer: TransformFunction { | ||
switch self { | ||
case .lowercase: return { string in string.localizedLowercase } | ||
case .uppercase: return { string in string.localizedUppercase } | ||
case .capitalized: return { string in string.localizedCapitalized } | ||
|
||
case .lowercaseWithLocale(let locale): return { string in string.lowercased(with: locale) } | ||
case .uppercaseWithLocale(let locale): return { string in string.uppercased(with: locale) } | ||
case .capitalizedWithLocale(let locale): return { string in string.capitalized(with: locale) } | ||
|
||
case .custom(let transform): return transform | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.