Make things public

This commit is contained in:
Shadowfacts 2023-11-25 22:58:00 -05:00
parent 97ce18d056
commit e22f778f8f
3 changed files with 47 additions and 31 deletions

View File

@ -11,7 +11,7 @@ import UIKit
import AppKit import AppKit
#endif #endif
struct AttributedStringConverter<Callbacks: AttributedStringCallbacks> { public struct AttributedStringConverter<Callbacks: AttributedStringCallbacks> {
private let configuration: AttributedStringConverterConfiguration private let configuration: AttributedStringConverterConfiguration
private var tokenizer: Tokenizer<String.Iterator> private var tokenizer: Tokenizer<String.Iterator>
private let str = NSMutableAttributedString() private let str = NSMutableAttributedString()
@ -21,16 +21,16 @@ struct AttributedStringConverter<Callbacks: AttributedStringCallbacks> {
// The current run of text w/o styles changing // The current run of text w/o styles changing
private var currentRun: String = "" private var currentRun: String = ""
init(html: String, configuration: AttributedStringConverterConfiguration) where Callbacks == DefaultCallbacks { public init(html: String, configuration: AttributedStringConverterConfiguration) where Callbacks == DefaultCallbacks {
self.init(html: html, configuration: configuration, callbacks: DefaultCallbacks.self) self.init(html: html, configuration: configuration, callbacks: DefaultCallbacks.self)
} }
init(html: String, configuration: AttributedStringConverterConfiguration, callbacks _: Callbacks.Type = Callbacks.self) { public init(html: String, configuration: AttributedStringConverterConfiguration, callbacks _: Callbacks.Type = Callbacks.self) {
self.configuration = configuration self.configuration = configuration
self.tokenizer = Tokenizer(chars: html.makeIterator()) self.tokenizer = Tokenizer(chars: html.makeIterator())
} }
mutating func convert() -> NSAttributedString { public mutating func convert() -> NSAttributedString {
while let token = tokenizer.next() { while let token = tokenizer.next() {
switch token { switch token {
case .character(let c): case .character(let c):
@ -265,12 +265,12 @@ struct AttributedStringConverter<Callbacks: AttributedStringCallbacks> {
} }
} }
protocol AttributedStringCallbacks { public protocol AttributedStringCallbacks {
static func makeURL(string: String) -> URL? static func makeURL(string: String) -> URL?
static func elementAction(name: String, attributes: InlineArray3<Attribute>) -> ElementAction static func elementAction(name: String, attributes: InlineArray3<Attribute>) -> ElementAction
} }
enum ElementAction: Equatable { public enum ElementAction: Equatable {
case `default` case `default`
case skip case skip
case replace(String) case replace(String)
@ -284,7 +284,7 @@ enum ElementAction: Equatable {
} }
} }
extension AttributedStringCallbacks { public extension AttributedStringCallbacks {
static func makeURL(string: String) -> URL? { static func makeURL(string: String) -> URL? {
URL(string: string) URL(string: string)
} }
@ -293,20 +293,36 @@ extension AttributedStringCallbacks {
} }
} }
struct DefaultCallbacks: AttributedStringCallbacks { public struct DefaultCallbacks: AttributedStringCallbacks {
} }
struct AttributedStringConverterConfiguration { public struct AttributedStringConverterConfiguration {
#if os(iOS) #if os(iOS)
var font: UIFont public var font: UIFont
var monospaceFont: UIFont public var monospaceFont: UIFont
var color: UIColor public var color: UIColor
#elseif os(macOS) #elseif os(macOS)
var font: NSFont public var font: NSFont
var monospaceFont: NSFont public var monospaceFont: NSFont
var color: NSColor public var color: NSColor
#endif
public var paragraphStyle: NSParagraphStyle
#if os(iOS)
public init(font: UIFont, monospaceFont: UIFont, color: UIColor, paragraphStyle: NSParagraphStyle) {
self.font = font
self.monospaceFont = monospaceFont
self.color = color
self.paragraphStyle = paragraphStyle
}
#elseif os(macOS)
public init(font: NSFont, monospaceFont: NSFont, color: NSColor, paragraphStyle: NSParagraphStyle) {
self.font = font
self.monospaceFont = monospaceFont
self.color = color
self.paragraphStyle = paragraphStyle
}
#endif #endif
var paragraphStyle: NSParagraphStyle
} }
#if os(macOS) #if os(macOS)
@ -372,7 +388,7 @@ private enum Style {
} }
extension Collection where Element == Attribute { extension Collection where Element == Attribute {
func attributeValue(for name: String) -> String? { public func attributeValue(for name: String) -> String? {
first(where: { $0.name == name })?.value first(where: { $0.name == name })?.value
} }
} }

View File

@ -12,10 +12,10 @@ import Foundation
/// If the array grows beyond 3 elements, it will be stored out-of-line. /// If the array grows beyond 3 elements, it will be stored out-of-line.
/// Once that happens, the array will never return to being stored inline, /// Once that happens, the array will never return to being stored inline,
/// since the allocation cost has already been paid. /// since the allocation cost has already been paid.
struct InlineArray3<E> { public struct InlineArray3<E> {
private var storage: Storage private var storage: Storage
init() { public init() {
self.storage = .inline(nil, nil, nil) self.storage = .inline(nil, nil, nil)
} }
} }
@ -28,7 +28,7 @@ extension InlineArray3 {
} }
extension InlineArray3: ExpressibleByArrayLiteral { extension InlineArray3: ExpressibleByArrayLiteral {
init(arrayLiteral elements: Element...) { public init(arrayLiteral elements: Element...) {
switch elements.count { switch elements.count {
case 0: case 0:
self.storage = .inline(nil, nil, nil) self.storage = .inline(nil, nil, nil)
@ -45,11 +45,11 @@ extension InlineArray3: ExpressibleByArrayLiteral {
} }
extension InlineArray3: MutableCollection { extension InlineArray3: MutableCollection {
typealias Element = E public typealias Element = E
typealias Index = Int public typealias Index = Int
typealias Indices = Range<Int> public typealias Indices = Range<Int>
subscript(position: Int) -> Element { public subscript(position: Int) -> Element {
_read { _read {
precondition(position < endIndex) precondition(position < endIndex)
switch storage { switch storage {
@ -94,11 +94,11 @@ extension InlineArray3: MutableCollection {
} }
} }
var startIndex: Int { public var startIndex: Int {
0 0
} }
var endIndex: Int { public var endIndex: Int {
switch storage { switch storage {
case .inline(let a, let b, let c): case .inline(let a, let b, let c):
a == nil ? 0 : b == nil ? 1 : c == nil ? 2 : 3 a == nil ? 0 : b == nil ? 1 : c == nil ? 2 : 3
@ -115,7 +115,7 @@ extension InlineArray3: RandomAccessCollection {
} }
extension InlineArray3: RangeReplaceableCollection { extension InlineArray3: RangeReplaceableCollection {
mutating func replaceSubrange<C>(_ subrange: Range<Int>, with newElements: C) where C: Collection, Element == C.Element { public mutating func replaceSubrange<C>(_ subrange: Range<Int>, with newElements: C) where C: Collection, Element == C.Element {
switch storage { switch storage {
case .array(var arr): case .array(var arr):
arr.replaceSubrange(subrange, with: newElements) arr.replaceSubrange(subrange, with: newElements)
@ -201,7 +201,7 @@ extension InlineArray3: Equatable where E: Equatable {
} }
extension InlineArray3: CustomStringConvertible { extension InlineArray3: CustomStringConvertible {
var description: String { public var description: String {
switch storage { switch storage {
case .inline(nil, nil, nil): case .inline(nil, nil, nil):
return "[]" return "[]"

View File

@ -200,9 +200,9 @@ enum Token: Equatable {
case doctype(String, forceQuirks: Bool, publicIdentifier: String?, systemIdentifier: String?) case doctype(String, forceQuirks: Bool, publicIdentifier: String?, systemIdentifier: String?)
} }
struct Attribute: Equatable { public struct Attribute: Equatable {
var name: String public var name: String
var value: String public var value: String
} }
private enum State { private enum State {