hex/ios/HEXShared/SpokenLists.swift
Sebastian Herrlinger b00240b437 iOS: the dictation rules run in the keyboard core
TranscriptFormatter, SpokenLists, SpokenPunctuation, SpokenCleanupRules,
CleanupReconstruction, FrenchSpacing and CleanupTagger.words keep their Swift
API and call hk_dictation_* (DictationCore.swift moves the text across). The
app and the keyboard both link libhex_keyboard.a, so both paths run the same
rules. DictationStyle, the settings structs, the tagger and the pipeline stay.

Two addresses said back to back still trap, on purpose and in one place,
SpokenCleanupRules.overlappingAddresses(in:), until the owner decides what to
write there (SpokenSymbolsTrapTests documents it, skipped).

In-process parity of the oracle copies against the wrappers: 1,663,830 cases
and, with another seed, 1,813,599 (Release), no differences; 4,218 in a normal
run. HEXMobileTests: 695 tests, 0 failures.
2026-11-23 01:19:57 +01:00

54 lines
3.1 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Foundation
import HexKeyboardCore
/// Settings › Dictation › Format lists, in the shared App Group so in-keyboard dictation reads
/// it too. On by default.
nonisolated struct DictationListSettings {
static let enabledKey = "settings.dictationFormatLists"
private let defaults: UserDefaults?
init(defaults: UserDefaults? = UserDefaults(suiteName: KeyboardBridge.appGroup)) {
self.defaults = defaults
}
/// Spoken lists ("first … second …", "bullet … bullet …") and line breaks ("new line",
/// "new paragraph") are written as lines (`SpokenLists`), in English and Spanish.
var isEnabled: Bool {
get { defaults?.object(forKey: Self.enabledKey) as? Bool ?? true }
nonmutating set { defaults?.set(newValue, forKey: Self.enabledKey) }
}
}
/// Dictated lists and line breaks as lines, with string rules and no model, in English and
/// Spanish; other languages are left as they are. Runs inside a style, after its fillers and
/// before its punctuation (`TranscriptFormatter.format(_:style:language:lists:)`), so each style
/// ends the lines its own way.
///
/// - "new line", "new paragraph" (desktop's Labs › Spoken formatting words; "nueva línea",
/// "nuevo párrafo", "salto de línea") become one or two line breaks, and the commas around
/// them go. Never at the very start, after "a", "the", "my", "una", … ("a new line of shoes"),
/// or before "of", "is", "de", … .
/// - Numbered lists: "first … second …" ("1st … 2nd …", "primero … segundo …",
/// "en primer lugar …"), "number one … number two …" ("step", "item", "point", "número",
/// "paso"), or "one, … two, …" ("uno, … dos, …", "1. … 2. …") become "1. …" lines. The
/// markers count up from one, there are at least two items, none is empty, and every
/// marker starts a clause: the start, after a mark (".", ",", ";", ":", …) or a line break,
/// or after "and"/"then"/"y"/"luego" that do. A bare number needs its comma ("one, …");
/// "finally" or "lastly" ("por último") ends a list of two or more.
/// - Bullets: "bullet", "bullet point", "next bullet", "next item", "dash" ("viñeta",
/// "guion", "siguiente elemento") said at least twice become "- …" lines, as the Notes style
/// already writes bullets (a hyphen reads in every app's plain text and is what Markdown and
/// Notes take for a list). "dash" and "guion" need a clause start; "bullet" may follow any
/// word but "a", "the", "to", … ("a bullet hit the wall").
/// - Text before the first marker is its own line, given a colon unless it ends a sentence;
/// a last item ends at its first sentence, and what follows is its own line. Items start
/// with a capital and lose a trailing comma, period, "and" or "or".
///
/// The rules and their words are the keyboard core's (`hk_dictation_spoken_lists`,
/// crates/keyboard/core/src/dictation/lists.rs).
nonisolated enum SpokenLists {
static func format(_ text: String, language: String?) -> String {
DictationCore.stage(text, language: language, hk_dictation_spoken_lists)
}
}