Introduce string extension property 'trimmed'
This commit is contained in:
parent
8573c66da2
commit
b6f94f8814
5 changed files with 18 additions and 3 deletions
|
|
@ -38,7 +38,7 @@ class CommitLogsTableViewController: UITableViewController {
|
||||||
let messageLabel = cell.contentView.viewWithTag(202) as? UILabel
|
let messageLabel = cell.contentView.viewWithTag(202) as? UILabel
|
||||||
author?.text = commits[indexPath.row].author?.name
|
author?.text = commits[indexPath.row].author?.name
|
||||||
dateLabel?.text = dateString
|
dateLabel?.text = dateString
|
||||||
messageLabel?.text = commits[indexPath.row].message?.trimmingCharacters(in: .whitespacesAndNewlines)
|
messageLabel?.text = commits[indexPath.row].message?.trimmed
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -230,7 +230,7 @@ class PasswordEditorTableViewController: UITableViewController, FillPasswordTabl
|
||||||
func insertScannedOTPFields(_ otpauth: String) {
|
func insertScannedOTPFields(_ otpauth: String) {
|
||||||
// update tableData
|
// update tableData
|
||||||
var additionsString = ""
|
var additionsString = ""
|
||||||
if let additionsPlainText = (tableData[additionsSection][0][PasswordEditorCellKey.content] as? String)?.trimmingCharacters(in: .whitespacesAndNewlines), additionsPlainText != "" {
|
if let additionsPlainText = (tableData[additionsSection][0][PasswordEditorCellKey.content] as? String)?.trimmed, additionsPlainText != "" {
|
||||||
additionsString = additionsPlainText + "\n" + otpauth
|
additionsString = additionsPlainText + "\n" + otpauth
|
||||||
} else {
|
} else {
|
||||||
additionsString = otpauth
|
additionsString = otpauth
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,11 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public extension String {
|
public extension String {
|
||||||
|
|
||||||
|
var trimmed: String {
|
||||||
|
return trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
}
|
||||||
|
|
||||||
func stringByAddingPercentEncodingForRFC3986() -> String? {
|
func stringByAddingPercentEncodingForRFC3986() -> String? {
|
||||||
let unreserved = "-._~/?"
|
let unreserved = "-._~/?"
|
||||||
var allowed = CharacterSet.alphanumerics
|
var allowed = CharacterSet.alphanumerics
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ class Parser {
|
||||||
result.append(Constants.getSeparator(breakingLines: !removingLineBreaks))
|
result.append(Constants.getSeparator(breakingLines: !removingLineBreaks))
|
||||||
i += 1
|
i += 1
|
||||||
}
|
}
|
||||||
return result.trimmingCharacters(in: .whitespacesAndNewlines)
|
return result.trimmed
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Split line from password file in to a key-value pair separted by `: `.
|
/// Split line from password file in to a key-value pair separted by `: `.
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,16 @@ import XCTest
|
||||||
|
|
||||||
class StringExtensionTest: XCTestCase {
|
class StringExtensionTest: XCTestCase {
|
||||||
|
|
||||||
|
func testTrimmed() {
|
||||||
|
[
|
||||||
|
(" ", ""),
|
||||||
|
(" \n\t\r", ""),
|
||||||
|
("\t a \n b \t c \r d \n ", "a \n b \t c \r d"),
|
||||||
|
].forEach { untrimmed, trimmed in
|
||||||
|
XCTAssertEqual(untrimmed.trimmed, trimmed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testStringByAddingPercentEncodingForRFC3986() {
|
func testStringByAddingPercentEncodingForRFC3986() {
|
||||||
[
|
[
|
||||||
("!#$&'()*+,/:;=?@[]^", "%21%23%24%26%27%28%29%2A%2B%2C/%3A%3B%3D?%40%5B%5D%5E"),
|
("!#$&'()*+,/:;=?@[]^", "%21%23%24%26%27%28%29%2A%2B%2C/%3A%3B%3D?%40%5B%5D%5E"),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue