{"id":15047976,"url":"https://github.com/tehreer/sheenbidi","last_synced_at":"2026-01-24T22:29:23.129Z","repository":{"id":23240254,"uuid":"26597967","full_name":"Tehreer/SheenBidi","owner":"Tehreer","description":"A sophisticated implementation of Unicode Bidirectional Algorithm","archived":false,"fork":false,"pushed_at":"2025-02-21T05:15:24.000Z","size":5505,"stargazers_count":138,"open_issues_count":8,"forks_count":24,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-05T00:08:31.233Z","etag":null,"topics":["ansi-c","bidi","c","c-plus-plus","c89","i18n","internationalization","library","script","text","uax-24","uax-9","uba","unicode","unicode-bidirectional-algorithm","writing"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tehreer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-11-13T16:57:28.000Z","updated_at":"2025-03-21T16:10:10.000Z","dependencies_parsed_at":"2024-01-06T00:44:56.547Z","dependency_job_id":"e247c8c9-490c-4b18-b50d-777807ccc369","html_url":"https://github.com/Tehreer/SheenBidi","commit_stats":null,"previous_names":["mta452/sheenbidi"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tehreer%2FSheenBidi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tehreer%2FSheenBidi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tehreer%2FSheenBidi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tehreer%2FSheenBidi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tehreer","download_url":"https://codeload.github.com/Tehreer/SheenBidi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247266564,"owners_count":20910836,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansi-c","bidi","c","c-plus-plus","c89","i18n","internationalization","library","script","text","uax-24","uax-9","uba","unicode","unicode-bidirectional-algorithm","writing"],"created_at":"2024-09-24T21:06:25.344Z","updated_at":"2026-01-24T22:29:23.123Z","avatar_url":"https://github.com/Tehreer.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SheenBidi\n\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n[![Linux CI](https://github.com/Tehreer/SheenBidi/actions/workflows/linux.yml/badge.svg)](https://github.com/Tehreer/SheenBidi/actions/workflows/linux.yml)\n[![macOS CI](https://github.com/Tehreer/SheenBidi/actions/workflows/macos.yml/badge.svg)](https://github.com/Tehreer/SheenBidi/actions/workflows/macos.yml)\n[![Windows CI](https://github.com/Tehreer/SheenBidi/actions/workflows/windows.yml/badge.svg)](https://github.com/Tehreer/SheenBidi/actions/workflows/windows.yml)\n[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/k2vvegcdqsb9ld5a?svg=true)](https://ci.appveyor.com/project/mta452/sheenbidi)\n[![Coverage Status](https://coveralls.io/repos/github/Tehreer/SheenBidi/badge.svg?branch=master)](https://coveralls.io/github/Tehreer/SheenBidi)\n\nSheenBidi is a lightweight, fast and stable implementation of the [Unicode Bidirectional Algorithm (UBA)](https://unicode.org/reports/tr9/).\n\nIt is being used by multiple open source and commercial projects in different domains such as:\n- **Game Engine:**\n  [Defold](https://github.com/defold/defold)\n- **Games:**\n  [Watch Dogs: Legion](https://www.mobygames.com/game/152206/watch-dogs-legion/),\n  [SuperTuxKart](https://github.com/supertuxkart/stk-code),\n  [VVVVVV](https://github.com/TerryCavanagh/VVVVVV),\n  [DevilutionX](https://github.com/diasurgical/DevilutionX),\n  [Monaco 2](https://www.mobygames.com/game/240348/monaco-2/)\n- **Multimedia:**\n  [SFML](https://github.com/SFML/SFML),\n  [JUCE](https://github.com/juce-framework/JUCE),\n  [Tracktion Engine](https://github.com/Tracktion/tracktion_engine),\n  [Rive Runtime](https://github.com/rive-app/rive-runtime)\n- **Text:**\n  [Raqm](https://github.com/HOST-Oman/libraqm),\n  [Tehreer Android](https://github.com/Tehreer/Tehreer-Android),\n  [Tehreer Cocoa](https://github.com/Tehreer/Tehreer-Cocoa)\n- **Mapping:**\n  [VTS Browser](https://github.com/melowntech/vts-browser-cpp)\n- **Web:**\n  [Dropflow](https://github.com/chearon/dropflow),\n  [Itemizer](https://github.com/chearon/itemizer)\n\n*If you use SheenBidi in your project, I’d love to hear about it!*\n\n## Features\n- **Object Based Design:** Facilitates modular and maintainable code.\n- **Core Level Optimization:** Ensures high performance.\n- **Thread Safe Architecture:** Suitable for multithreaded applications.\n- **Lightweight API:** Simplifies integration.\n- **Encoding Support:** UTF-8, UTF-16, and UTF-32.\n\n## API Overview\n\u003cimg src=\"https://user-images.githubusercontent.com/2664112/39663208-716af1c4-5088-11e8-855c-ababe3e58c58.png\" width=\"350\"\u003e\n\nThe above diagram provides a visual representation of the API applied to sample text.\n\n### SBCodepointSequence\nDecodes a string buffer in a specified encoding into code points.\n\n### SBAlgorithm\nDetermines the bidirectional type of each code unit in the source string. It identifies paragraph boundaries as per rule [P1](https://www.unicode.org/reports/tr9/#P1) and allows creation of paragraph objects with explicit base levels or derived from rules [P2](https://www.unicode.org/reports/tr9/#P2)-[P3](https://www.unicode.org/reports/tr9/#P3).\n\n### SBParagraph\nRepresents a single paragraph processed with rules [X1](https://www.unicode.org/reports/tr9/#X1)-[I2](https://www.unicode.org/reports/tr9/#I2), providing resolved embedding levels for all code units.\n\n### SBLine\nRepresents a line of text processed with rules [L1](https://www.unicode.org/reports/tr9/#L1)-[L2](https://www.unicode.org/reports/tr9/#L2), offering reordered level runs instead of individual characters.\n\n### SBRun\nDenotes a sequence of characters sharing the same embedding level. A run's direction is right-to-left if its embedding level is odd.\n\n### SBMirrorLocator\nIdentifies mirrored characters in a line as determined by rule [L4](https://www.unicode.org/reports/tr9/#L4).\n\n### SBScriptLocator\nAssists in text shaping by locating script runs as specified in [UAX #24](https://www.unicode.org/reports/tr24/).\n\n## Dependency\nSheenBidi relies solely on standard C library headers: `stddef.h`, `stdint.h`, `stdlib.h`, and `string.h`.\n\n## Compiling\nSheenBidi can be compiled with any C compiler.\n\n### CMake\nTo build and install SheenBidi using CMake:\n\n```bash\ncmake -S. -Bbuild-release -DCMAKE_BUILD_TYPE=Release\ncmake --build build-release\nsudo cmake --install build-release\n```\n\nFor development and testing:\n\n```bash\ncmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Debug -DSB_CONFIG_UNITY=OFF\ncmake --build build\nctest --test-dir build --output-on-failure\n```\n\nIn other CMake projects, SheenBidi can be found via `find_package(SheenBidi)`, providing the target `SheenBidi::SheenBidi`. SheenBidi can also be used via `FetchContent`.\n\n### Meson\nTo build and install SheenBidi using Meson:\n\n```bash\nmeson setup builddir --buildtype=release\nmeson compile -C builddir\nsudo meson install -C builddir\n```\n\nFor testing:\n\n```bash\nmeson setup builddir -Dunity_mode=disabled\nmeson test -C builddir --print-errorlogs\n```\n\n## Example\nA simple example in C11.\n\n```c\n#include \u003cstdint.h\u003e\n#include \u003cstdio.h\u003e\n#include \u003cstring.h\u003e\n\n#include \u003cSheenBidi/SheenBidi.h\u003e\n\nint main(int argc, const char * argv[]) {\n    /* Create code point sequence for a sample bidirectional text. */\n    const char *bidiText = \"یہ ایک )car( ہے۔\";\n    SBCodepointSequence codepointSequence = { SBStringEncodingUTF8, (void *)bidiText, strlen(bidiText) };\n\n    /* Extract the first bidirectional paragraph. */\n    SBAlgorithmRef bidiAlgorithm = SBAlgorithmCreate(\u0026codepointSequence);\n    SBParagraphRef firstParagraph = SBAlgorithmCreateParagraph(bidiAlgorithm, 0, INT32_MAX, SBLevelDefaultLTR);\n    SBUInteger paragraphLength = SBParagraphGetLength(firstParagraph);\n\n    /* Create a line consisting of the whole paragraph and get its runs. */\n    SBLineRef paragraphLine = SBParagraphCreateLine(firstParagraph, 0, paragraphLength);\n    SBUInteger runCount = SBLineGetRunCount(paragraphLine);\n    const SBRun *runArray = SBLineGetRunsPtr(paragraphLine);\n\n    /* Log the details of each run in the line. */\n    for (SBUInteger i = 0; i \u003c runCount; i++) {\n        printf(\"Run Offset: %ld\\n\", (long)runArray[i].offset);\n        printf(\"Run Length: %ld\\n\", (long)runArray[i].length);\n        printf(\"Run Level: %ld\\n\\n\", (long)runArray[i].level);\n    }\n\n    /* Create a mirror locator and load the line in it. */\n    SBMirrorLocatorRef mirrorLocator = SBMirrorLocatorCreate();\n    SBMirrorLocatorLoadLine(mirrorLocator, paragraphLine, (void *)bidiText);\n    const SBMirrorAgent *mirrorAgent = SBMirrorLocatorGetAgent(mirrorLocator);\n\n    /* Log the details of each mirror in the line. */\n    while (SBMirrorLocatorMoveNext(mirrorLocator)) {\n        printf(\"Mirror Index: %ld\\n\", (long)mirrorAgent-\u003eindex);\n        printf(\"Actual Code Point: %ld\\n\", (long)mirrorAgent-\u003ecodepoint);\n        printf(\"Mirrored Code Point: %ld\\n\\n\", (long)mirrorAgent-\u003emirror);\n    }\n\n    /* Release all objects. */\n    SBMirrorLocatorRelease(mirrorLocator);\n    SBLineRelease(paragraphLine);\n    SBParagraphRelease(firstParagraph);\n    SBAlgorithmRelease(bidiAlgorithm);\n\n    return 0;\n}\n```\n\n## Support\nIf SheenBidi plays a role in your project, you’re welcome to [star the repository](https://github.com/Tehreer/SheenBidi/stargazers) or [contribute improvements](https://github.com/Tehreer/SheenBidi/pulls). Engagement from the community helps inform future development and ensures continued relevance.\n\n## License\n```\nCopyright (C) 2014-2026 Muhammad Tayyab Akram\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n  http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftehreer%2Fsheenbidi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftehreer%2Fsheenbidi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftehreer%2Fsheenbidi/lists"}