This commit is contained in:
Михаил Капелько committed 2026-10-16 14:00:38 +03:00
1 parent ad4fb381ee
commit 73fbba0d57
15 files changed
+147 -1

No files matched your search

+70
View File
@@ -0,0 +1,70 @@
import Foundation
/// Decode a base64 string back into a regular string
func otherBase64ToString(_ encoded: String) -> String {
guard
let data = Data(base64Encoded: encoded),
let str = String(data: data, encoding: .utf8)
else {
return ""
}
return str
}
/// Capitalize the first letter of a string
func otherCapitalize(_ s: String) -> String {
guard let first = s.first else {
return s
}
return String(first).uppercased() + String(s.dropFirst())
}
/// Launch to wait for asynchrnous actions
func otherLaunch() {
RunLoop.current.run()
}
/// Count leading spaces in a line
func otherLineIndent(_ line: String) -> Int {
var count = 0
for ch in line {
if ch == " " {
count += 1
} else {
break
}
}
return count
}
/// Print to stderr
func otherPrintStderr(_ txt: String) {
if let dat = "\(txt)\n".data(using: .utf8) {
FileHandle.standardError.write(dat)
}
}
/// Print each key/value processed by a controller into stderr
func otherSetupConsoleLogging(
_ ctrl: DialectController,
_ prefix: String
) {
ctrl.registerCallback { c -> Void in
let value = c.fieldAny(c.recentField)
let line = "ИГР \(prefix) k/v: '\(c.recentField)'/'\(value)'"
otherPrintStderr(line)
}
}
/// Write output text to a file
func otherWriteFile(
_ path: String,
_ content: String
) {
try? content.write(toFile: path, atomically: true, encoding: .utf8)
}
/// Terminate the main RunLoop
func otherShutdown() {
exit(0)
}