// // 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 } }