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 moreTransliterator
Declaration
Swift
public enum PositionalUnits
-
A Boolean value indicating whether the
Transliterator
state is empty.Declaration
Swift
public func isEmpty() -> Bool
-
Convert the given position from one
PositionalUnits
to another within the aggregateTransliterator
state.Declaration
Swift
public func convertPosition(position: Int, fromUnits: PositionalUnits, toUnits: PositionalUnits) -> Int?
Parameters
position
index position within the aggregate
Transliterator
state specified infromUnits
fromUnits
PositionalUnits
of theposition
parametertoUnits
desired
PositionalUnits
of the returned valueReturn Value
index corrosponding to input
position
intoUnits
of the aggregate state ornil
if 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) -> Literated
Parameters
input
(optional) Additional part of input string in specified scheme
position
(optional) Position in
PositionalUnits.input
within theTransliterator
state at which to insertinput
Return Value
Literated
output 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) whenposition
is either nil or unspecified and O(n) otherwiseDeclaration
Swift
public func delete(position: Int? = nil) -> Literated?
Parameters
position
(optional) the position in
PositionalUnits.input
within theTransliterator
state after which to delete or the last character if unspecifiedReturn Value
Literated
output for the remaining input ornil
if there is nothing to delete