From 712cf80e2d25d5313ce31e7803e1bc546c3b4acf Mon Sep 17 00:00:00 2001 From: aB0t Date: Wed, 5 Jul 2023 08:48:52 +0200 Subject: [PATCH] update 2023-07-05 08:48:52 --- README.md | 1 + .../README.md | 51 ++++++++++++ .../code.php | 82 +++++++++++++++++++ .../code.power | 59 +++++++++++++ .../settings.json | 18 ++++ .../README.md | 8 ++ .../code.php | 17 ++++ .../code.power | 16 ++++ .../settings.json | 4 + super-powers.json | 11 +++ 10 files changed, 267 insertions(+) create mode 100644 src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/README.md create mode 100644 src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/code.php create mode 100644 src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/code.power create mode 100644 src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/settings.json diff --git a/README.md b/README.md index 1d8b6e3..154ac26 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ This repository contains an index (see below) of all the approved powers within - **final class Http** | [Details](src/b8c66089-735e-4081-825c-8fe36b28e4a6) | [Code](src/b8c66089-735e-4081-825c-8fe36b28e4a6/code.php) | [Settings](src/b8c66089-735e-4081-825c-8fe36b28e4a6/settings.json) | Super__b8c66089_735e_4081_825c_8fe36b28e4a6__Power - **final class Response** | [Details](src/c99e85a0-d120-4f25-bcbf-0940dd7b773b) | [Code](src/c99e85a0-d120-4f25-bcbf-0940dd7b773b/code.php) | [Settings](src/c99e85a0-d120-4f25-bcbf-0940dd7b773b/settings.json) | Super__c99e85a0_d120_4f25_bcbf_0940dd7b773b__Power + - **final class StringHelper** | [Details](src/a5b32737-207d-4cf6-b8ae-ee815612c3a0) | [Code](src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/code.php) | [Settings](src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/settings.json) | Super__a5b32737_207d_4cf6_b8ae_ee815612c3a0__Power - **final class Uri** | [Details](src/fc9ab6f0-c31b-4077-bb1c-2dcddd36f6bb) | [Code](src/fc9ab6f0-c31b-4077-bb1c-2dcddd36f6bb/code.php) | [Settings](src/fc9ab6f0-c31b-4077-bb1c-2dcddd36f6bb/settings.json) | Super__fc9ab6f0_c31b_4077_bb1c_2dcddd36f6bb__Power --- diff --git a/src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/README.md b/src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/README.md new file mode 100644 index 0000000..d00dcd1 --- /dev/null +++ b/src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/README.md @@ -0,0 +1,51 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# final class StringHelper (Details) +> namespace: **VDM\Joomla\GetBible\Utilities** +```uml +@startuml +class StringHelper << (F,LightGreen) >> #Green { + + split(string $text) : array + + isCJK(string $text) : bool + + hasLength(string $word) : bool +} + +note right of StringHelper::split + Return an array of words + + return: array +end note + +note right of StringHelper::isCJK + Checks if a string contains characters typically used in East Asian languages (Chinese, Japanese, Korean) +These languages do not typically use word boundaries in the same way as languages written in Latin script + + return: bool +end note + +note right of StringHelper::hasLength + Make sure a string has a length + + return: bool +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/code.php b/src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/code.php new file mode 100644 index 0000000..c462960 --- /dev/null +++ b/src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/code.php @@ -0,0 +1,82 @@ + + * @git GetBible + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\GetBible\Utilities; + + +/** + * The GetBible String Helper + * + * @since 2.0.1 + */ +final class StringHelper +{ + /** + * Return an array of words + * + * @param string $text The actual sentence + * + * @return array An array of words + */ + public function split(string $text): array + { + if ($this->isCJK($text)) + { + // Split by characters for languages that don't use spaces + $words = (array) preg_split('//u', $text, -1, PREG_SPLIT_NO_EMPTY); + } + elseif (strpos($text, ' ') !== false) + { + // Split by spaces for languages that use them + $words = (array) preg_split('/(\s+)/u', $text, -1, PREG_SPLIT_DELIM_CAPTURE); + } + else + { + $words = [$text]; + } + + return $words; + } + + /** + * Checks if a string contains characters typically used in East Asian languages (Chinese, Japanese, Korean) + * These languages do not typically use word boundaries in the same way as languages written in Latin script + * + * @param string $text The string to be checked for CJK characters + * + * @return bool True if the string contains at least one CJK character, false otherwise + */ + public function isCJK(string $text): bool + { + if (preg_match('/[\x{4E00}-\x{9FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{AC00}-\x{D7AF}]/u', $text)) + { + return true; + } + return false; + } + + /** + * Make sure a string has a length + * + * @param string $word The actual string to check + * + * @return bool True if its a string with characters. + */ + public function hasLength(string $word): bool + { + // Trim the string + $trimmed = trim($word); + + // Return true if the trimmed string is not empty, false otherwise + return !empty($trimmed); + } +} + diff --git a/src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/code.power b/src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/code.power new file mode 100644 index 0000000..98ff3f9 --- /dev/null +++ b/src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/code.power @@ -0,0 +1,59 @@ + /** + * Return an array of words + * + * @param string $text The actual sentence + * + * @return array An array of words + */ + public function split(string $text): array + { + if ($this->isCJK($text)) + { + // Split by characters for languages that don't use spaces + $words = (array) preg_split('//u', $text, -1, PREG_SPLIT_NO_EMPTY); + } + elseif (strpos($text, ' ') !== false) + { + // Split by spaces for languages that use them + $words = (array) preg_split('/(\s+)/u', $text, -1, PREG_SPLIT_DELIM_CAPTURE); + } + else + { + $words = [$text]; + } + + return $words; + } + + /** + * Checks if a string contains characters typically used in East Asian languages (Chinese, Japanese, Korean) + * These languages do not typically use word boundaries in the same way as languages written in Latin script + * + * @param string $text The string to be checked for CJK characters + * + * @return bool True if the string contains at least one CJK character, false otherwise + */ + public function isCJK(string $text): bool + { + if (preg_match('/[\x{4E00}-\x{9FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{AC00}-\x{D7AF}]/u', $text)) + { + return true; + } + return false; + } + + /** + * Make sure a string has a length + * + * @param string $word The actual string to check + * + * @return bool True if its a string with characters. + */ + public function hasLength(string $word): bool + { + // Trim the string + $trimmed = trim($word); + + // Return true if the trimmed string is not empty, false otherwise + return !empty($trimmed); + } \ No newline at end of file diff --git a/src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/settings.json b/src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/settings.json new file mode 100644 index 0000000..f2ea4a8 --- /dev/null +++ b/src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/settings.json @@ -0,0 +1,18 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "a5b32737-207d-4cf6-b8ae-ee815612c3a0", + "implements": null, + "load_selection": null, + "name": "StringHelper", + "power_version": "1.0.0", + "system_name": "Joomla.GetBible.Utilities.StringHelper", + "type": "final class", + "use_selection": null, + "namespace": "VDM\\Joomla\\GetBible\\Utilities.StringHelper", + "description": "The GetBible String Helper\r\n\r\n@since 2.0.1", + "licensing_template": "\/**\r\n * @package GetBible\r\n *\r\n * @created 30th May, 2023\r\n * @author Llewellyn van der Merwe \r\n * @git GetBible \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/b89d74ef-c71c-4a58-8455-5dbdfe94027a/README.md b/src/b89d74ef-c71c-4a58-8455-5dbdfe94027a/README.md index 058ac5d..51d547d 100644 --- a/src/b89d74ef-c71c-4a58-8455-5dbdfe94027a/README.md +++ b/src/b89d74ef-c71c-4a58-8455-5dbdfe94027a/README.md @@ -15,6 +15,7 @@ class Utilities #Gold { + getUri(Container $container) : Uri + getResponse(Container $container) : Response + getHttp(Container $container) : Http + + getString(Container $container) : StringHelper } note right of Utilities::register @@ -44,6 +45,13 @@ note right of Utilities::getHttp since: 3.2.0 return: Http end note + +note right of Utilities::getString + Get the String Helper class + + since: 3.2.0 + return: StringHelper +end note @enduml ``` diff --git a/src/b89d74ef-c71c-4a58-8455-5dbdfe94027a/code.php b/src/b89d74ef-c71c-4a58-8455-5dbdfe94027a/code.php index 36e54ad..b437644 100644 --- a/src/b89d74ef-c71c-4a58-8455-5dbdfe94027a/code.php +++ b/src/b89d74ef-c71c-4a58-8455-5dbdfe94027a/code.php @@ -17,6 +17,7 @@ use Joomla\DI\ServiceProviderInterface; use VDM\Joomla\GetBible\Utilities\Uri; use VDM\Joomla\GetBible\Utilities\Response; use VDM\Joomla\GetBible\Utilities\Http; +use VDM\Joomla\GetBible\Utilities\StringHelper; /** @@ -44,6 +45,9 @@ class Utilities implements ServiceProviderInterface $container->alias(Http::class, 'GetBible.Utilities.Http') ->share('GetBible.Utilities.Http', [$this, 'getHttp'], true); + + $container->alias(StringHelper::class, 'GetBible.Utilities.String') + ->share('GetBible.Utilities.String', [$this, 'getString'], true); } /** @@ -85,6 +89,19 @@ class Utilities implements ServiceProviderInterface public function getHttp(Container $container): Http { return new Http(); + } + + /** + * Get the String Helper class + * + * @param Container $container The DI container. + * + * @return StringHelper + * @since 3.2.0 + */ + public function getString(Container $container): StringHelper + { + return new StringHelper(); } } diff --git a/src/b89d74ef-c71c-4a58-8455-5dbdfe94027a/code.power b/src/b89d74ef-c71c-4a58-8455-5dbdfe94027a/code.power index 65e4382..8c86712 100644 --- a/src/b89d74ef-c71c-4a58-8455-5dbdfe94027a/code.power +++ b/src/b89d74ef-c71c-4a58-8455-5dbdfe94027a/code.power @@ -16,6 +16,9 @@ $container->alias(Http::class, 'GetBible.Utilities.Http') ->share('GetBible.Utilities.Http', [$this, 'getHttp'], true); + + $container->alias(StringHelper::class, 'GetBible.Utilities.String') + ->share('GetBible.Utilities.String', [$this, 'getString'], true); } /** @@ -57,4 +60,17 @@ public function getHttp(Container $container): Http { return new Http(); + } + + /** + * Get the String Helper class + * + * @param Container $container The DI container. + * + * @return StringHelper + * @since 3.2.0 + */ + public function getString(Container $container): StringHelper + { + return new StringHelper(); } \ No newline at end of file diff --git a/src/b89d74ef-c71c-4a58-8455-5dbdfe94027a/settings.json b/src/b89d74ef-c71c-4a58-8455-5dbdfe94027a/settings.json index b3873c0..e38ea28 100644 --- a/src/b89d74ef-c71c-4a58-8455-5dbdfe94027a/settings.json +++ b/src/b89d74ef-c71c-4a58-8455-5dbdfe94027a/settings.json @@ -23,6 +23,10 @@ "use_selection2": { "use": "b8c66089-735e-4081-825c-8fe36b28e4a6", "as": "default" + }, + "use_selection3": { + "use": "a5b32737-207d-4cf6-b8ae-ee815612c3a0", + "as": "default" } }, "namespace": "VDM\\Joomla\\GetBible\\Service.Utilities", diff --git a/super-powers.json b/super-powers.json index 3391d46..1eba571 100644 --- a/super-powers.json +++ b/super-powers.json @@ -120,6 +120,17 @@ "spk": "Super__a07d90f6_6ff2_40a1_99c1_0f2cf33c9adf__Power", "guid": "a07d90f6-6ff2-40a1-99c1-0f2cf33c9adf" }, + "a5b32737-207d-4cf6-b8ae-ee815612c3a0": { + "name": "StringHelper", + "type": "final class", + "namespace": "VDM\\Joomla\\GetBible\\Utilities", + "code": "src\/a5b32737-207d-4cf6-b8ae-ee815612c3a0\/code.php", + "power": "src\/a5b32737-207d-4cf6-b8ae-ee815612c3a0\/code.power", + "settings": "src\/a5b32737-207d-4cf6-b8ae-ee815612c3a0\/settings.json", + "path": "src\/a5b32737-207d-4cf6-b8ae-ee815612c3a0", + "spk": "Super__a5b32737_207d_4cf6_b8ae_ee815612c3a0__Power", + "guid": "a5b32737-207d-4cf6-b8ae-ee815612c3a0" + }, "a752e4b2-9b5e-4188-8d33-3799c46d5119": { "name": "Chapters", "type": "final class",