aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2013-08-06 15:38:07 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2013-08-06 15:38:07 +0200
commita61754b26cb609a7e699b7d7e6ab321707b96377 (patch)
tree1eddd26d79a840dad58821fb7382cf082c280e0d
parentd159e94e7c54e1358b2cd9bdd8584f9ad69069a0 (diff)
downloadUstring-a61754b26cb609a7e699b7d7e6ab321707b96377.zip
Ustring-a61754b26cb609a7e699b7d7e6ab321707b96377.tar.gz
Ustring-a61754b26cb609a7e699b7d7e6ab321707b96377.tar.bz2
compareTo() uses \Collator if exists.
-rw-r--r--String.php30
-rw-r--r--composer.json2
2 files changed, 28 insertions, 4 deletions
diff --git a/String.php b/String.php
index 8521229..09c2dc9 100644
--- a/String.php
+++ b/String.php
@@ -160,14 +160,21 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
*
* @var \Hoa\String string
*/
- protected $_string = null;
+ protected $_string = null;
/**
* Direction. Please see self::LTR and self::RTL constants.
*
* @var \Hoa\String int
*/
- protected $_direction = null;
+ protected $_direction = null;
+
+ /**
+ * Collator.
+ *
+ * @var \Collator object
+ */
+ protected static $_collator = null;
@@ -270,7 +277,24 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
*/
public function compareTo ( $string ) {
- return strcmp($this->_string, (string) $string);
+ if(false === class_exists('Collator', false))
+ return strcmp($this->_string, (string) $string);
+
+ return static::getCollator()->compare($this->_string, $string);
+ }
+
+ /**
+ * Get collator.
+ *
+ * @access public
+ * @return \Collator
+ */
+ public static function getCollator ( ) {
+
+ if(null === static::$_collator)
+ static::$_collator = new \Collator(setlocale(LC_COLLATE, null));
+
+ return static::$_collator;
}
/**
diff --git a/composer.json b/composer.json
index 909f7d3..03cdf92 100644
--- a/composer.json
+++ b/composer.json
@@ -27,6 +27,6 @@
},
"minimum-stability": "dev",
"suggest": {
- "ext-intl" : "To get a better Hoa\\String::toAscii()."
+ "ext-intl" : "To get a better Hoa\\String::toAscii() and Hoa\\String::compareTo()."
}
}