feat(RES-34): Fix plist font filename (#14)
All checks were successful
gitea-openium/resgen.swift/pipeline/head This commit looks good
All checks were successful
gitea-openium/resgen.swift/pipeline/head This commit looks good
Reviewed-on: #14
This commit is contained in:
@ -1,83 +1,88 @@
|
||||
//
|
||||
// Extensions.swift
|
||||
//
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 13/12/2021.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public extension String {
|
||||
func removeCharacters(from forbiddenChars: CharacterSet) -> String {
|
||||
extension String {
|
||||
|
||||
public func removeCharacters(from forbiddenChars: CharacterSet) -> String {
|
||||
let passed = self.unicodeScalars.filter { !forbiddenChars.contains($0) }
|
||||
return String(String.UnicodeScalarView(passed))
|
||||
}
|
||||
|
||||
func removeCharacters(from: String) -> String {
|
||||
return removeCharacters(from: CharacterSet(charactersIn: from))
|
||||
|
||||
public func removeCharacters(from: String) -> String {
|
||||
removeCharacters(from: CharacterSet(charactersIn: from))
|
||||
}
|
||||
|
||||
func replacingOccurrences(of: [String], with: String) -> Self {
|
||||
|
||||
public func replacingOccurrences(of: [String], with: String) -> Self {
|
||||
var tmp = self
|
||||
for e in of {
|
||||
tmp = tmp.replacingOccurrences(of: e, with: with)
|
||||
for ofValue in of {
|
||||
tmp = tmp.replacingOccurrences(of: ofValue, with: with)
|
||||
}
|
||||
return tmp
|
||||
}
|
||||
|
||||
func removeTrailingWhitespace() -> Self {
|
||||
|
||||
public func removeTrailingWhitespace() -> Self {
|
||||
var newString = self
|
||||
|
||||
|
||||
while newString.last?.isWhitespace == true {
|
||||
newString = String(newString.dropLast())
|
||||
}
|
||||
|
||||
|
||||
return newString
|
||||
}
|
||||
|
||||
func removeLeadingWhitespace() -> Self {
|
||||
|
||||
public func removeLeadingWhitespace() -> Self {
|
||||
var newString = self
|
||||
|
||||
|
||||
while newString.first?.isWhitespace == true {
|
||||
newString = String(newString.dropFirst())
|
||||
}
|
||||
|
||||
|
||||
return newString
|
||||
}
|
||||
|
||||
func removeLeadingTrailingWhitespace() -> Self {
|
||||
|
||||
public func removeLeadingTrailingWhitespace() -> Self {
|
||||
var newString = self
|
||||
|
||||
|
||||
newString = newString.removeLeadingWhitespace()
|
||||
newString = newString.removeTrailingWhitespace()
|
||||
|
||||
|
||||
return newString
|
||||
}
|
||||
|
||||
func escapeDoubleQuote() -> Self {
|
||||
|
||||
public func escapeDoubleQuote() -> Self {
|
||||
replacingOccurrences(of: "\"", with: "\\\"")
|
||||
}
|
||||
|
||||
func replaceTiltWithHomeDirectoryPath() -> Self {
|
||||
|
||||
public func replaceTiltWithHomeDirectoryPath() -> Self {
|
||||
// See NSString.expandingTildeInPath
|
||||
#if os(macOS)
|
||||
replacingOccurrences(of: "~", with: "\(FileManager.default.homeDirectoryForCurrentUser.relativePath)")
|
||||
#else
|
||||
fatalError("This command should run on Mac only")
|
||||
#endif
|
||||
}
|
||||
|
||||
func colorComponent() -> (alpha: String, red: String, green: String, blue: String) {
|
||||
|
||||
public func colorComponent() -> (alpha: String, red: String, green: String, blue: String) { // swiftlint:disable:this large_tuple
|
||||
var alpha: String = "FF"
|
||||
var red: String
|
||||
var green: String
|
||||
var blue: String
|
||||
|
||||
var colorClean = self
|
||||
.replacingOccurrences(of: "#", with: "")
|
||||
.replacingOccurrences(of: "0x", with: "")
|
||||
.replacingOccurrences(of: "#", with: "")
|
||||
.replacingOccurrences(of: "0x", with: "")
|
||||
|
||||
if colorClean.count == 8 {
|
||||
alpha = String(colorClean.prefix(2))
|
||||
colorClean = String(colorClean.dropFirst(2))
|
||||
}
|
||||
|
||||
|
||||
red = String(colorClean.prefix(2))
|
||||
colorClean = String(colorClean.dropFirst(2))
|
||||
green = String(colorClean.prefix(2))
|
||||
@ -85,12 +90,12 @@ public extension String {
|
||||
blue = String(colorClean.prefix(2))
|
||||
return (alpha: alpha, red: red, green: green, blue: blue)
|
||||
}
|
||||
|
||||
func uppercasedFirst() -> String {
|
||||
|
||||
public func uppercasedFirst() -> String {
|
||||
prefix(1).uppercased() + dropFirst()
|
||||
}
|
||||
|
||||
func replacingFirstOccurrence(of: String, with: String) -> Self {
|
||||
public func replacingFirstOccurrence(of: String, with: String) -> Self {
|
||||
if let range = self.range(of: of) {
|
||||
let tmp = self.replacingOccurrences(
|
||||
of: of,
|
||||
|
Reference in New Issue
Block a user