feat(RES-34): Fix plist font filename (#14)
All checks were successful
gitea-openium/resgen.swift/pipeline/head This commit looks good

Reviewed-on: #14
This commit is contained in:
2025-05-05 09:53:05 +02:00
parent 8442c89944
commit 756de4f1de
96 changed files with 3028 additions and 2852 deletions

View File

@ -1,76 +1,74 @@
//
// TwineFileParser.swift
//
//
//
// Created by Thibaut Schmitt on 10/01/2022.
//
import Foundation
class TwineFileParser {
// swiftlint:disable function_body_length
enum TwineFileParser {
static func parse(_ inputFile: String) -> [Section] {
let inputFileContent = try! String(contentsOfFile: inputFile, encoding: .utf8)
let inputFileContent = try! String(contentsOfFile: inputFile, encoding: .utf8) // swiftlint:disable:this force_try
let stringsByLines = inputFileContent.components(separatedBy: .newlines)
var sections = [Section]()
// Parse file
stringsByLines.forEach {
stringsByLines.forEach { // swiftlint:disable:this closure_body_length
// Section
if let section = Section.match($0) {
sections.append(section)
return
}
// Definition
if let definition = Definition.match($0) {
sections.last?.definitions.append(definition)
return
}
// Definition content
if $0.isEmpty == false {
// fr = Test => ["fr ", " Test"]
let splitLine = $0
.removeLeadingTrailingWhitespace()
.split(separator: "=")
guard let lastDefinition = sections.last?.definitions.last,
let leftElement = splitLine.first else {
return
}
return
}
let rightElement: String = splitLine.dropFirst().joined(separator: "=")
// "fr " => "fr"
let leftHand = String(leftElement).removeTrailingWhitespace()
// " Test" => "Test"
let rightHand = String(rightElement).removeLeadingWhitespace()
// Handle comments, tags and translation
switch leftHand {
case "comments":
lastDefinition.comment = rightHand
case "tags":
lastDefinition.tags = rightHand
.split(separator: ",")
.map { String($0) }
case "ref":
lastDefinition.reference = rightHand
default:
lastDefinition.translations[leftHand] = rightHand.escapeDoubleQuote()
// Is a plurals strings (fr:one = Test)
// Will be handle later
//if leftHand.split(separator: ":").count > 1 {
// lastDefinition.isPlurals = true
//}
}
}
}
// Keep only valid definition
var invalidDefinitionNames = [String]()
sections.forEach { section in
@ -83,10 +81,10 @@ class TwineFileParser {
return true
}
}
if invalidDefinitionNames.count > 0 {
if invalidDefinitionNames.isEmpty == false {
print("warning: [\(Stringium.toolName)] Found \(invalidDefinitionNames.count) definition (\(invalidDefinitionNames.joined(separator: ", "))")
}
return sections
}
}