{"id":13704662,"url":"https://github.com/hoaproject/Ustring","last_synced_at":"2025-05-05T10:30:41.404Z","repository":{"id":4401633,"uuid":"5538851","full_name":"hoaproject/Ustring","owner":"hoaproject","description":"The Hoa\\Ustring library.","archived":true,"fork":false,"pushed_at":"2021-04-29T19:09:54.000Z","size":214,"stargazers_count":402,"open_issues_count":7,"forks_count":16,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-10-30T00:00:44.519Z","etag":null,"topics":["hoa","library","php","string","string-algorithms","unicode","ustring"],"latest_commit_sha":null,"homepage":"https://hoa-project.net/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hoaproject.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-08-24T10:31:31.000Z","updated_at":"2023-12-07T10:17:51.000Z","dependencies_parsed_at":"2022-09-21T11:11:29.185Z","dependency_job_id":null,"html_url":"https://github.com/hoaproject/Ustring","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FUstring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FUstring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FUstring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FUstring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hoaproject","download_url":"https://codeload.github.com/hoaproject/Ustring/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223938052,"owners_count":17228316,"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":["hoa","library","php","string","string-algorithms","unicode","ustring"],"created_at":"2024-08-02T21:01:16.264Z","updated_at":"2024-11-13T11:31:37.895Z","avatar_url":"https://github.com/hoaproject.png","language":"PHP","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://static.hoa-project.net/Image/Hoa.svg\" alt=\"Hoa\" width=\"250px\" /\u003e\n\u003c/p\u003e\n\n---\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://travis-ci.org/hoaproject/ustring\"\u003e\u003cimg src=\"https://img.shields.io/travis/hoaproject/ustring/master.svg\" alt=\"Build status\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://coveralls.io/github/hoaproject/ustring?branch=master\"\u003e\u003cimg src=\"https://img.shields.io/coveralls/hoaproject/ustring/master.svg\" alt=\"Code coverage\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://packagist.org/packages/hoa/ustring\"\u003e\u003cimg src=\"https://img.shields.io/packagist/dt/hoa/ustring.svg\" alt=\"Packagist\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://hoa-project.net/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/packagist/l/hoa/ustring.svg\" alt=\"License\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  Hoa is a \u003cstrong\u003emodular\u003c/strong\u003e, \u003cstrong\u003eextensible\u003c/strong\u003e and\n  \u003cstrong\u003estructured\u003c/strong\u003e set of PHP libraries.\u003cbr /\u003e\n  Moreover, Hoa aims at being a bridge between industrial and research worlds.\n\u003c/p\u003e\n\n# Hoa\\Ustring\n\n[![Help on IRC](https://img.shields.io/badge/help-%23hoaproject-ff0066.svg)](https://webchat.freenode.net/?channels=#hoaproject)\n[![Help on Gitter](https://img.shields.io/badge/help-gitter-ff0066.svg)](https://gitter.im/hoaproject/central)\n[![Documentation](https://img.shields.io/badge/documentation-hack_book-ff0066.svg)](https://central.hoa-project.net/Documentation/Library/Ustring)\n[![Board](https://img.shields.io/badge/organisation-board-ff0066.svg)](https://waffle.io/hoaproject/ustring)\n\nThis library allows to manipulate UTF-8 strings easily with some search\nalgorithms.\n\n[Learn more](https://central.hoa-project.net/Documentation/Library/Ustring).\n\n## Installation\n\nWith [Composer](https://getcomposer.org/), to include this library into\nyour dependencies, you need to\nrequire [`hoa/ustring`](https://packagist.org/packages/hoa/ustring):\n\n```sh\n$ composer require hoa/ustring '~4.0'\n```\n\nFor more installation procedures, please read [the Source\npage](https://hoa-project.net/Source.html).\n\n## Testing\n\nBefore running the test suites, the development dependencies must be installed:\n\n```sh\n$ composer install\n```\n\nThen, to run all the test suites:\n\n```sh\n$ vendor/bin/hoa test:run\n```\n\nFor more information, please read the [contributor\nguide](https://hoa-project.net/Literature/Contributor/Guide.html).\n\n## Quick usage\n\nWe propose a quick overview of two usages: manipulate UTF-8 strings and one\nsearch algorithm.\n\n### Natural UTF-8 strings manipulation\n\nThe `Hoa\\Ustring\\Ustring` class allows to manipulate easily UTF-8 strings in a\nvery natural way. This class implements the `\\ArrayAccess`, `\\Countable` and\n`\\IteratorAggregate` interfaces. We will use the following examples:\n\n```php\n$french   = new Hoa\\Ustring\\Ustring('Je t\\'aime');\n$arabic   = new Hoa\\Ustring\\Ustring('أحبك');\n$japanese = new Hoa\\Ustring\\Ustring('私はあなたを愛して');\n```\n\nTo get the first character, we will do:\n\n```php\nvar_dump(\n    $french[0],  // string(1) \"J\"\n    $arabic[0],  // string(2) \"أ\"\n    $japanese[0] // string(3) \"私\"\n);\n```\n\nAnd to get the last character, we will do `[-1]`. It supports unbounded (and\nmodulo) indexes.\n\nWe note that it cares about text **direction**. Look at `$arabic[0]`, it returns\n`أ` and not `ك`. To get the direction, we can use the\n`Hoa\\Ustring\\Ustring::getDirection` method (which call the\n`Hoa\\Ustring\\Ustring::getCharDirection` static method), it returns either\n`Hoa\\Ustring\\Ustring::LTR` (`0`) or `Hoa\\Ustring\\Ustring::RTL` (`1`):\n\n```php\nvar_dump(\n    $french-\u003egetDirection(),  // int(0)\n    $arabic-\u003egetDirection(),  // int(1)\n    $japanese-\u003egetDirection() // int(0)\n);\n```\n\nText direction is also important for the `append`, `prepend`, `pad`… methods on\n`Hoa\\Ustring\\Ustring` for example. \n\nTo get the length of a string, we can use the `count` function:\n\n```php\nvar_dump(\n    count($french),  // int(9)\n    count($arabic),  // int(4)\n    count($japanese) // int(9)\n);\n```\n\nWe are also able to iterate over the string:\n\n```php\nforeach ($arabic as $letter) {\n    var_dump($letter);\n}\n\n/**\n * Will output:\n *     string(2) \"أ\"\n *     string(2) \"ح\"\n *     string(2) \"ب\"\n *     string(2) \"ك\"\n */\n```\n\nAgain, text direction is useful here. For `$arabic`, the iteration is done from\nright to left.\n\nSome static methods are helpful, such as `fromCode`, `toCode` or `isUtf8` on\n`Hoa\\Ustring\\Ustring`:\n\n```php\nvar_dump(\n    Hoa\\Ustring\\Ustring::fromCode(0x1a9), // string(2) \"Ʃ\"\n    Hoa\\Ustring\\Ustring::toCode('Ʃ'),     // int(425) == 0x1a9\n    Hoa\\Ustring\\Ustring::isUtf8('Ʃ')      // bool(true)\n);\n```\n\nWe can also transform any text into ASCII:\n\n```php\n$emoji = new Hoa\\Ustring\\Ustring('I ❤ Unicode');\n$maths = new Hoa\\Ustring\\Ustring('∀ i ∈ ℕ');\n\necho\n    $emoji-\u003etoAscii(), \"\\n\",\n    $maths-\u003etoAscii(), \"\\n\";\n\n/**\n * Will output:\n *     I (heavy black heart) Unicode\n *     (for all) i (element of) N\n */\n```\n\n### Search algorithm\n\nThe `Hoa\\Ustring\\Search` implements search algorithms on strings.\n\nFor example, the `Hoa\\Ustring\\Search::approximated` method make a search by\napproximated patterns (with *k* differences based upon the principle diagonal\nmonotony). If we search the word `GATAA` in `CAGATAAGAGAA` with 1 difference, we\nwill do:\n\n```php\n$search = Hoa\\Ustring\\Search::approximated(\n    $haystack = 'CAGATAAGAGAA',\n    $needle   = 'GATAA',\n    $k        = 1\n);\n$solutions = array();\n\nforeach ($search as $pos) {\n    $solutions[] = substr($haystack, $pos['i'], $pos['l']);\n}\n```\n\nWe will found `AGATA`, `GATAA`, `ATAAG` and `GAGAA`.\n\nThe result is not very handy but the algorithm is much optimized and found many\napplications.\n\n## Documentation\n\nThe\n[hack book of `Hoa\\Ustring`](https://central.hoa-project.net/Documentation/Library/Ustring) contains\ndetailed information about how to use this library and how it works.\n\nTo generate the documentation locally, execute the following commands:\n\n```sh\n$ composer require --dev hoa/devtools\n$ vendor/bin/hoa devtools:documentation --open\n```\n\nMore documentation can be found on the project's website:\n[hoa-project.net](https://hoa-project.net/).\n\n## Getting help\n\nThere are mainly two ways to get help:\n\n  * On the [`#hoaproject`](https://webchat.freenode.net/?channels=#hoaproject)\n    IRC channel,\n  * On the forum at [users.hoa-project.net](https://users.hoa-project.net).\n\n## Contribution\n\nDo you want to contribute? Thanks! A detailed [contributor\nguide](https://hoa-project.net/Literature/Contributor/Guide.html) explains\neverything you need to know.\n\n## License\n\nHoa is under the New BSD License (BSD-3-Clause). Please, see\n[`LICENSE`](https://hoa-project.net/LICENSE) for details.\n","funding_links":[],"categories":["目录","Table of Contents"],"sub_categories":["字符串 Strings","Strings"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoaproject%2FUstring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoaproject%2FUstring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoaproject%2FUstring/lists"}