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 Transliterator

    See more

    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 aggregate Transliterator state.

    Declaration

    Swift

    public func convertPosition(position: Int, fromUnits: PositionalUnits, toUnits: PositionalUnits) -> Int?

    Parameters

    position

    index position within the aggregate Transliterator state specified in fromUnits

    fromUnits

    PositionalUnits of the position parameter

    toUnits

    desired PositionalUnits of the returned value

    Return Value

    index corrosponding to input position in toUnits of the aggregate state or nil 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. Call reset() 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 the Transliterator state at which to insert input

    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) when position is either nil or unspecified and O(n) otherwise

    Declaration

    Swift

    public func delete(position: Int? = nil) -> Literated?

    Parameters

    position

    (optional) the position in PositionalUnits.input within the Transliterator state after which to delete or the last character if unspecified

    Return Value

    Literated output for the remaining input or nil if there is nothing to delete

  • Clears all transient internal state associated with previous inputs.

    Declaration

    Swift

    public func reset() -> Literated?

    Return Value

    Literated output of what was in the buffer before clearing state or nil if there is nothing to clear