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:
41
Sources/Strings/Model/Section.swift
Normal file
41
Sources/Strings/Model/Section.swift
Normal file
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// Section.swift
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 04/01/2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension Strings {
|
||||
class Section {
|
||||
let name: String // OnBoarding
|
||||
var definitions = [Definition]()
|
||||
|
||||
init(name: String) {
|
||||
self.name = name
|
||||
}
|
||||
|
||||
static func match(_ line: String) -> Section? {
|
||||
guard line.range(of: "\\[\\[(.*?)]]", options: .regularExpression, range: nil, locale: nil) != nil else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let sectionName = line
|
||||
.replacingOccurrences(of: ["[", "]"], with: "")
|
||||
.removeLeadingTrailingWhitespace()
|
||||
return Section(name: sectionName)
|
||||
}
|
||||
|
||||
func hasOneOrMoreMatchingTags(tags: [String]) -> Bool {
|
||||
let allTags = definitions.flatMap { $0.tags }
|
||||
|
||||
for tag in tags {
|
||||
if allTags.contains(tag) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user