All Projects → Tehreer → Sheenbidi

Tehreer / Sheenbidi

Licence: apache-2.0
A sophisticated implementation of Unicode Bidirectional Algorithm

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Sheenbidi

Ustring
The Hoa\Ustring library.
Stars: ✭ 403 (+675%)
Mutual labels:  library, unicode
Harfbuzz
HarfBuzz text shaping engine
Stars: ✭ 2,206 (+4142.31%)
Mutual labels:  library, unicode
Php Confusable Homoglyphs
A PHP port of https://github.com/vhf/confusable_homoglyphs
Stars: ✭ 27 (-48.08%)
Mutual labels:  library, unicode
Contour
Modern C++ Terminal Emulator
Stars: ✭ 191 (+267.31%)
Mutual labels:  library, unicode
Slug Generator
Slug Generator Library for PHP, based on Unicode’s CLDR data
Stars: ✭ 740 (+1323.08%)
Mutual labels:  library, unicode
Idutf8lib
Idiot's UTF-8 Library
Stars: ✭ 12 (-76.92%)
Mutual labels:  library, unicode
Unicode Bidirectional
A Javascript implementation of the Unicode 9.0.0 Bidirectional Algorithm
Stars: ✭ 35 (-32.69%)
Mutual labels:  library, unicode
Libgit2
A cross-platform, linkable library implementation of Git that you can use in your application.
Stars: ✭ 8,208 (+15684.62%)
Mutual labels:  library
Lingua Franca
Mycroft's multilingual text parsing and formatting library
Stars: ✭ 51 (-1.92%)
Mutual labels:  library
Cordova App Harness
[DEPRECATED] Apache Cordova app harness
Stars: ✭ 49 (-5.77%)
Mutual labels:  library
Pnet
High level Java network library
Stars: ✭ 49 (-5.77%)
Mutual labels:  library
Kotlin Link Parser
Link preview for android
Stars: ✭ 50 (-3.85%)
Mutual labels:  library
Aiodine
🧪 Async-first Python dependency injection library
Stars: ✭ 51 (-1.92%)
Mutual labels:  library
Thirtyinch
a MVP library for Android favoring a stateful Presenter
Stars: ✭ 1,052 (+1923.08%)
Mutual labels:  library
Hadotnet
🏡 A .NET Standard library for Home Assistant.
Stars: ✭ 52 (+0%)
Mutual labels:  library
Go Tox
Go wrapper for the toxcore library - contributions welcome!
Stars: ✭ 49 (-5.77%)
Mutual labels:  library
Androidsvgloader
Android library for load svg from internet to imageview
Stars: ✭ 52 (+0%)
Mutual labels:  library
Vrac
Declarative html template library from the future. <wip>
Stars: ✭ 52 (+0%)
Mutual labels:  library
Long Shadows
Long Shadows for android!
Stars: ✭ 1,059 (+1936.54%)
Mutual labels:  library
Siler
⚡ Flat-files and plain-old PHP functions rockin'on as a set of general purpose high-level abstractions.
Stars: ✭ 1,056 (+1930.77%)
Mutual labels:  library

SheenBidi

License Travis-CI Build Status AppVeyor Build Status Coverage Status

SheenBidi implements Unicode Bidirectional Algorithm available at http://www.unicode.org/reports/tr9. It is a sophisticated implementaion which provides the developers an easy way to use UBA in their applications.

Here are some of the advantages of SheenBidi.

  • Object based.
  • Optimized to the core.
  • Designed to be thread safe.
  • Lightweight API for interaction.
  • Supports UTF-8, UTF-16 and UTF-32 encodings.

API

The above screenshot depicts a visual representation of the API on a sample text.

SBCodepointSequence

It works as a code point decoder by accepting a string buffer in specified encoding.

SBAlgorithm

It provides bidirectional type of each code unit in source string. Paragraph boundaries can be quried from it as determined by rule P1. Individual paragraph objects can be created from it by explicitly specifying the base level or deriving it from rules P2-P3.

SBParagraph

It represents a single paragraph of text processed with rules X1-I2. It provides resolved embedding levels of all the code units of a paragraph.

SBLine

It represents a single line of text processed with rules L1-L2. However, it provides reordered level runs instead of reordered characters.

SBRun

It represents a sequence of characters which have the same embedding level. The direction of a run would be right-to-left, if its embedding level is odd.

SBMirrorLocator

It provides the facility to find out the mirrored characters in a line as determined by rule L4.

SBScriptLocator

Not directly related to UBA but can be useful for text shaping. It provides the facility to find out the script runs as specified in UAX #24.

Dependency

SheenBidi does not depend on any external library. It only uses standard C library headers stddef.h, stdint.h and stdlib.h.

Configuration

The configuration options are available in Headers/SBConfig.h.

  • SB_CONFIG_LOG logs every activity performed in order to apply bidirectional algorithm.
  • SB_CONFIG_UNITY builds the library as a single module and lets the compiler make decisions to inline functions.

Compiling

SheenBidi can be compiled with any C compiler. The best way for compiling is to add all the files in an IDE and hit build. The only thing to consider however is that if SB_CONFIG_UNITY is enabled then only Source/SheenBidi.c should be compiled.

Example

Here is a simple example written in C11.

#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include <SheenBidi.h>

int main(int argc, const char * argv[]) {
    /* Create code point sequence for a sample bidirectional text. */
    const char *bidiText = "یہ ایک )car( ہے۔";
    SBCodepointSequence codepointSequence = { SBStringEncodingUTF8, (void *)bidiText, strlen(bidiText) };

    /* Extract the first bidirectional paragraph. */
    SBAlgorithmRef bidiAlgorithm = SBAlgorithmCreate(&codepointSequence);
    SBParagraphRef firstParagraph = SBAlgorithmCreateParagraph(bidiAlgorithm, 0, INT32_MAX, SBLevelDefaultLTR);
    SBUInteger paragraphLength = SBParagraphGetLength(firstParagraph);

    /* Create a line consisting of whole paragraph and get its runs. */
    SBLineRef paragraphLine = SBParagraphCreateLine(firstParagraph, 0, paragraphLength);
    SBUInteger runCount = SBLineGetRunCount(paragraphLine);
    const SBRun *runArray = SBLineGetRunsPtr(paragraphLine);

    /* Log the details of each run in the line. */
    for (SBUInteger i = 0; i < runCount; i++) {
        printf("Run Offset: %ld\n", (long)runArray[i].offset);
        printf("Run Length: %ld\n", (long)runArray[i].length);
        printf("Run Level: %ld\n\n", (long)runArray[i].level);
    }

    /* Create a mirror locator and load the line in it. */
    SBMirrorLocatorRef mirrorLocator = SBMirrorLocatorCreate();
    SBMirrorLocatorLoadLine(mirrorLocator, paragraphLine, (void *)bidiText);
    const SBMirrorAgent *mirrorAgent = SBMirrorLocatorGetAgent(mirrorLocator);

    /* Log the details of each mirror in the line. */
    while (SBMirrorLocatorMoveNext(mirrorLocator)) {
        printf("Mirror Index: %ld\n", (long)mirrorAgent->index);
        printf("Actual Code Point: %ld\n", (long)mirrorAgent->codepoint);
        printf("Mirrored Code Point: %ld\n\n", (long)mirrorAgent->mirror);
    }

    /* Release all objects. */
    SBMirrorLocatorRelease(mirrorLocator);
    SBLineRelease(paragraphLine);
    SBParagraphRelease(firstParagraph);
    SBAlgorithmRelease(bidiAlgorithm);

    return 0;
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].