2018-09-23 20:02:07 +08:00
|
|
|
//
|
2019-01-20 12:34:40 +01:00
|
|
|
// String+Utilities.swift
|
2018-09-23 20:02:07 +08:00
|
|
|
// passKit
|
|
|
|
|
//
|
|
|
|
|
// Created by Yishi Lin on 2018/9/23.
|
|
|
|
|
// Copyright © 2018 Bob Sun. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
2019-01-20 12:34:40 +01:00
|
|
|
extension String {
|
|
|
|
|
public var trimmed: String {
|
2018-11-13 23:53:08 +01:00
|
|
|
return trimmingCharacters(in: .whitespacesAndNewlines)
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-20 12:34:40 +01:00
|
|
|
public func stringByAddingPercentEncodingForRFC3986() -> String? {
|
2018-09-23 20:02:07 +08:00
|
|
|
let unreserved = "-._~/?"
|
|
|
|
|
var allowed = CharacterSet.alphanumerics
|
|
|
|
|
allowed.insert(charactersIn: unreserved)
|
|
|
|
|
return addingPercentEncoding(withAllowedCharacters: allowed)
|
|
|
|
|
}
|
2020-01-18 22:30:38 +01:00
|
|
|
|
|
|
|
|
public func splitByNewline() -> [String] {
|
|
|
|
|
return split(omittingEmptySubsequences: false) { $0 == "\n" || $0 == "\r\n" }.map(String.init)
|
|
|
|
|
}
|
2018-09-23 20:02:07 +08:00
|
|
|
}
|
2018-11-11 18:09:52 +01:00
|
|
|
|
|
|
|
|
extension String {
|
2019-01-20 12:15:54 +01:00
|
|
|
public static func | (left: String, right: String) -> String {
|
2018-11-11 18:09:52 +01:00
|
|
|
return right.isEmpty ? left : left + "\n" + right
|
|
|
|
|
}
|
|
|
|
|
}
|