Coder Social home page Coder Social logo

prepare / sheenbidi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tehreer/sheenbidi

0.0 1.0 0.0 2.13 MB

A sophisticated implementation of Unicode Bidirectional Algorithm

License: Apache License 2.0

C 60.59% C++ 37.57% Makefile 1.11% Objective-C 0.73%

sheenbidi's Introduction

SheenBidi

License 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.
  • Clear differentiation of public and private API.

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 <stdio.h>
#include <string.h>

#include <SheenBidi.h>

int main(int argc, const char * argv[]) {
    const char *bidiText = u8"یہ ایک )car( ہے۔";

    SBCodepointSequence sequence = { SBStringEncodingUTF8, (void *)bidiText, strlen(bidiText) };
    SBAlgorithmRef algorithm = SBAlgorithmCreate(&sequence);
    SBParagraphRef paragraph = SBAlgorithmCreateParagraph(algorithm, 0, sequence.stringLength, SBLevelDefaultLTR);
    SBLineRef line = SBParagraphCreateLine(paragraph, 0, sequence.stringLength);

    SBUInteger runCount = SBLineGetRunCount(line);
    const SBRun *runArray = SBLineGetRunsPtr(line);
    for (SBUInteger i = 0; i < runCount; i++) {
        printf("Run Level: %ld\n", (long)runArray[i].level);
        printf("Run Offset: %ld\n", (long)runArray[i].offset);
        printf("Run Length: %ld\n\n", (long)runArray[i].length);
    }

    SBMirrorLocatorRef locator = SBMirrorLocatorCreate();
    SBMirrorLocatorLoadLine(locator, line, sequence.stringBuffer);
    const SBMirrorAgentRef agent = SBMirrorLocatorGetAgent(locator);
    while (SBMirrorLocatorMoveNext(locator)) {
        printf("Mirror Location: %ld\n", (long)agent->index);
        printf("Mirror Code Point: %ld\n\n", (long)agent->mirror);
    }
    SBMirrorLocatorRelease(locator);

    SBLineRelease(line);
    SBParagraphRelease(paragraph);
    SBAlgorithmRelease(algorithm);
    
    return 0;
}

sheenbidi's People

Contributors

mta452 avatar khaledhosny avatar

Watchers

win avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.