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.
|
|
|
|
|
//
|
|
|
|
|
|
2020-11-07 12:06:28 +01:00
|
|
|
public extension String {
|
|
|
|
|
var trimmed: String {
|
2020-06-28 21:25:40 +02:00
|
|
|
trimmingCharacters(in: .whitespacesAndNewlines)
|
2018-11-13 23:53:08 +01:00
|
|
|
}
|
|
|
|
|
|
2020-11-07 12:06:28 +01:00
|
|
|
func stringByAddingPercentEncodingForRFC3986() -> String? {
|
2020-11-07 13:30:38 +01:00
|
|
|
let unreserved = "-._~/"
|
2018-09-23 20:02:07 +08:00
|
|
|
var allowed = CharacterSet.alphanumerics
|
|
|
|
|
allowed.insert(charactersIn: unreserved)
|
|
|
|
|
return addingPercentEncoding(withAllowedCharacters: allowed)
|
|
|
|
|
}
|
2020-01-18 22:30:38 +01:00
|
|
|
|
2020-11-07 12:06:28 +01:00
|
|
|
func splitByNewline() -> [String] {
|
2020-06-28 21:25:40 +02:00
|
|
|
split(omittingEmptySubsequences: false) { $0 == "\n" || $0 == "\r\n" }.map(String.init)
|
2020-01-18 22:30:38 +01:00
|
|
|
}
|
2018-09-23 20:02:07 +08:00
|
|
|
}
|
2018-11-11 18:09:52 +01:00
|
|
|
|
2020-11-07 12:06:28 +01:00
|
|
|
public extension String {
|
|
|
|
|
static func | (left: String, right: String) -> String {
|
2020-06-28 21:25:40 +02:00
|
|
|
right.isEmpty ? left : left + "\n" + right
|
2018-11-11 18:09:52 +01:00
|
|
|
}
|
|
|
|
|
}
|