Transliterator
public class Transliterator
Stateful class that aggregates incremental input in the given scheme and provides aggregated output in the specified script through the transliterate API.
Usage:
class MyConfig: Config {
...
}
let factory = try TransliteratorFactory(config: MyConfig())
guard let schemes = try factory.availableSchemes(), let scripts = try factory.availableScripts() else {
// Deal with bad config
}
let tranliterator = try factory.tranliterator(schemeName: schemes[0], scriptName: scripts[0])
try tranliterator.transliterate("...")
-
Units that define a position within the aggregate state of the
See moreTransliteratorDeclaration
Swift
public enum PositionalUnits -
A Boolean value indicating whether the
Transliteratorstate is empty.Declaration
Swift
public func isEmpty() -> Bool -
Convert the given position from one
PositionalUnitsto another within the aggregateTransliteratorstate.Declaration
Swift
public func convertPosition(position: Int, fromUnits: PositionalUnits, toUnits: PositionalUnits) -> Int?Parameters
positionindex position within the aggregate
Transliteratorstate specified infromUnitsfromUnitsPositionalUnitsof thepositionparametertoUnitsdesired
PositionalUnitsof the returned valueReturn Value
index corrosponding to input
positionintoUnitsof the aggregate state ornilif the position is invalid -
Transliterate the aggregate input in the specified scheme to the corresponding unicode string in the specified target script.
Important
This API maintains state and aggregates inputs given to it. Callreset()to clear state between invocations if desired.Declaration
Swift
public func transliterate(_ input: String? = nil, position: Int? = nil) -> LiteratedParameters
input(optional) Additional part of input string in specified scheme
position(optional) Position in
PositionalUnits.inputwithin theTransliteratorstate at which to insertinputReturn Value
Literatedoutput for the aggregated input -
Delete the specified input character from the buffer if it exists or if unspecified, delete the last input character.
Important
the method is O(1) whenpositionis either nil or unspecified and O(n) otherwiseDeclaration
Swift
public func delete(position: Int? = nil) -> Literated?Parameters
position(optional) the position in
PositionalUnits.inputwithin theTransliteratorstate after which to delete or the last character if unspecifiedReturn Value
Literatedoutput for the remaining input ornilif there is nothing to delete
View on GitHub
Transliterator Class Reference