Moved BindingGenerator from gen html project. It makes more sense here.

This commit is contained in:
2025-10-25 00:06:22 -04:00
parent 58a8419984
commit 603a0aa0e3
141 changed files with 12738 additions and 7 deletions

View File

@@ -0,0 +1,43 @@
//
// String+Ext.swift
// gen_html
//
// Created by Isaac Paul on 9/25/25.
//
import Foundation
extension String {
init(readFromUrl:URL) throws {
let inputHandle = try FileHandle(forReadingFrom: readFromUrl)
guard let data = try inputHandle.readToEnd() else {
throw AppError("Empty input.")
}
guard let fileStr = String(data: data, encoding: .utf8) else {
throw AppError("Unable to decode data as utf-8 string")
}
self = fileStr
}
func uppercaseFirstLetter() -> String {
guard let firstLetter = self.first else { return self }
return firstLetter.uppercased() + self.dropFirst()
}
func fixPoorCharactersForVariables() -> String {
let firstPass = self.camelCaseBy("-")
let secondPass = firstPass.replacingOccurrences(of: "/", with: "_")
return secondPass
}
func camelCaseBy(_ c: Character) -> String {
let components = self.split(separator: c)
guard let first = components.first?.lowercased() else { return "" }
let rest = components.dropFirst().map { $0.capitalized }
let camelCase = ([first] + rest).joined()
return camelCase
}
}