aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2015-05-18 09:49:37 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2015-05-18 09:49:37 +0200
commitcedbbdb85a5897e48e276ada329242d48dd719d9 (patch)
treeedca9fd34da51311413702cd74e579b19629c4fe
parent8df23c4758c8a692d523c966c7b9b79bbf9771c3 (diff)
downloadUstring-cedbbdb85a5897e48e276ada329242d48dd719d9.zip
Ustring-cedbbdb85a5897e48e276ada329242d48dd719d9.tar.gz
Ustring-cedbbdb85a5897e48e276ada329242d48dd719d9.tar.bz2
Move to PSR-1 and PSR-2.
-rw-r--r--Bin/Fromcode.php61
-rw-r--r--Bin/Tocode.php61
-rw-r--r--Documentation/En/Index.xyl18
-rw-r--r--Documentation/Fr/Index.xyl18
-rw-r--r--Exception.php10
-rw-r--r--README.md13
-rw-r--r--Search.php39
-rw-r--r--String.php531
-rw-r--r--Test/Unit/Issue.php16
-rw-r--r--Test/Unit/Search.php16
-rw-r--r--Test/Unit/String.php272
11 files changed, 514 insertions, 541 deletions
diff --git a/Bin/Fromcode.php b/Bin/Fromcode.php
index 3c9cf72..25d67b3 100644
--- a/Bin/Fromcode.php
+++ b/Bin/Fromcode.php
@@ -8,7 +8,7 @@
*
* New BSD License
*
- * Copyright © 2007-2015, Ivan Enderlin. All rights reserved.
+ * Copyright © 2007-2015, Hoa community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -44,17 +44,15 @@ use Hoa\String;
*
* Get a character from its code. Please, see Hoa\String\String::fromCode.
*
- * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
- * @copyright Copyright © 2007-2015 Ivan Enderlin.
+ * @copyright Copyright © 2007-2015 Hoa community
* @license New BSD License
*/
-
-class Fromcode extends Console\Dispatcher\Kit {
-
+class Fromcode extends Console\Dispatcher\Kit
+{
/**
* Options description.
*
- * @var \Hoa\String\Bin\Fromcode array
+ * @var array
*/
protected $options = [
['base', Console\GetOption::REQUIRED_ARGUMENT, 'b'],
@@ -67,28 +65,29 @@ class Fromcode extends Console\Dispatcher\Kit {
/**
* The entry method.
*
- * @access public
* @return int
*/
- public function main ( ) {
-
+ public function main()
+ {
$base = 16;
- while(false !== $c = $this->getOption($v)) switch($c) {
+ while (false !== $c = $this->getOption($v)) {
+ switch ($c) {
+ case 'b':
+ $base = intval($v);
+
+ break;
- case 'b':
- $base = intval($v);
- break;
+ case '__ambiguous':
+ $this->resolveOptionAmbiguity($v);
- case '__ambiguous':
- $this->resolveOptionAmbiguity($v);
- break;
+ break;
- case 'h':
- case '?':
- default:
- return $this->usage();
- break;
+ case 'h':
+ case '?':
+ default:
+ return $this->usage();
+ }
}
$this->parser->listInputs($code);
@@ -103,17 +102,17 @@ class Fromcode extends Console\Dispatcher\Kit {
/**
* The command usage.
*
- * @access public
* @return int
*/
- public function usage ( ) {
-
- echo 'Usage : string:fromcode <char>', "\n",
- 'Options :', "\n",
- $this->makeUsageOptionsList([
- 'b' => 'Specify the base of the code (16 by default).',
- 'help' => 'This help.'
- ]), "\n";
+ public function usage()
+ {
+ echo
+ 'Usage : string:fromcode <char>', "\n",
+ 'Options :', "\n",
+ $this->makeUsageOptionsList([
+ 'b' => 'Specify the base of the code (16 by default).',
+ 'help' => 'This help.'
+ ]), "\n";
return;
}
diff --git a/Bin/Tocode.php b/Bin/Tocode.php
index 1c20116..35c8972 100644
--- a/Bin/Tocode.php
+++ b/Bin/Tocode.php
@@ -8,7 +8,7 @@
*
* New BSD License
*
- * Copyright © 2007-2015, Ivan Enderlin. All rights reserved.
+ * Copyright © 2007-2015, Hoa community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -44,17 +44,15 @@ use Hoa\String;
*
* Transform a character into its code. Please, see Hoa\String\String::toCode.
*
- * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
- * @copyright Copyright © 2007-2015 Ivan Enderlin.
+ * @copyright Copyright © 2007-2015 Hoa community
* @license New BSD License
*/
-
-class Tocode extends Console\Dispatcher\Kit {
-
+class Tocode extends Console\Dispatcher\Kit
+{
/**
* Options description.
*
- * @var \Hoa\String\Bin\Tocode array
+ * @var array
*/
protected $options = [
['base', Console\GetOption::REQUIRED_ARGUMENT, 'b'],
@@ -67,28 +65,29 @@ class Tocode extends Console\Dispatcher\Kit {
/**
* The entry method.
*
- * @access public
* @return int
*/
- public function main ( ) {
-
+ public function main()
+ {
$base = 16;
- while(false !== $c = $this->getOption($v)) switch($c) {
+ while (false !== $c = $this->getOption($v)) {
+ switch ($c) {
+ case 'b':
+ $base = intval($v);
+
+ break;
- case 'b':
- $base = intval($v);
- break;
+ case '__ambiguous':
+ $this->resolveOptionAmbiguity($v);
- case '__ambiguous':
- $this->resolveOptionAmbiguity($v);
- break;
+ break;
- case 'h':
- case '?':
- default:
- return $this->usage();
- break;
+ case 'h':
+ case '?':
+ default:
+ return $this->usage();
+ }
}
$this->parser->listInputs($char);
@@ -103,17 +102,17 @@ class Tocode extends Console\Dispatcher\Kit {
/**
* The command usage.
*
- * @access public
* @return int
*/
- public function usage ( ) {
-
- echo 'Usage : string:tocode <char>', "\n",
- 'Options :', "\n",
- $this->makeUsageOptionsList([
- 'b' => 'Get the code in a specific base (16 by default).',
- 'help' => 'This help.'
- ]), "\n";
+ public function usage()
+ {
+ echo
+ 'Usage : string:tocode <char>', "\n",
+ 'Options :', "\n",
+ $this->makeUsageOptionsList([
+ 'b' => 'Get the code in a specific base (16 by default).',
+ 'help' => 'This help.'
+ ]), "\n";
return;
}
diff --git a/Documentation/En/Index.xyl b/Documentation/En/Index.xyl
index 1fd45ca..72182ac 100644
--- a/Documentation/En/Index.xyl
+++ b/Documentation/En/Index.xyl
@@ -205,10 +205,11 @@ echo $title->toAscii();
<pre><code class="language-php">$emoji = new Hoa\String\String('I ❤ Unicode');
$maths = new Hoa\String\String('∀ i ∈ ℕ');
-echo $arabic->toAscii(), "\n",
- $japanese->toAscii(), "\n",
- $emoji->toAscii(), "\n",
- $maths->toAscii(), "\n";
+echo
+ $arabic->toAscii(), "\n",
+ $japanese->toAscii(), "\n",
+ $emoji->toAscii(), "\n",
+ $maths->toAscii(), "\n";
/**
* Will output:
@@ -286,8 +287,9 @@ echo $arabic->toAscii(), "\n",
<code>IteratorAggregate</code> method, being the
<code>Hoa\String\String::getIterator</code> method. Let's see on the Arabic
example:</p>
- <pre><code class="language-php">foreach($arabic as $letter)
+ <pre><code class="language-php">foreach ($arabic as $letter) {
echo $letter, "\n";
+}
/**
* Will output:
@@ -392,8 +394,7 @@ var_dump($matches['direct_object']);
replacements to apply. If the replacement is a callable, then the
<code>preg_replace_callback</code> function will be used.</p>
<p>Thus, we will modify our French example to be more polite:</p>
- <pre><code class="language-php">$french->replace('#(?:\w[\'\b])(?&amp;lt;verb>aime)#', function ( $matches ) {
-
+ <pre><code class="language-php">$french->replace('#(?:\w[\'\b])(?&amp;lt;verb>aime)#', function ($matches) {
return 'vous ' . $matches['verb'];
});
@@ -545,8 +546,9 @@ $n = count($search);
echo 'Try to match ', $x, ' in ', $y, ' with at most ', $k, ' difference(s):', "\n";
echo $n, ' match(es) found:', "\n";
-foreach($search as $position)
+foreach ($search as $position) {
echo ' • ', substr($y, $position['i'], $position['l'), "\n";
+}
/**
* Will output:
diff --git a/Documentation/Fr/Index.xyl b/Documentation/Fr/Index.xyl
index ca146c5..e16ae52 100644
--- a/Documentation/Fr/Index.xyl
+++ b/Documentation/Fr/Index.xyl
@@ -211,10 +211,11 @@ echo $title->toAscii();
<pre><code class="language-php">$emoji = new Hoa\String\String('I ❤ Unicode');
$maths = new Hoa\String\String('∀ i ∈ ℕ');
-echo $arabic->toAscii(), "\n",
- $japanese->toAscii(), "\n",
- $emoji->toAscii(), "\n",
- $maths->toAscii(), "\n";
+echo
+ $arabic->toAscii(), "\n",
+ $japanese->toAscii(), "\n",
+ $emoji->toAscii(), "\n",
+ $maths->toAscii(), "\n";
/**
* Will output:
@@ -294,8 +295,9 @@ echo $arabic->toAscii(), "\n",
<code>IteratorAggregate</code>, soit la méthode
<code>Hoa\String\String::getIterator</code>. Voyons plutôt sur l'exemple en
arabe :</p>
- <pre><code class="language-php">foreach($arabic as $letter)
+ <pre><code class="language-php">foreach ($arabic as $letter) {
echo $letter, "\n";
+}
/**
* Will output:
@@ -406,8 +408,7 @@ var_dump($matches['direct_object']);
alors la fonction <code>preg_replace_callback</code> sera utilisée.</p>
<p>Ainsi, nous allons modifier notre exemple français pour qu'il soit plus
poli :</p>
- <pre><code class="language-php">$french->replace('#(?:\w[\'\b])(?&amp;lt;verb>aime)#', function ( $matches ) {
-
+ <pre><code class="language-php">$french->replace('#(?:\w[\'\b])(?&amp;lt;verb>aime)#', function ($matches) {
return 'vous ' . $matches['verb'];
});
@@ -561,8 +562,9 @@ $n = count($search);
echo 'Try to match ', $x, ' in ', $y, ' with at most ', $k, ' difference(s):', "\n";
echo $n, ' match(es) found:', "\n";
-foreach($search as $position)
+foreach ($search as $position) {
echo ' • ', substr($y, $position['i'], $position['l'), "\n";
+}
/**
* Will output:
diff --git a/Exception.php b/Exception.php
index e9708d7..c78dba8 100644
--- a/Exception.php
+++ b/Exception.php
@@ -8,7 +8,7 @@
*
* New BSD License
*
- * Copyright © 2007-2015, Ivan Enderlin. All rights reserved.
+ * Copyright © 2007-2015, Hoa community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -43,9 +43,9 @@ use Hoa\Core;
*
* Extending the \Hoa\Core\Exception class.
*
- * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
- * @copyright Copyright © 2007-2015 Ivan Enderlin.
+ * @copyright Copyright © 2007-2015 Hoa community
* @license New BSD License
*/
-
-class Exception extends Core\Exception { }
+class Exception extends Core\Exception
+{
+}
diff --git a/README.md b/README.md
index 3085e2f..13265c6 100644
--- a/README.md
+++ b/README.md
@@ -85,8 +85,9 @@ var_dump(
We are also able to iterate over the string:
```php
-foreach($arabic as $letter)
+foreach ($arabic as $letter) {
var_dump($letter);
+}
/**
* Will output:
@@ -117,8 +118,9 @@ We can also transform any text into ASCII:
$emoji = new Hoa\String\String('I ❤ Unicode');
$maths = new Hoa\String\String('∀ i ∈ ℕ');
-echo $emoji->toAscii(), "\n",
- $maths->toAscii(), "\n";
+echo
+ $emoji->toAscii(), "\n",
+ $maths->toAscii(), "\n";
/**
* Will output:
@@ -137,15 +139,16 @@ monotony). If we search the word `GATAA` in `CAGATAAGAGAA` with 1 difference, we
will do:
```php
-$search = Hoa\String\Search::approximated(
+$search = Hoa\String\Search::approximated(
$haystack = 'CAGATAAGAGAA',
$needle = 'GATAA',
$k = 1
);
$solutions = array();
-foreach($search as $pos)
+foreach ($search as $pos) {
$solutions[] = substr($haystack, $pos['i'], $pos['l']);
+}
```
We will found `AGATA`, `GATAA`, `ATAAG` and `GAGAA`.
diff --git a/Search.php b/Search.php
index c7d219c..76a1a64 100644
--- a/Search.php
+++ b/Search.php
@@ -8,7 +8,7 @@
*
* New BSD License
*
- * Copyright © 2007-2015, Ivan Enderlin. All rights reserved.
+ * Copyright © 2007-2015, Hoa community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -41,25 +41,22 @@ namespace Hoa\String;
*
* Some algorithms about search in strings.
*
- * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
- * @copyright Copyright © 2007-2015 Ivan Enderlin.
+ * @copyright Copyright © 2007-2015 Hoa community
* @license New BSD License
*/
-
-class Search {
-
+class Search
+{
/**
* Search by approximated patterns, with k differences based upon the
* principle diagonal monotony.
*
- * @access public
* @param string $y Haystack.
* @param string $x Needle.
* @param int $k Number of differences.
* @return array
*/
- public static function approximated ( $y, $x, $k ) {
-
+ public static function approximated($y, $x, $k)
+ {
$x = (string) $x;
$y = (string) $y;
$m = strlen($x);
@@ -67,12 +64,12 @@ class Search {
$offset = [];
$L = [-1 => array_fill(-1, $n - $m + $k + 3, -2)];
- for($q = 0, $max = $k - 1; $q <= $max; ++$q)
+ for ($q = 0, $max = $k - 1; $q <= $max; ++$q) {
$L[$q][-$q - 1] = $L[$q][-$q - 2] = $q - 1;
+ }
- for($q = 0; $q <= $k; ++$q)
- for($d = -$q, $max = $n - $m + $k - $q; $d <= $max; ++$d) {
-
+ for ($q = 0; $q <= $k; ++$q) {
+ for ($d = -$q, $max = $n - $m + $k - $q; $d <= $max; ++$d) {
$l = min(
max(
$L[$q - 1][$d - 1],
@@ -81,18 +78,18 @@ class Search {
),
$m - 1
);
- $a = substr($x, $l + 1 , $m - $l );
+ $a = substr($x, $l + 1, $m - $l);
$b = substr($y, $l + 1 + $d, $n - $l - $d);
$L[$q][$d] = $l + static::lcp($a, $b);
- if( $L[$q][$d] == $m - 1
- || $d + $L[$q][$d] == $n - 1) {
-
+ if ($L[$q][$d] == $m - 1 ||
+ $d + $L[$q][$d] == $n - 1) {
$j = $m + $d;
$i = max(0, $j - $m);
$offset[$q][] = ['i' => $i, 'j' => $j, 'l' => $j - $i];
}
}
+ }
return empty($offset) ? $offset : $offset[$k];
}
@@ -100,18 +97,18 @@ class Search {
/**
* Length of the longest common prefixes.
*
- * @access public
* @param string $x Word.
* @param string $y Word.
* @return int
*/
- public static function lcp ( $x, $y ) {
-
+ public static function lcp($x, $y)
+ {
$max = min(strlen($x), strlen($y));
$i = 0;
- while($i < $max && $x[$i] == $y[$i])
+ while ($i < $max && $x[$i] == $y[$i]) {
++$i;
+ }
return $i;
}
diff --git a/String.php b/String.php
index 597faa6..cbca6be 100644
--- a/String.php
+++ b/String.php
@@ -8,7 +8,7 @@
*
* New BSD License
*
- * Copyright © 2007-2015, Ivan Enderlin. All rights reserved.
+ * Copyright © 2007-2015, Hoa community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -47,13 +47,11 @@ use Hoa\Core;
* • http://unicode.org/reports/tr9/;
* • http://www.unicode.org/Public/6.0.0/ucd/UnicodeData.txt.
*
- * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
- * @copyright Copyright © 2007-2015 Ivan Enderlin.
+ * @copyright Copyright © 2007-2015 Hoa community
* @license New BSD License
*/
-
-class String implements \ArrayAccess, \Countable, \IteratorAggregate {
-
+class String implements \ArrayAccess, \Countable, \IteratorAggregate
+{
/**
* Left-To-Right.
*
@@ -178,21 +176,21 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Current string.
*
- * @var \Hoa\String string
+ * @var string
*/
protected $_string = null;
/**
* Direction. Please see self::LTR and self::RTL constants.
*
- * @var \Hoa\String int
+ * @var int
*/
protected $_direction = null;
/**
* Collator.
*
- * @var \Collator object
+ * @var \Collator
*/
protected static $_collator = null;
@@ -201,18 +199,22 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Construct a UTF-8 string.
*
- * @access public
* @param string $string String.
* @return void
*/
- public function __construct ( $string = null ) {
-
- if(false === function_exists('mb_substr'))
+ public function __construct($string = null)
+ {
+ if (false === function_exists('mb_substr')) {
throw new Exception(
- '%s needs the mbstring extension.', 0, get_class($this));
+ '%s needs the mbstring extension.',
+ 0,
+ get_class($this)
+ );
+ }
- if(null !== $string)
+ if (null !== $string) {
$this->append($string);
+ }
return;
}
@@ -220,12 +222,11 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Append a substring to the current string, i.e. add to the end.
*
- * @access public
* @param string $substring Substring to append.
* @return \Hoa\String
*/
- public function append ( $substring ) {
-
+ public function append($substring)
+ {
$this->_string .= $substring;
return $this;
@@ -234,13 +235,12 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Prepend a substring to the current string, i.e. add to the start.
*
- * @access public
* @param string $substring Substring to append.
* @return \Hoa\String
*/
- public function prepend ( $substring ) {
-
- $this->_string = $substring . $this->_string;
+ public function prepend($substring)
+ {
+ $this->_string = $substring . $this->_string;
return $this;
}
@@ -248,30 +248,32 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Pad the current string to a certain length with another piece, aka piece.
*
- * @access public
* @param int $length Length.
* @param string $piece Piece.
* @param int $side Whether we append at the end or the beginning
* of the current string.
* @return \Hoa\String
*/
- public function pad ( $length, $piece, $side = self::END ) {
-
+ public function pad($length, $piece, $side = self::END)
+ {
$difference = $length - $this->count();
- if(0 >= $difference)
+ if (0 >= $difference) {
return $this;
+ }
$handle = null;
- for($i = $difference / mb_strlen($piece) - 1; $i >= 0; --$i)
+ for ($i = $difference / mb_strlen($piece) - 1; $i >= 0; --$i) {
$handle .= $piece;
+ }
$handle .= mb_substr($piece, 0, $difference - mb_strlen($handle));
- return static::END === $side
- ? $this->append($handle)
- : $this->prepend($handle);
+ return
+ static::END === $side
+ ? $this->append($handle)
+ : $this->prepend($handle);
}
/**
@@ -279,14 +281,14 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
* Return < 0 if current string is less than $string, > 0 if greater and 0
* if equal.
*
- * @access public
* @param mixed $string String.
* @return int
*/
- public function compare ( $string ) {
-
- if(null === $collator = static::getCollator())
+ public function compare($string)
+ {
+ if (null === $collator = static::getCollator()) {
return strcmp($this->_string, (string) $string);
+ }
return $collator->compare($this->_string, $string);
}
@@ -294,16 +296,17 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Get collator.
*
- * @access public
* @return \Collator
*/
- public static function getCollator ( ) {
-
- if(false === class_exists('Collator'))
+ public static function getCollator()
+ {
+ if (false === class_exists('Collator')) {
return null;
+ }
- if(null === static::$_collator)
+ if (null === static::$_collator) {
static::$_collator = new \Collator(setlocale(LC_COLLATE, null));
+ }
return static::$_collator;
}
@@ -311,20 +314,20 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Ensure that the pattern is safe for Unicode: add the “u” option.
*
- * @access public
* @param string $pattern Pattern.
* @return string
*/
- public static function safePattern ( $pattern ) {
-
+ public static function safePattern($pattern)
+ {
$delimiter = mb_substr($pattern, 0, 1);
$options = mb_substr(
mb_strrchr($pattern, $delimiter, false),
mb_strlen($delimiter)
);
- if(false === strpos($options, 'u'))
+ if (false === strpos($options, 'u')) {
$pattern .= 'u';
+ }
return $pattern;
}
@@ -332,7 +335,6 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Perform a regular expression (PCRE) match.
*
- * @access public
* @param string $pattern Pattern.
* @param array $matches Matches.
* @param int $flags Please, see constants self::WITH_OFFSET,
@@ -343,23 +345,27 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
* @param bool $global Whether the match is global or not.
* @return int
*/
- public function match ( $pattern, &$matches = null, $flags = 0,
- $offset = 0, $global = false ) {
-
+ public function match(
+ $pattern,
+ &$matches = null,
+ $flags = 0,
+ $offset = 0,
+ $global = false
+ ) {
$pattern = static::safePattern($pattern);
- if(0 === $flags) {
-
- if(true === $global)
+ if (0 === $flags) {
+ if (true === $global) {
$flags = static::GROUP_BY_PATTERN;
- }
- else
+ }
+ } else {
$flags &= ~PREG_SPLIT_OFFSET_CAPTURE;
+ }
$offset = strlen(mb_substr($this->_string, 0, $offset));
- if(true === $global)
+ if (true === $global) {
return preg_match_all(
$pattern,
$this->_string,
@@ -367,6 +373,7 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
$flags,
$offset
);
+ }
return preg_match($pattern, $this->_string, $matches, $flags, $offset);
}
@@ -374,31 +381,31 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Perform a regular expression (PCRE) search and replace.
*
- * @access public
* @param mixed $pattern Pattern(s).
* @param mixed $replacement Replacement(s) (please, see
* preg_replace() documentation).
* @param int $limit Maximum of replacements. -1 for unbound.
* @return \Hoa\String
*/
- public function replace ( $pattern, $replacement, $limit = -1 ) {
-
+ public function replace($pattern, $replacement, $limit = -1)
+ {
$pattern = static::safePattern($pattern);
- if(false === is_callable($replacement))
+ if (false === is_callable($replacement)) {
$this->_string = preg_replace(
$pattern,
$replacement,
$this->_string,
$limit
);
- else
+ } else {
$this->_string = preg_replace_callback(
$pattern,
$replacement,
$this->_string,
$limit
);
+ }
return $this;
}
@@ -406,16 +413,17 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Split the current string according to a given pattern (PCRE).
*
- * @access public
* @param string $pattern Pattern (as a regular expression).
* @param int $limit Maximum of split. -1 for unbound.
* @param int $flags Please, see constants self::WITHOUT_EMPTY,
* self::WITH_DELIMITERS, self::WITH_OFFSET.
* @return array
*/
- public function split ( $pattern, $limit = -1,
- $flags = self::WITHOUT_EMPTY ) {
-
+ public function split(
+ $pattern,
+ $limit = -1,
+ $flags = self::WITHOUT_EMPTY
+ ) {
return preg_split(
static::safePattern($pattern),
$this->_string,
@@ -427,22 +435,20 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Iterator over chars.
*
- * @access public
* @return \ArrayIterator
*/
- public function getIterator ( ) {
-
+ public function getIterator()
+ {
return new \ArrayIterator(preg_split('#(?<!^)(?!$)#u', $this->_string));
}
/**
* Perform a lowercase folding on the current string.
*
- * @access public
* @return \Hoa\String
*/
- public function toLowerCase ( ) {
-
+ public function toLowerCase()
+ {
$this->_string = mb_strtolower($this->_string);
return $this;
@@ -451,11 +457,10 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Perform an uppercase folding on the current string.
*
- * @access public
* @return \Hoa\String
*/
- public function toUpperCase ( ) {
-
+ public function toUpperCase()
+ {
$this->_string = mb_strtoupper($this->_string);
return $this;
@@ -466,28 +471,26 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
* First, try with a transliterator. If not available, will fallback to a
* normalizer. If not available, will try something homemade.
*
- * @access public
* @param bool $try Try something if \Normalizer is not present.
* @return \Hoa\String
- * @throw \Hoa\String\Exception
+ * @throws \Hoa\String\Exception
*/
- public function toAscii ( $try = false ) {
-
- if(0 === preg_match('#[\x80-\xff]#', $this->_string))
+ public function toAscii($try = false)
+ {
+ if (0 === preg_match('#[\x80-\xff]#', $this->_string)) {
return $this;
+ }
- $string = $this->_string;
-
- $transId = 'Any-Latin; ' .
- '[\p{S}] Name; ' .
- 'Latin-ASCII';
-
- if(null !== $transliterator = static::getTransliterator($transId)) {
+ $string = $this->_string;
+ $transId =
+ 'Any-Latin; ' .
+ '[\p{S}] Name; ' .
+ 'Latin-ASCII';
+ if (null !== $transliterator = static::getTransliterator($transId)) {
$this->_string = preg_replace_callback(
'#\\\N\{([A-Z ]+)\}#u',
- function ( Array $matches ) {
-
+ function (Array $matches) {
return '(' . strtolower($matches[1]) . ')';
},
$transliterator->transliterate($string)
@@ -496,13 +499,15 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
return $this;
}
- if(false === class_exists('Normalizer')) {
-
- if(false === $try)
+ if (false === class_exists('Normalizer')) {
+ if (false === $try) {
throw new Exception(
'%s needs the class Normalizer to work properly, ' .
'or you can force a try by using %1$s(true).',
- 1, __METHOD__);
+ 1,
+ __METHOD__
+ );
+ }
$string = static::transcode($string, 'UTF-8', 'ASCII//IGNORE//TRANSLIT');
$this->_string = preg_replace('#(?:[\'"`^](\w))#u', '\1', $string);
@@ -521,19 +526,21 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
* Transliterate the string into another.
* See self::getTransliterator for more information.
*
- * @access public
* @param string $identifier Identifier.
* @param int $start Start.
* @param int $end End.
* @return \Hoa\String
- * @throw \Hoa\String\Exception
+ * @throws \Hoa\String\Exception
*/
- public function transliterate ( $identifier, $start = 0, $end = null ) {
-
- if(null === $transliterator = static::getTransliterator($identifier))
+ public function transliterate($identifier, $start = 0, $end = null)
+ {
+ if (null === $transliterator = static::getTransliterator($identifier)) {
throw new Exception(
'%s needs the class Transliterator to work properly.',
- 2, __METHOD__);
+ 2,
+ __METHOD__
+ );
+ }
$this->_string = $transliterator->transliterate($this->_string, $start, $end);
@@ -544,14 +551,14 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
* Get transliterator.
* See http://userguide.icu-project.org/transforms/general for $identifier.
*
- * @access public
* @param string $identifier Identifier.
* @return \Transliterator
*/
- public static function getTransliterator ( $identifier ) {
-
- if(false === class_exists('Transliterator'))
+ public static function getTransliterator($identifier)
+ {
+ if (false === class_exists('Transliterator')) {
return null;
+ }
return \Transliterator::create($identifier);
}
@@ -559,25 +566,24 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Strip characters (default \s) of the current string.
*
- * @access public
* @param string $regex Characters to remove.
* @param int $side Whether we trim the beginning, the end or both
* sides, of the current string.
* @return \Hoa\String
*/
- public function trim ( $regex = '\s', $side = 3 /* static::BEGINNING
- | static::END */ ) {
-
+ public function trim($regex = '\s', $side = 3 /* static::BEGINNING | static::END */)
+ {
$regex = '(?:' . $regex . ')+';
$handle = null;
- if(0 !== ($side & static::BEGINNING))
+ if (0 !== ($side & static::BEGINNING)) {
$handle .= '(^' . $regex . ')';
+ }
- if(0 !== ($side & static::END)) {
-
- if(null !== $handle)
+ if (0 !== ($side & static::END)) {
+ if (null !== $handle) {
$handle .= '|';
+ }
$handle .= '(' . $regex . '$)';
}
@@ -591,23 +597,22 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Compute offset (negative, unbound etc.).
*
- * @access protected
* @param int $offset Offset.
* @return int
*/
- protected function computeOffset ( $offset ) {
-
+ protected function computeOffset($offset)
+ {
$length = mb_strlen($this->_string);
- if(0 > $offset) {
-
+ if (0 > $offset) {
$offset = -$offset % $length;
- if(0 !== $offset)
+ if (0 !== $offset) {
$offset = $length - $offset;
- }
- elseif($offset >= $length)
+ }
+ } elseif ($offset >= $length) {
$offset %= $length;
+ }
return $offset;
}
@@ -615,30 +620,29 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Get a specific chars of the current string.
*
- * @access public
* @param int $offset Offset (can be negative and unbound).
* @return string
*/
- public function offsetGet ( $offset ) {
-
+ public function offsetGet($offset)
+ {
return mb_substr($this->_string, $this->computeOffset($offset), 1);
}
/**
* Set a specific character of the current string.
*
- * @access public
* @param int $offset Offset (can be negative and unbound).
* @param string $value Value.
* @return \Hoa\String
*/
- public function offsetSet ( $offset, $value ) {
-
+ public function offsetSet($offset, $value)
+ {
$head = null;
$offset = $this->computeOffset($offset);
- if(0 < $offset)
+ if (0 < $offset) {
$head = mb_substr($this->_string, 0, $offset);
+ }
$tail = mb_substr($this->_string, $offset + 1);
$this->_string = $head . $value . $tail;
@@ -650,36 +654,33 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Delete a specific character of the current string.
*
- * @access public
* @param int $offset Offset (can be negative and unbound).
* @return string
*/
- public function offsetUnset ( $offset ) {
-
+ public function offsetUnset($offset)
+ {
return $this->offsetSet($offset, null);
}
/**
* Check if a specific offset exists.
*
- * @access public
* @return bool
*/
- public function offsetExists ( $offset ) {
-
+ public function offsetExists($offset)
+ {
return true;
}
/**
* Reduce the strings.
*
- * @access public
* @param int $start Position of first character.
* @param int $length Maximum number of characters.
* @return \Hoa\String
*/
- public function reduce ( $start, $length = null ) {
-
+ public function reduce($start, $length = null)
+ {
$this->_string = mb_substr($this->_string, $start, $length);
return $this;
@@ -688,34 +689,32 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Count number of characters of the current string.
*
- * @access public
* @return int
*/
- public function count ( ) {
-
+ public function count()
+ {
return mb_strlen($this->_string);
}
/**
* Get byte (not character) at a specific offset.
*
- * @access public
* @param int $offset Offset (can be negative and unbound).
* @return string
*/
- public function getByteAt ( $offset ) {
-
+ public function getByteAt($offset)
+ {
$length = strlen($this->_string);
- if(0 > $offset) {
-
+ if (0 > $offset) {
$offset = -$offset % $length;
- if(0 !== $offset)
+ if (0 !== $offset) {
$offset = $length - $offset;
- }
- elseif($offset >= $length)
+ }
+ } elseif ($offset >= $length) {
$offset %= $length;
+ }
return $this->_string[$offset];
}
@@ -723,11 +722,10 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Count number of bytes (not characters) of the current string.
*
- * @access public
* @return int
*/
- public function getBytesLength ( ) {
-
+ public function getBytesLength()
+ {
return strlen($this->_string);
}
@@ -736,11 +734,10 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
* Useful when printing the string in monotype (some character need more
* than one column to be printed).
*
- * @access public
* @return int
*/
- public function getWidth ( ) {
-
+ public function getWidth()
+ {
return mb_strwidth($this->_string);
}
@@ -749,19 +746,18 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
* Please, see the self::LTR and self::RTL constants.
* It does not yet support embedding directions.
*
- * @access public
* @return int
*/
- public function getDirection ( ) {
-
- if(null === $this->_direction) {
-
- if(null === $this->_string)
+ public function getDirection()
+ {
+ if (null === $this->_direction) {
+ if (null === $this->_string) {
$this->_direction = static::LTR;
- else
+ } else {
$this->_direction = static::getCharDirection(
mb_substr($this->_string, 0, 1)
);
+ }
}
return $this->_direction;
@@ -771,91 +767,90 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
* Get character of a specific character.
* Please, see the self::LTR and self::RTL constants.
*
- * @access public
* @param string $char Character.
* @return int
*/
- public static function getCharDirection ( $char ) {
-
+ public static function getCharDirection($char)
+ {
$c = static::toCode($char);
- if(!(0x5be <= $c && 0x10b7f >= $c))
+ if (!(0x5be <= $c && 0x10b7f >= $c)) {
return static::LTR;
+ }
- if(0x85e >= $c) {
-
- if( 0x5be === $c
- || 0x5c0 === $c
- || 0x5c3 === $c
- || 0x5c6 === $c
- || (0x5d0 <= $c && 0x5ea >= $c)
- || (0x5f0 <= $c && 0x5f4 >= $c)
- || 0x608 === $c
- || 0x60b === $c
- || 0x60d === $c
- || 0x61b === $c
- || (0x61e <= $c && 0x64a >= $c)
- || (0x66d <= $c && 0x66f >= $c)
- || (0x671 <= $c && 0x6d5 >= $c)
- || (0x6e5 <= $c && 0x6e6 >= $c)
- || (0x6ee <= $c && 0x6ef >= $c)
- || (0x6fa <= $c && 0x70d >= $c)
- || 0x710 === $c
- || (0x712 <= $c && 0x72f >= $c)
- || (0x74d <= $c && 0x7a5 >= $c)
- || 0x7b1 === $c
- || (0x7c0 <= $c && 0x7ea >= $c)
- || (0x7f4 <= $c && 0x7f5 >= $c)
- || 0x7fa === $c
- || (0x800 <= $c && 0x815 >= $c)
- || 0x81a === $c
- || 0x824 === $c
- || 0x828 === $c
- || (0x830 <= $c && 0x83e >= $c)
- || (0x840 <= $c && 0x858 >= $c)
- || 0x85e === $c)
+ if (0x85e >= $c) {
+ if (0x5be === $c ||
+ 0x5c0 === $c ||
+ 0x5c3 === $c ||
+ 0x5c6 === $c ||
+ (0x5d0 <= $c && 0x5ea >= $c) ||
+ (0x5f0 <= $c && 0x5f4 >= $c) ||
+ 0x608 === $c ||
+ 0x60b === $c ||
+ 0x60d === $c ||
+ 0x61b === $c ||
+ (0x61e <= $c && 0x64a >= $c) ||
+ (0x66d <= $c && 0x66f >= $c) ||
+ (0x671 <= $c && 0x6d5 >= $c) ||
+ (0x6e5 <= $c && 0x6e6 >= $c) ||
+ (0x6ee <= $c && 0x6ef >= $c) ||
+ (0x6fa <= $c && 0x70d >= $c) ||
+ 0x710 === $c ||
+ (0x712 <= $c && 0x72f >= $c) ||
+ (0x74d <= $c && 0x7a5 >= $c) ||
+ 0x7b1 === $c ||
+ (0x7c0 <= $c && 0x7ea >= $c) ||
+ (0x7f4 <= $c && 0x7f5 >= $c) ||
+ 0x7fa === $c ||
+ (0x800 <= $c && 0x815 >= $c) ||
+ 0x81a === $c ||
+ 0x824 === $c ||
+ 0x828 === $c ||
+ (0x830 <= $c && 0x83e >= $c) ||
+ (0x840 <= $c && 0x858 >= $c) ||
+ 0x85e === $c) {
return static::RTL;
- }
- elseif(0x200f === $c)
+ }
+ } elseif (0x200f === $c) {
return static::RTL;
- elseif(0xfb1d <= $c) {
-
- if( 0xfb1d === $c
- || (0xfb1f <= $c && 0xfb28 >= $c)
- || (0xfb2a <= $c && 0xfb36 >= $c)
- || (0xfb38 <= $c && 0xfb3c >= $c)
- || 0xfb3e === $c
- || (0xfb40 <= $c && 0xfb41 >= $c)
- || (0xfb43 <= $c && 0xfb44 >= $c)
- || (0xfb46 <= $c && 0xfbc1 >= $c)
- || (0xfbd3 <= $c && 0xfd3d >= $c)
- || (0xfd50 <= $c && 0xfd8f >= $c)
- || (0xfd92 <= $c && 0xfdc7 >= $c)
- || (0xfdf0 <= $c && 0xfdfc >= $c)
- || (0xfe70 <= $c && 0xfe74 >= $c)
- || (0xfe76 <= $c && 0xfefc >= $c)
- || (0x10800 <= $c && 0x10805 >= $c)
- || 0x10808 === $c
- || (0x1080a <= $c && 0x10835 >= $c)
- || (0x10837 <= $c && 0x10838 >= $c)
- || 0x1083c === $c
- || (0x1083f <= $c && 0x10855 >= $c)
- || (0x10857 <= $c && 0x1085f >= $c)
- || (0x10900 <= $c && 0x1091b >= $c)
- || (0x10920 <= $c && 0x10939 >= $c)
- || 0x1093f === $c
- || 0x10a00 === $c
- || (0x10a10 <= $c && 0x10a13 >= $c)
- || (0x10a15 <= $c && 0x10a17 >= $c)
- || (0x10a19 <= $c && 0x10a33 >= $c)
- || (0x10a40 <= $c && 0x10a47 >= $c)
- || (0x10a50 <= $c && 0x10a58 >= $c)
- || (0x10a60 <= $c && 0x10a7f >= $c)
- || (0x10b00 <= $c && 0x10b35 >= $c)
- || (0x10b40 <= $c && 0x10b55 >= $c)
- || (0x10b58 <= $c && 0x10b72 >= $c)
- || (0x10b78 <= $c && 0x10b7f >= $c))
+ } elseif (0xfb1d <= $c) {
+ if (0xfb1d === $c ||
+ (0xfb1f <= $c && 0xfb28 >= $c) ||
+ (0xfb2a <= $c && 0xfb36 >= $c) ||
+ (0xfb38 <= $c && 0xfb3c >= $c) ||
+ 0xfb3e === $c ||
+ (0xfb40 <= $c && 0xfb41 >= $c) ||
+ (0xfb43 <= $c && 0xfb44 >= $c) ||
+ (0xfb46 <= $c && 0xfbc1 >= $c) ||
+ (0xfbd3 <= $c && 0xfd3d >= $c) ||
+ (0xfd50 <= $c && 0xfd8f >= $c) ||
+ (0xfd92 <= $c && 0xfdc7 >= $c) ||
+ (0xfdf0 <= $c && 0xfdfc >= $c) ||
+ (0xfe70 <= $c && 0xfe74 >= $c) ||
+ (0xfe76 <= $c && 0xfefc >= $c) ||
+ (0x10800 <= $c && 0x10805 >= $c) ||
+ 0x10808 === $c ||
+ (0x1080a <= $c && 0x10835 >= $c) ||
+ (0x10837 <= $c && 0x10838 >= $c) ||
+ 0x1083c === $c ||
+ (0x1083f <= $c && 0x10855 >= $c) ||
+ (0x10857 <= $c && 0x1085f >= $c) ||
+ (0x10900 <= $c && 0x1091b >= $c) ||
+ (0x10920 <= $c && 0x10939 >= $c) ||
+ 0x1093f === $c ||
+ 0x10a00 === $c ||
+ (0x10a10 <= $c && 0x10a13 >= $c) ||
+ (0x10a15 <= $c && 0x10a17 >= $c) ||
+ (0x10a19 <= $c && 0x10a33 >= $c) ||
+ (0x10a40 <= $c && 0x10a47 >= $c) ||
+ (0x10a50 <= $c && 0x10a58 >= $c) ||
+ (0x10a60 <= $c && 0x10a7f >= $c) ||
+ (0x10b00 <= $c && 0x10b35 >= $c) ||
+ (0x10b40 <= $c && 0x10b55 >= $c) ||
+ (0x10b58 <= $c && 0x10b72 >= $c) ||
+ (0x10b78 <= $c && 0x10b7f >= $c)) {
return static::RTL;
+ }
}
return static::LTR;
@@ -873,26 +868,28 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
* occupied by the wide-character code wc, or return -1 (if wc does not
* correspond to a printable wide-character code).
*
- * @access public
* @param string $char Character.
* @return int
*/
- public static function getCharWidth ( $char ) {
-
+ public static function getCharWidth($char)
+ {
$char = (string) $char;
$c = static::toCode($char);
// Test for 8-bit control characters.
- if(0x0 === $c)
+ if (0x0 === $c) {
return 0;
+ }
- if(0x20 > $c || (0x7f <= $c && $c < 0xa0))
+ if (0x20 > $c || (0x7f <= $c && $c < 0xa0)) {
return -1;
+ }
// Non-spacing characters.
- if( 0xad !== $c
- && 0 !== preg_match('#^[\p{Mn}\p{Me}\p{Cf}\x{1160}-\x{11ff}\x{200b}]#u', $char))
+ if (0xad !== $c &&
+ 0 !== preg_match('#^[\p{Mn}\p{Me}\p{Cf}\x{1160}-\x{11ff}\x{200b}]#u', $char)) {
return 0;
+ }
// If we arrive here, $c is not a combining C0/C1 control character.
return 1 +
@@ -914,24 +911,22 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Check whether the character is printable or not.
*
- * @access public
* @param string $char Character.
* @return bool
*/
- public static function isCharPrintable ( $char ) {
-
+ public static function isCharPrintable($char)
+ {
return 1 <= static::getCharWidth($char);
}
/**
* Get a UTF-8 character from its decimal code representation.
*
- * @access public
* @param int $code Code.
* @return string
*/
- public static function fromCode ( $code ) {
-
+ public static function fromCode($code)
+ {
return mb_convert_encoding(
'&#x' . dechex($code) . ';',
'UTF-8',
@@ -942,38 +937,33 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Get a decimal code representation of a specific character.
*
- * @access public
* @param string $char Character.
* @return int
*/
- public static function toCode ( $char ) {
-
+ public static function toCode($char)
+ {
$char = (string) $char;
$code = ord($char[0]);
$bytes = 1;
- if(!($code & 0x80)) // 0xxxxxxx
+ if (!($code & 0x80)) {// 0xxxxxxx
return $code;
+ }
- if(($code & 0xe0) === 0xc0) { // 110xxxxx
-
+ if (($code & 0xe0) === 0xc0) { // 110xxxxx
$bytes = 2;
$code = $code & ~0xc0;
- }
- elseif(($code & 0xf0) == 0xe0) { // 1110xxxx
-
+ } elseif (($code & 0xf0) == 0xe0) { // 1110xxxx
$bytes = 3;
$code = $code & ~0xe0;
- }
-
- elseif(($code & 0xf8) === 0xf0) { // 11110xxx
-
+ } elseif (($code & 0xf8) === 0xf0) { // 11110xxx
$bytes = 4;
$code = $code & ~0xf0;
}
- for($i = 2; $i <= $bytes; $i++) // 10xxxxxx
+ for ($i = 2; $i <= $bytes; $i++) {// 10xxxxxx
$code = ($code << 6) + (ord($char[$i - 1]) & ~0x80);
+ }
return $code;
}
@@ -981,17 +971,17 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Get a binary representation of a specific character.
*
- * @access public
* @param string $char Character.
* @return string
*/
- public static function toBinaryCode ( $char ) {
-
+ public static function toBinaryCode($char)
+ {
$char = (string) $char;
$out = null;
- for($i = 0, $max = strlen($char); $i < $max; ++$i)
+ for ($i = 0, $max = strlen($char); $i < $max; ++$i) {
$out .= vsprintf('%08b', ord($char[$i]));
+ }
return $out;
}
@@ -999,26 +989,24 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
/**
* Transcode.
*
- * @access public
* @param string $string String.
* @param string $from Original encoding.
* @param string $to Final encoding.
* @return string
*/
- public static function transcode ( $string, $from, $to = 'UTF-8' ) {
-
+ public static function transcode($string, $from, $to = 'UTF-8')
+ {
return iconv($from, $to, $string);
}
/**
* Check if a string is encoded in UTF-8.
*
- * @access public
* @param string $string String.
* @return bool
*/
- public static function isUtf8 ( $string ) {
-
+ public static function isUtf8($string)
+ {
return (bool) preg_match('##u', $string);
}
@@ -1027,19 +1015,18 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
*
* @return \Hoa\String
*/
- public function copy ( ) {
-
+ public function copy()
+ {
return clone $this;
}
/**
* Transform the object as a string.
*
- * @access public
* @return string
*/
- public function __toString ( ) {
-
+ public function __toString()
+ {
return $this->_string;
}
}
diff --git a/Test/Unit/Issue.php b/Test/Unit/Issue.php
index ba4eeb8..9e21a33 100644
--- a/Test/Unit/Issue.php
+++ b/Test/Unit/Issue.php
@@ -8,7 +8,7 @@
*
* New BSD License
*
- * Copyright © 2007-2015, Ivan Enderlin. All rights reserved.
+ * Copyright © 2007-2015, Hoa community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -36,23 +36,21 @@
namespace Hoa\String\Test\Unit;
-use Hoa\Test;
use Hoa\String as LUT;
+use Hoa\Test;
/**
* Class \Hoa\String\Test\Unit\Issue.
*
* Test suite of detected issues.
*
- * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
- * @copyright Copyright © 2007-2015 Ivan Enderlin.
+ * @copyright Copyright © 2007-2015 Hoa community
* @license New BSD License
*/
-
-class Issue extends Test\Unit\Suite {
-
- public function case_github_26 ( ) {
-
+class Issue extends Test\Unit\Suite
+{
+ public function case_github_26()
+ {
$this
->when($result = LUT::toCode(chr(160)))
->then
diff --git a/Test/Unit/Search.php b/Test/Unit/Search.php
index 570898a..dbc5fc4 100644
--- a/Test/Unit/Search.php
+++ b/Test/Unit/Search.php
@@ -8,7 +8,7 @@
*
* New BSD License
*
- * Copyright © 2007-2015, Ivan Enderlin. All rights reserved.
+ * Copyright © 2007-2015, Hoa community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -36,23 +36,21 @@
namespace Hoa\String\Test\Unit;
-use Hoa\Test;
use Hoa\String as LUT;
+use Hoa\Test;
/**
* Class \Hoa\String\Test\Unit\Search.
*
* Test suite of the search algorithms.
*
- * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
- * @copyright Copyright © 2007-2015 Ivan Enderlin.
+ * @copyright Copyright © 2007-2015 Hoa community
* @license New BSD License
*/
-
-class Search extends Test\Unit\Suite {
-
- public function case_approximated ( ) {
-
+class Search extends Test\Unit\Suite
+{
+ public function case_approximated()
+ {
$this
->given(
$x = 'GATAA',
diff --git a/Test/Unit/String.php b/Test/Unit/String.php
index 32d9001..0757b95 100644
--- a/Test/Unit/String.php
+++ b/Test/Unit/String.php
@@ -8,7 +8,7 @@
*
* New BSD License
*
- * Copyright © 2007-2015, Ivan Enderlin. All rights reserved.
+ * Copyright © 2007-2015, Hoa community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -36,39 +36,35 @@
namespace Hoa\String\Test\Unit;
-use Hoa\Test;
use Hoa\String as LUT;
+use Hoa\Test;
/**
* Class \Hoa\String\Test\Unit\String.
*
* Test suite of the string class.
*
- * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
- * @copyright Copyright © 2007-2015 Ivan Enderlin.
+ * @copyright Copyright © 2007-2015 Hoa community
* @license New BSD License
*/
-
-class String extends Test\Unit\Suite {
-
- public function case_no_mbstring ( ) {
-
+class String extends Test\Unit\Suite
+{
+ public function case_no_mbstring()
+ {
$this
->given(
- $this->function->function_exists = function ( $name ) {
-
+ $this->function->function_exists = function ($name) {
return 'mb_substr' !== $name;
}
)
- ->exception(function ( ) {
-
+ ->exception(function () {
new LUT();
})
->isInstanceOf('Hoa\String\Exception');
}
- public function case_append_ltr ( ) {
-
+ public function case_append_ltr()
+ {
$this
->given($string = new LUT('je'))
->when($result = $string->append(' t\'aime'))
@@ -79,8 +75,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('je t\'aime');
}
- public function case_append_rtl ( ) {
-
+ public function case_append_rtl()
+ {
$this
->given($string = new LUT('أ'))
->when($result = $string->append('حبك'))
@@ -91,8 +87,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('أحبك');
}
- public function case_prepend_ltr ( ) {
-
+ public function case_prepend_ltr()
+ {
$this
->given($string = new LUT(' t\'aime'))
->when($result = $string->prepend('je'))
@@ -103,8 +99,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('je t\'aime');
}
- public function case_prepend_rtl ( ) {
-
+ public function case_prepend_rtl()
+ {
$this
->given($string = new LUT('ك'))
->when($result = $string->prepend('أحب'))
@@ -115,8 +111,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('أحبك');
}
- public function case_pad_beginning_ltr ( ) {
-
+ public function case_pad_beginning_ltr()
+ {
$this
->given($string = new LUT('je t\'aime'))
->when($result = $string->pad(20, '👍 💩 😄 ❤️ ', LUT::BEGINNING))
@@ -127,8 +123,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('👍 💩 😄 ❤️ 👍 je t\'aime');
}
- public function case_pad_beginning_rtl ( ) {
-
+ public function case_pad_beginning_rtl()
+ {
$this
->given($string = new LUT('أحبك'))
->when($result = $string->pad(20, '👍 💩 😄 ❤️ ', LUT::BEGINNING))
@@ -139,8 +135,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('👍 💩 😄 ❤️ 👍 💩 😄 ❤أحبك');
}
- public function case_pad_end_ltr ( ) {
-
+ public function case_pad_end_ltr()
+ {
$this
->given($string = new LUT('je t\'aime'))
->when($result = $string->pad(20, '👍 💩 😄 ❤️ ', LUT::END))
@@ -151,8 +147,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('je t\'aime👍 💩 😄 ❤️ 👍 ');
}
- public function case_pad_end_rtl ( ) {
-
+ public function case_pad_end_rtl()
+ {
$this
->given($string = new LUT('أحبك'))
->when($result = $string->pad(20, '👍 💩 😄 ❤️ ', LUT::END))
@@ -163,12 +159,11 @@ class String extends Test\Unit\Suite {
->isEqualTo('أحبك👍 💩 😄 ❤️ 👍 💩 😄 ❤');
}
- public function case_compare_no_collator ( ) {
-
+ public function case_compare_no_collator()
+ {
$this
->given(
- $this->function->class_exists = function ( $name ) {
-
+ $this->function->class_exists = function ($name) {
return 'Collator' !== $name;
},
$string = new LUT('b')
@@ -176,8 +171,8 @@ class String extends Test\Unit\Suite {
->case_compare();
}
- public function case_compare ( ) {
-
+ public function case_compare()
+ {
$this
->given($string = new LUT('b'))
->when($result = $string->compare('a'))
@@ -196,8 +191,8 @@ class String extends Test\Unit\Suite {
->isEqualTo(-1);
}
- public function case_collator ( ) {
-
+ public function case_collator()
+ {
$this
->given(
$this->function->setlocale = 'fr_FR',
@@ -209,8 +204,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('fr');
}
- public function case_safe_unsafe_pattern ( ) {
-
+ public function case_safe_unsafe_pattern()
+ {
$this
->given($pattern = '/foo/i')
->when($result = LUT::safePattern($pattern))
@@ -219,8 +214,8 @@ class String extends Test\Unit\Suite {
->isEqualto('/foo/iu');
}
- public function case_safe_safe_pattern ( ) {
-
+ public function case_safe_safe_pattern()
+ {
$this
->given($pattern = '/foo/ui')
->when($result = LUT::safePattern($pattern))
@@ -229,8 +224,8 @@ class String extends Test\Unit\Suite {
->isEqualto('/foo/ui');
}
- public function case_match_default ( ) {
-
+ public function case_match_default()
+ {
$this
->given(
$pattern = '/💩/u',
@@ -246,8 +241,8 @@ class String extends Test\Unit\Suite {
]);
}
- public function case_match_offset ( ) {
-
+ public function case_match_offset()
+ {
$this
->given(
$pattern = '/💩/u',
@@ -275,8 +270,8 @@ class String extends Test\Unit\Suite {
->isEmpty();
}
- public function case_match_with_offset ( ) {
-
+ public function case_match_with_offset()
+ {
$this
->given(
$pattern = '/💩/u',
@@ -295,8 +290,8 @@ class String extends Test\Unit\Suite {
]);
}
- public function case_match_all_default ( ) {
-
+ public function case_match_all_default()
+ {
$this
->given(
$pattern = '/💩/u',
@@ -315,8 +310,8 @@ class String extends Test\Unit\Suite {
]);
}
- public function case_match_all_with_offset ( ) {
-
+ public function case_match_all_with_offset()
+ {
$this
->given(
$pattern = '/💩/u',
@@ -341,8 +336,8 @@ class String extends Test\Unit\Suite {
]);
}
- public function case_match_all_grouped_by_pattern ( ) {
-
+ public function case_match_all_grouped_by_pattern()
+ {
$this
->given(
$pattern = '/(💩)/u',
@@ -365,8 +360,8 @@ class String extends Test\Unit\Suite {
]);
}
- public function case_match_all_grouped_by_tuple ( ) {
-
+ public function case_match_all_grouped_by_tuple()
+ {
$this
->given(
$pattern = '/(💩)/u',
@@ -389,8 +384,8 @@ class String extends Test\Unit\Suite {
]);
}
- public function case_replace ( ) {
-
+ public function case_replace()
+ {
$this
->given($string = new LUT('❤️ 💩 💩'))
->when($result = $string->replace('/💩/u', '😄'))
@@ -401,8 +396,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('❤️ 😄 😄');
}
- public function case_replace_limited ( ) {
-
+ public function case_replace_limited()
+ {
$this
->given($string = new LUT('❤️ 💩 💩'))
->when($result = $string->replace('/💩/u', '😄', 1))
@@ -413,8 +408,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('❤️ 😄 💩');
}
- public function case_split_default ( ) {
-
+ public function case_split_default()
+ {
$this
->given($string = new LUT('❤️💩❤️💩❤️'))
->when($result = $string->split('/💩/'))
@@ -427,8 +422,8 @@ class String extends Test\Unit\Suite {
]);
}
- public function case_split_default_limited ( ) {
-
+ public function case_split_default_limited()
+ {
$this
->given($string = new LUT('❤️💩❤️💩❤️'))
->when($result = $string->split('/💩/', 1))
@@ -439,8 +434,8 @@ class String extends Test\Unit\Suite {
]);
}
- public function case_split_with_delimiters ( ) {
-
+ public function case_split_with_delimiters()
+ {
$this
->given($string = new LUT('❤️💩❤️💩❤️'))
->when($result = $string->split('/💩/', -1, $string::WITH_DELIMITERS))
@@ -453,8 +448,8 @@ class String extends Test\Unit\Suite {
]);
}
- public function case_split_with_offset ( ) {
-
+ public function case_split_with_offset()
+ {
$this
->given($string = new LUT('❤️💩❤️💩❤️'))
->when($result = $string->split('/💩/', -1, $string::WITH_OFFSET))
@@ -476,8 +471,8 @@ class String extends Test\Unit\Suite {
]);
}
- public function case_iterator_ltr ( ) {
-
+ public function case_iterator_ltr()
+ {
$this
->given($string = new LUT('je t\'aime'))
->when($result = iterator_to_array($string))
@@ -496,8 +491,8 @@ class String extends Test\Unit\Suite {
]);
}
- public function case_iterator_rtl ( ) {
-
+ public function case_iterator_rtl()
+ {
$this
->given($string = new LUT('أحبك'))
->when($result = iterator_to_array($string))
@@ -511,8 +506,8 @@ class String extends Test\Unit\Suite {
]);
}
- public function case_to_lower ( ) {
-
+ public function case_to_lower()
+ {
$this
->given($string = new LUT('Σ \'ΑΓΑΠΏ'))
->when($result = $string->toLowerCase())
@@ -531,8 +526,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('je t\'aime');
}
- public function case_to_upper ( ) {
-
+ public function case_to_upper()
+ {
$this
->given($string = new LUT('σ \'αγαπώ'))
->when($result = $string->toUpperCase())
@@ -551,8 +546,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('JE T\'AIME');
}
- public function case_trim_default ( ) {
-
+ public function case_trim_default()
+ {
$this
->given($string = new LUT('💩💩❤️💩💩'))
->when($result = $string->trim('💩'))
@@ -563,8 +558,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('❤️');
}
- public function case_trim_beginning ( ) {
-
+ public function case_trim_beginning()
+ {
$this
->given($string = new LUT('💩💩❤️💩💩'))
->when($result = $string->trim('💩', $string::BEGINNING))
@@ -575,8 +570,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('❤️💩💩');
}
- public function case_trim_end ( ) {
-
+ public function case_trim_end()
+ {
$this
->given($string = new LUT('💩💩❤️💩💩'))
->when($result = $string->trim('💩', $string::END))
@@ -587,8 +582,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('💩💩❤️');
}
- public function case_offset_get_ltr ( ) {
-
+ public function case_offset_get_ltr()
+ {
$this
->given($string = new LUT('je t\'aime'))
->when($result = $string[0])
@@ -602,8 +597,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('e');
}
- public function case_offset_get_rtl ( ) {
-
+ public function case_offset_get_rtl()
+ {
$this
->given($string = new LUT('أحبك'))
->when($result = $string[0])
@@ -617,8 +612,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('ك');
}
- public function case_offset_set ( ) {
-
+ public function case_offset_set()
+ {
$this
->given($string = new LUT('أحبﻙ'))
->when($string[-1] = 'ك')
@@ -627,12 +622,11 @@ class String extends Test\Unit\Suite {
->isEqualTo('أحبك');
}
- public function case_offset_unset ( ) {
-
+ public function case_offset_unset()
+ {
$this
->given($string = new LUT('أحبك😄'))
- ->when(function ( ) use ( $string ) {
-
+ ->when(function () use ($string) {
unset($string[-1]);
})
->then
@@ -640,8 +634,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('أحبك');
}
- public function case_reduce ( ) {
-
+ public function case_reduce()
+ {
$this
->given($string = new LUT('أحبك'))
->when($result = $string->reduce(0, 1))
@@ -652,8 +646,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('أ');
}
- public function case_count ( ) {
-
+ public function case_count()
+ {
$this
->given($string = new LUT('je t\'aime'))
->when($result = count($string))
@@ -674,8 +668,8 @@ class String extends Test\Unit\Suite {
->isEqualTo(1);
}
- public function case_byte_at ( ) {
-
+ public function case_byte_at()
+ {
$this
->given($string = new LUT('💩'))
->when($result = $string->getByteAt(0))
@@ -704,8 +698,8 @@ class String extends Test\Unit\Suite {
->isEqualTo(0xa9);
}
- public function case_bytes_length ( ) {
-
+ public function case_bytes_length()
+ {
$this
->given($string = new LUT('💩'))
->when($result = $string->getBytesLength())
@@ -714,8 +708,8 @@ class String extends Test\Unit\Suite {
->isEqualTo(4);
}
- public function case_get_width ( ) {
-
+ public function case_get_width()
+ {
$this
->given($string = new LUT('💩'))
->when($result = $string->getWidth())
@@ -730,8 +724,8 @@ class String extends Test\Unit\Suite {
->isEqualTo(2);
}
- public function case_get_char_direction ( ) {
-
+ public function case_get_char_direction()
+ {
$this
->when($result = LUT::getCharDirection('A'))
->then
@@ -744,8 +738,8 @@ class String extends Test\Unit\Suite {
->isEqualTo(LUT::RTL);
}
- public function case_get_char_width ( ) {
-
+ public function case_get_char_width()
+ {
$this
->given(
$data = [
@@ -782,10 +776,8 @@ class String extends Test\Unit\Suite {
[0xf900, 2]
]
)
- ->when(function ( ) use ( $data ) {
-
- foreach($data as $datum) {
-
+ ->when(function () use ($data) {
+ foreach ($data as $datum) {
list($code, $width) = $datum;
$this
@@ -797,8 +789,8 @@ class String extends Test\Unit\Suite {
});
}
- public function case_is_char_printable ( ) {
-
+ public function case_is_char_printable()
+ {
$this
->when($result = LUT::isCharPrintable(LUT::fromCode(0x7f)))
->then
@@ -816,8 +808,8 @@ class String extends Test\Unit\Suite {
->isTrue();
}
- public function case_from_code ( ) {
-
+ public function case_from_code()
+ {
$this
// U+0000 to U+007F
->when($result = LUT::fromCode(0x7e))
@@ -844,8 +836,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('💩');
}
- public function case_to_code ( ) {
-
+ public function case_to_code()
+ {
$this
// U+0000 to U+007F
->when($result = LUT::toCode('~'))
@@ -872,8 +864,8 @@ class String extends Test\Unit\Suite {
->isEqualTo(0x1f4a9);
}
- public function case_to_binary_code ( ) {
-
+ public function case_to_binary_code()
+ {
$this
// U+0000 to U+007F
->when($result = LUT::toBinaryCode('~'))
@@ -900,8 +892,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('11110000100111111001001010101001');
}
- public function case_transcode_and_isUtf8 ( ) {
-
+ public function case_transcode_and_isUtf8()
+ {
$this
->given($uΣ = 'Σ')
->when($Σ = LUT::transcode($uΣ, 'UTF-8', 'UTF-16'))
@@ -920,29 +912,26 @@ class String extends Test\Unit\Suite {
->isTrue();
}
- public function case_to_ascii_no_transliterator_no_normalizer ( ) {
-
+ public function case_to_ascii_no_transliterator_no_normalizer()
+ {
$this
->given(
- $this->function->class_exists = function ( $name ) {
-
+ $this->function->class_exists = function ($name) {
return false === in_array($name, ['Transliterator', 'Normalizer']);
},
$string = new LUT('Un été brûlant sur la côte')
)
- ->exception(function ( ) use ( $string ) {
-
+ ->exception(function () use ($string) {
$string->toAscii();
})
->isInstanceOf('Hoa\String\Exception');
}
- public function case_to_ascii_no_transliterator_no_normalizer_try ( ) {
-
+ public function case_to_ascii_no_transliterator_no_normalizer_try()
+ {
$this
->given(
- $this->function->class_exists = function ( $name ) {
-
+ $this->function->class_exists = function ($name) {
return false === in_array($name, ['Transliterator', 'Normalizer']);
},
$string = new LUT('Un été brûlant sur la côte')
@@ -955,12 +944,11 @@ class String extends Test\Unit\Suite {
->isEqualTo('Un ete brulant sur la cote');
}
- public function case_to_ascii_no_transliterator ( ) {
-
+ public function case_to_ascii_no_transliterator()
+ {
$this
->given(
- $this->function->class_exists = function ( $name ) {
-
+ $this->function->class_exists = function ($name) {
return 'Transliterator' !== $name;
},
$string = new LUT('Un été brûlant sur la côte')
@@ -973,8 +961,8 @@ class String extends Test\Unit\Suite {
->isEqualTo('Un ete brulant sur la cote');
}
- public function case_to_ascii ( ) {
-
+ public function case_to_ascii()
+ {
$this
->given(
$strings = [
@@ -1012,9 +1000,8 @@ class String extends Test\Unit\Suite {
=> '(for all) i (element of) N'
]
)
- ->when(function ( ) use ( $strings ) {
-
- foreach($strings as $original => $asciied)
+ ->when(function () use ($strings) {
+ foreach ($strings as $original => $asciied) {
$this
->given($string = new LUT($original))
->when($result = $string->toAscii())
@@ -1023,11 +1010,12 @@ class String extends Test\Unit\Suite {
->isIdenticalTo($string)
->string((string) $result)
->isEqualTo($asciied);
+ }
});
}
- public function case_copy ( ) {
-
+ public function case_copy()
+ {
$this
->given($string = new LUT('foo'))
->when($result = $string->copy())
@@ -1036,8 +1024,8 @@ class String extends Test\Unit\Suite {
->isEqualTo($string);
}
- public function case_toString ( ) {
-
+ public function case_toString()
+ {
$this
->given($datum = $this->sample($this->realdom->regex('/\w{7,42}/')))
->when($result = new LUT($datum))