Generation des strings sans twine et generation des tags. Refactor de toutes les commandes strings (Twine, CustomStrings, Tags) dans une commande avec des sous commandes

This commit is contained in:
2022-01-10 12:01:09 +01:00
parent 4973b245ad
commit b0900c10cd
39 changed files with 1519 additions and 40 deletions

View File

@ -0,0 +1,15 @@
//
// SequenceExtension.swift
//
//
// Created by Thibaut Schmitt on 04/01/2022.
//
import Foundation
public extension Sequence where Iterator.Element: Hashable {
func unique() -> [Iterator.Element] {
var seen: [Iterator.Element: Bool] = [:]
return self.filter { seen.updateValue(true, forKey: $0) == nil }
}
}

View File

@ -1,5 +1,5 @@
//
// File.swift
// Shell.swift
//
//
// Created by Thibaut Schmitt on 22/12/2021.

View File

@ -7,8 +7,6 @@
import Foundation
// MARK: - String
public extension String {
func removeCharacters(from forbiddenChars: CharacterSet) -> String {
let passed = self.unicodeScalars.filter { !forbiddenChars.contains($0) }
@ -19,7 +17,15 @@ public extension String {
return removeCharacters(from: CharacterSet(charactersIn: from))
}
func removeTrailingWhitespace() -> String {
func replacingOccurrences(of: [String], with: String) -> Self {
var tmp = self
for e in of {
tmp = tmp.replacingOccurrences(of: e, with: with)
}
return tmp
}
func removeTrailingWhitespace() -> Self {
var newString = self
while newString.last?.isWhitespace == true {
@ -29,6 +35,33 @@ public extension String {
return newString
}
func removeLeadingWhitespace() -> Self {
var newString = self
while newString.first?.isWhitespace == true {
newString = String(newString.dropFirst())
}
return newString
}
func removeLeadingTrailingWhitespace() -> Self {
var newString = self
newString = newString.removeLeadingWhitespace()
newString = newString.removeTrailingWhitespace()
return newString
}
func escapeDoubleQuote() -> Self {
replacingOccurrences(of: "\"", with: "\\\"")
}
func replaceTiltWithHomeDirectoryPath() -> Self {
replacingOccurrences(of: "~", with: "\(FileManager.default.homeDirectoryForCurrentUser.relativePath)")
}
func colorComponent() -> (alpha: String, red: String, green: String, blue: String) {
var alpha: String = "FF"
var red: String
@ -52,13 +85,3 @@ public extension String {
return (alpha: alpha, red: red, green: green, blue: blue)
}
}
// MARK: - Sequence
extension Sequence where Iterator.Element: Hashable {
public func unique() -> [Iterator.Element] {
var seen: [Iterator.Element: Bool] = [:]
return self.filter { seen.updateValue(true, forKey: $0) == nil }
}
}