Copyright | (c) 2018 Ondrej Palkovsky |
---|---|
License | BSD-style |
Maintainer | bos@serpentine.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | Safe-Inferred |
Language | Haskell98 |
Implementation of the Unicode Bidirectional Algorithm. See the documentation of the libicu library for additional details.
- - Note: this module is not thread safe. Do not call the functions on one BiDi object from more than one thread!
Synopsis
- data BiDi
- open :: IO BiDi
- openSized :: Int32 -> Int32 -> IO BiDi
- setPara :: BiDi -> Text -> Int32 -> IO ()
- setLine :: BiDi -> Int32 -> Int32 -> BiDi -> IO ()
- countParagraphs :: BiDi -> IO Int32
- getParagraphByIndex :: BiDi -> Int32 -> IO (Int32, Int32)
- getProcessedLength :: BiDi -> IO Int32
- writeReordered :: BiDi -> [WriteOption] -> IO Text
- data WriteOption
- reorderParagraphs :: [WriteOption] -> Text -> [Text]
Documentation
BiDi object. Note: this structure is not thread safe. It is not safe to use value of this type simultaneously from multiple threads.
Basic functions
:: Int32 | is the maximum text or line length that internal memory will be preallocated for. An attempt to associate this object with a longer text will fail, unless this value is 0. |
-> Int32 | is the maximum anticipated number of same-level runs that internal memory will be preallocated for. An attempt to access visual runs on an object that was not preallocated for as many runs as the text was actually resolved to will fail, unless this value is 0. |
-> IO BiDi |
Allocate a BiDi structure with preallocated memory for internal structures.
Set data
:: BiDi | |
-> Text | |
-> Int32 | specifies the default level for the text; it is typically 0 (LTR) or 1 (RTL) |
-> IO () |
Perform the Unicode Bidi algorithm. It is defined in the Unicode Standard Annex #9, version 13, also described in The Unicode Standard, Version 4.0. This function takes a piece of plain text containing one or more paragraphs, with or without externally specified embedding levels from styled text and computes the left-right-directionality of each character.
:: BiDi | the parent paragraph object. It must have been set by a successful call to |
-> Int32 | is the line's first index into the text |
-> Int32 | is just behind the line's last index into the text (its last index +1). |
-> BiDi | is the object that will now represent a line of the text |
-> IO () |
Sets a BiDi to contain the reordering information, especially the resolved levels, for all the characters in a line of text
Access the BiDi object
:: BiDi | |
-> Int32 | is the number of the paragraph, in the range [0..ubidi_countParagraphs(pBiDi)-1]. |
-> IO (Int32, Int32) | index of the first character of the paragraph in the text and limit of the paragraph |
Get a paragraph, given the index of this paragraph.
getProcessedLength :: BiDi -> IO Int32 Source #
Get the length of the source text processed by the last call to setPara
.
Output text
writeReordered :: BiDi -> [WriteOption] -> IO Text Source #
data WriteOption Source #
DoMirroring | replace characters with the "mirrored" property in RTL runs by their mirror-image mappings |
InsertLrmForNumeric | surround the run with LRMs if necessary; this is part of the approximate "inverse Bidi" algorithm |
KeepBaseCombining | keep combining characters after their base characters in RTL runs |
OutputReverse | write the output in reverse order |
RemoveBidiControls | remove Bidi control characters (this does not affect InsertLrmForNumeric) |
Instances
Show WriteOption Source # | |
Defined in Data.Text.ICU.BiDi showsPrec :: Int -> WriteOption -> ShowS # show :: WriteOption -> String # showList :: [WriteOption] -> ShowS # |
High-level functions
reorderParagraphs :: [WriteOption] -> Text -> [Text] Source #
Helper function to reorder a text to a series of paragraphs.