update 2023-07-05 08:48:52
This commit is contained in:
parent
4ff9c09995
commit
712cf80e2d
@ -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
|
||||
|
||||
---
|
||||
|
51
src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/README.md
Normal file
51
src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/README.md
Normal file
@ -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)
|
||||
|
82
src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/code.php
Normal file
82
src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/code.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* @package GetBible
|
||||
*
|
||||
* @created 30th May, 2023
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git GetBible <https://git.vdm.dev/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);
|
||||
}
|
||||
}
|
||||
|
59
src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/code.power
Normal file
59
src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/code.power
Normal file
@ -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);
|
||||
}
|
18
src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/settings.json
Normal file
18
src/a5b32737-207d-4cf6-b8ae-ee815612c3a0/settings.json
Normal file
@ -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 <https:\/\/dev.vdm.io>\r\n * @git GetBible <https:\/\/git.vdm.dev\/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": ""
|
||||
}
|
@ -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
|
||||
```
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
@ -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",
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user