/**
     * Test for the sort feature of country list
     */
    public function testFetchTranslatedNamesSort()
    {
        $translatedCountriesList = array(
            'FR' => 'France',
            'GB' => 'Royaume-uni',
            'DE' => 'Allemagne',
            'NO' => 'Norvège' );

        ezpINIHelper::setINISetting( array( 'fre-FR.ini', 'share/locale' ), 'CountryNames', 'Countries', $translatedCountriesList );
        ezpINIHelper::setINISetting( 'site.ini', 'RegionalSettings', 'Locale', 'fre-FR' );

        $countries = eZCountryType::fetchCountryList();
        $this->assertInternalType( 'array', $countries, "eZCountryType::fetchCountryList() didn't return an array" );

        $countryListIsSorted = true;
        foreach( $countries as $country )
        {
            if ( !isset( $previousCountry ) )
            {
                $previousCountry = $country;
                continue;
            }

            if ( strcoll( $previousCountry['Name'], $country['Name'] ) > 0 )
            {
                $countryListIsSorted = false;
                break;
            }
        }

        ezpINIHelper::restoreINISettings();
        $this->assertTrue( $countryListIsSorted, "Country list isn't sorted" );
    }
Example #2
0
 public static function postprocessDefinition(&$machine_def)
 {
     // Make sure the names are always set
     if (!empty($machine_def['properties'])) {
         foreach ($machine_def['properties'] as $p_name => &$property) {
             if (empty($property['name'])) {
                 $property['name'] = $p_name;
             }
         }
         unset($property);
     }
     if (!empty($machine_def['actions'])) {
         foreach ($machine_def['actions'] as $a_name => &$action) {
             if (empty($action['name'])) {
                 $action['name'] = $a_name;
             }
         }
         unset($action);
         // Sort actions, so they appear everywhere in defined order
         // (readers may provide them in random order)
         uasort($machine_def['actions'], function ($a, $b) {
             $aw = isset($a['weight']) ? $a['weight'] : 50;
             $bw = isset($b['weight']) ? $b['weight'] : 50;
             if ($aw == $bw) {
                 return strcoll(isset($a['label']) ? $a['label'] : $a['name'], isset($b['label']) ? $b['label'] : $b['name']);
             } else {
                 return $aw - $bw;
             }
         });
     }
 }
Example #3
0
 private function cmp($aitem, $bitem)
 {
     if (!array_key_exists($this->_sortKey, $aitem)) {
         return -$this->_sortVal;
     } elseif (!array_key_exists($this->_sortKey, $bitem)) {
         return -$this->_sortVal;
     }
     if (is_string($aitem[$this->_sortKey]) && is_string($bitem[$this->_sortKey])) {
         return strcoll($aitem[$this->_sortKey], $bitem[$this->_sortKey]) * $this->_sortVal;
     } else {
         return $aitem[$this->_sortKey] > $bitem[$this->_sortKey] ? $this->_sortVal : -$this->_sortVal;
     }
 }
Example #4
0
 /**
  * Helper method for uasort to sort applications by name.
  *
  * @param string $a
  * @param string $a
  *
  * @return integer
  */
 protected function _sortByName($a, $b)
 {
     return strcoll(_($a['name']), _($b['name']));
 }
 /**
  * Compare two strings
  */
 function strCmp($a, $b)
 {
     global $ilCollator;
     if (is_object($ilCollator)) {
         return $ilCollator->compare(ilStr::strToUpper($a), ilStr::strToUpper($b)) > 0;
     } else {
         return strcoll(ilStr::strToUpper($a), ilStr::strToUpper($b)) > 0;
     }
 }
Example #6
0
 /**
  * Callback for uasort() that implements correct
  * locale-aware case-sensitive sorting
  */
 protected function sort_folder_comparator($str1, $str2)
 {
     $path1 = explode($this->delimiter, $str1);
     $path2 = explode($this->delimiter, $str2);
     foreach ($path1 as $idx => $folder1) {
         $folder2 = $path2[$idx];
         if ($folder1 === $folder2) {
             continue;
         }
         return strcoll($folder1, $folder2);
     }
 }
 /**
  * Compare function for ordering by name in order_definitions().
  *
  * @param $first WPCF_Field_Definition_Abstract
  * @param $second WPCF_Field_Definition_Abstract
  *
  * @return int
  */
 public function compare_definitions_by_name($first, $second)
 {
     return strcoll(strtolower($first->get_name()), strtolower($second->get_name()));
 }
function strcmp_lok($teksto1, $teksto2)
{
    return strcoll($teksto1, $teksto2);
}
Example #9
0
 /**
  * Comparison function for sorting notes by notepad name.
  *
  * @param array $a  Note one.
  * @param array $b  Note two.
  *
  * @return integer  1 if note one is greater, -1 if note two is greater;
  *                  0 if they are equal.
  */
 protected static function _sortByNotepad($a, $b)
 {
     $aowner = $a['memolist_id'];
     $bowner = $b['memolist_id'];
     $ashare = $GLOBALS['mnemo_shares']->getShare($aowner);
     $bshare = $GLOBALS['mnemo_shares']->getShare($bowner);
     if ($aowner != $ashare->get('owner')) {
         $aowner = $ashare->get('name');
     }
     if ($bowner != $bshare->get('owner')) {
         $bowner = $bshare->get('name');
     }
     return strcoll($aowner, $bowner);
 }
Example #10
0
<?php

setlocale(LC_COLLATE, 'NL');
echo strcoll("Hello World!", "Hello World!");
echo "<br>";
setlocale(LC_COLLATE, 'en_US');
echo strcoll("Hello World!", "Hello World!");
Example #11
0
 protected function _sortCategoryArrayByName($a, $b)
 {
     return strcoll($a->getName(), $b->getName());
 }
Example #12
0
 /**
  * Helper method to sort an array of tickets.
  *
  * Used as callback to usort().
  *
  * @param array $a         The first ticket to compare.
  * @param array $b         The second ticket to compare.
  * @param string $sortby   The field to sort by. If null, uses the field
  *                         from self::sortBy().
  * @param string $sortdir  The direction to sort. If null, uses the value
  *                         from self::sortDir().
  *
  * @return integer
  */
 protected static function _sort($a, $b, $sortby = null, $sortdir = null)
 {
     if (is_null($sortby)) {
         $sortby = self::$_sortBy;
     }
     if (is_null($sortdir)) {
         $sortdir = self::$_sortDir;
     }
     if (is_array($sortby)) {
         if (!isset($a[$sortby[0]])) {
             $a[$sortby[0]] = null;
         }
         if (!isset($b[$sortby[0]])) {
             $b[$sortby[0]] = null;
         }
         if (!count($sortby)) {
             return 0;
         }
         if ($a['sort_by'][$sortby[0]] > $b['sort_by'][$sortby[0]]) {
             return $sortdir[0] ? -1 : 1;
         }
         if ($a['sort_by'][$sortby[0]] === $b['sort_by'][$sortby[0]]) {
             array_shift($sortby);
             array_shift($sortdir);
             return self::_sort($a, $b, $sortby, $sortdir);
         }
         return $sortdir[0] ? 1 : -1;
     }
     $a_val = isset($a['sort_by'][$sortby]) ? $a['sort_by'][$sortby] : null;
     $b_val = isset($b['sort_by'][$sortby]) ? $b['sort_by'][$sortby] : null;
     // Take care of the simplest case first
     if ($a_val === $b_val) {
         return 0;
     }
     if ((is_numeric($a_val) || is_null($a_val)) && (is_numeric($b_val) || is_null($b_val))) {
         // Numeric comparison
         return (int) ($sortdir ? $b_val > $a_val : $a_val > $b_val);
     }
     // Some special case sorting
     if (is_array($a_val) || is_array($b_val)) {
         $a_val = implode('', $a_val);
         $b_val = implode('', $b_val);
     }
     // String comparison
     return $sortdir ? strcoll($b_val, $a_val) : strcoll($a_val, $b_val);
 }
Example #13
0
 /**
  * (PHP 4 &gt;= 4.0.5, PHP 5)<br/>
  * Locale based string comparison
  * @link http://php.net/manual/en/function.strcoll.php
  * @param string $string1 <p>
  * The first string.
  * </p>
  * @param string $string2 <p>
  * The second string.
  * </p>
  * @return int &lt; 0 if <i>string1</i> is less than
  * <i>string2</i>; &gt; 0 if
  * <i>string1</i> is greater than
  * <i>string2</i>, and 0 if they are equal.
  */
 static function coll($string1, $string2)
 {
     return strcoll($string1, $string2);
 }
 /**
  * sub-function to sort an array
  *
  * @param	array	$a
  * @param	array	$b
  *
  * @return	boolean	true on success / false on error
  * @static
  * 
  */
 public static function sort_func($a, $b)
 {
     global $array_sortby, $array_sortorder;
     // this comparison should give optimal results if
     // locale is provided and mb string functions are supported
     if ($array_sortorder == "asc") {
         return ilStr::strCmp($a[$array_sortby], $b[$array_sortby]);
     }
     if ($array_sortorder == "desc") {
         return !ilStr::strCmp($a[$array_sortby], $b[$array_sortby]);
         return strcoll(ilStr::strToUpper($b[$array_sortby]), ilStr::strToUpper($a[$array_sortby]));
     }
 }
Example #15
0
 /**
  * Used with usort() to sort events based on their start times.
  */
 protected static function _sortEventStartTime($a, $b)
 {
     $diff = $a->start->compareDateTime($b->start);
     if ($diff == 0) {
         return strcoll($a->title, $b->title);
     } else {
         return $diff;
     }
 }
Example #16
0
 /**
  * The comparison function used to sort the elements
  *
  * @param mixed $a an element in the list
  * @param mixed $b an element in the list
  * @return int
  */
 public function compare($a, $b)
 {
     if ($this->_dir === SORT_ASC) {
         list($a, $b) = [$b, $a];
     }
     $callback = $this->_callback;
     $a = $callback($a);
     $b = $callback($b);
     if ($this->_type === SORT_NUMERIC) {
         return $a - $b;
     }
     if ($this->_type === SORT_NATURAL) {
         return strnatcmp($a, $b);
     }
     if ($this->_type === SORT_STRING) {
         return strcmp($a, $b);
     }
     return strcoll($a, $b);
 }
Example #17
0
/**
 * @param string $a
 * @param string $b
 * @return bool strcoll()-like result
 */
function asearch_unhtml_strcoll($a, $b)
{
    return strcoll(asearch_unhtmlentities($a), asearch_unhtmlentities($b));
}
Example #18
0
/**
 * Compare two strings or numbers. Return values as strcmp().
 **/
function myCompare($arrA, $arrB, $caseSensitive = false)
{
    $a = $arrA[$_GET["sort"]];
    $b = $arrB[$_GET["sort"]];
    // sort .. first
    if ($arrA["isBack"]) {
        return -1;
    }
    if ($arrB["isBack"]) {
        return 1;
    }
    // sort directories above everything else
    if ($arrA["isDirectory"] != $arrB["isDirectory"]) {
        $result = $arrB["isDirectory"] - $arrA["isDirectory"];
    } else {
        if ($arrA["isDirectory"] && $arrB["isDirectory"] && ($_GET["sort"] == "type" || $_GET["sort"] == "size")) {
            $result = 0;
        } else {
            if (is_string($a) or is_string($b)) {
                if (!$caseSensitive) {
                    $a = strtoupper($a);
                    $b = strtoupper($b);
                }
                $result = strcoll($a, $b);
            } else {
                $result = $a - $b;
            }
        }
    }
    if (strtolower($_GET["order"]) == "desc") {
        return -$result;
    } else {
        return $result;
    }
}
Example #19
0
 /**
  * Sorting Method
  *
  * @param Mage_Catalog_Model_Category $arg1
  * @param Mage_Catalog_Model_Category $arg2
  * @return int
  * @deprecated
  */
 protected function _sortCategoryArrayByName($arg1, $arg2)
 {
     return strcoll($arg1->getName(), $arg2->getName());
 }
Example #20
0
 /**
  * Get a list of items from a facet.
  *
  * @param string $facet    which facet we're searching in
  * @param string $category which subfacet the search applies to
  * @param string $sort     how are we ranking these? || 'index'
  * @param string $query    is there a specific query? No = wildcard
  *
  * @return array           Array indexed by value with text of displayText and
  * count
  */
 protected function getFacetList($facet, $category = null, $sort = 'count', $query = '[* TO *]')
 {
     $results = $this->getServiceLocator()->get('VuFind\\SearchResultsPluginManager')->get('Solr');
     $params = $results->getParams();
     $params->addFacet($facet);
     if ($category != null) {
         $query = $category . ':' . $query;
     } else {
         $query = $facet . ':' . $query;
     }
     $params->setOverrideQuery($query);
     $params->getOptions()->disableHighlighting();
     $params->getOptions()->spellcheckEnabled(false);
     // Get limit from config
     $params->setFacetLimit($this->config->Browse->result_limit);
     $params->setLimit(0);
     // Facet prefix
     if ($this->params()->fromQuery('facet_prefix')) {
         $params->setFacetPrefix($this->params()->fromQuery('facet_prefix'));
     }
     $params->setFacetSort($sort);
     $result = $results->getFacetList();
     if (isset($result[$facet])) {
         // Sort facets alphabetically if configured to do so:
         if (isset($this->config->Browse->alphabetical_order) && $this->config->Browse->alphabetical_order) {
             $callback = function ($a, $b) {
                 return strcoll($a['displayText'], $b['displayText']);
             };
             usort($result[$facet]['list'], $callback);
         }
         return $result[$facet]['list'];
     } else {
         return [];
     }
 }
 /**
  * Compares its two arguments for order. Returns a negative integer, 
  * zero, or a positive integer as the first argument is less than, 
  * equal to, or greater than the second.
  *
  * @param   string a
  * @param   string b
  * @return  int
  */
 public function compare($a, $b)
 {
     setlocale(LC_COLLATE, $this->locale);
     return strcoll($a, $b);
 }
Example #22
0
 public static function localeCompare($that)
 {
     $obj = jsrt::this();
     return js_int(strcoll($obj->toStr()->value, $that->toStr()->value));
 }
Example #23
0
var_dump(strcasecmp("a", "_"));
var_dump(strcasecmp("A", "_"));
var_dump(strcasecmp("@", "`"));
var_dump(strcasecmp("`", "@"));
var_dump(strcasecmp("a", "a0"));
var_dump(strcasecmp("a", "A0"));
var_dump(strcasecmp("A", "a0"));
var_dump(strcasecmp("A", "A0"));
var_dump(strcasecmp("a0", "a"));
var_dump(strcasecmp("a0", "A"));
var_dump(strcasecmp("A0", "a"));
var_dump(strcasecmp("A0", "A"));
var_dump(strncasecmp("a", "Ab", 1));
var_dump(strnatcasecmp("a", "Ab"));
var_dump(strcoll("a", "b") < 0);
var_dump(strcoll("a", "A") > 0);
var_dump(substr_compare("abcde", "bc", 1, 2));
var_dump(substr_compare("abcde", "de", -2, 2));
var_dump(substr_compare("abcde", "bcg", 1, 2));
var_dump(substr_compare("abcde", "BC", 1, 2, true));
var_dump(substr_compare("abcde", "bc", 1, 3));
var_dump(substr_compare("abcde", "cd", 1, 2));
$email = "*****@*****.**";
var_dump(strchr($email, "@"));
$text = "Line 1\nLine 2\nLine 3";
var_dump(strrchr($text, 10));
$email = "*****@*****.**";
var_dump(strstr($email, "@"));
var_dump(strstr($email, "@", true));
var_dump(strstr($email, "@", false));
var_dump(stristr("Hello World!", "earth"));
Example #24
0
 /**
  * UTF-8/LOCALE aware alternative to strcmp
  * A case sensitive string comparison
  *
  * @param   string  $str1    string 1 to compare
  * @param   string  $str2    string 2 to compare
  * @param   mixed   $locale  The locale used by strcoll or false to use classical comparison
  *
  * @return  integer  < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.
  *
  * @see     http://www.php.net/strcmp
  * @see     http://www.php.net/strcoll
  * @see     http://www.php.net/setlocale
  * @since   11.1
  */
 public static function strcmp($str1, $str2, $locale = false)
 {
     if ($locale) {
         // Get current locale
         $locale0 = setlocale(LC_COLLATE, 0);
         if (!($locale = setlocale(LC_COLLATE, $locale))) {
             $locale = $locale0;
         }
         // See if we have successfully set locale to UTF-8
         if (!stristr($locale, 'UTF-8') && stristr($locale, '_') && preg_match('~\\.(\\d+)$~', $locale, $m)) {
             $encoding = 'CP' . $m[1];
         } elseif (stristr($locale, 'UTF-8')) {
             $encoding = 'UTF-8';
         } else {
             $encoding = 'nonrecodable';
         }
         // If we successfully set encoding it to utf-8 or encoding is sth weird don't recode
         if ($encoding == 'UTF-8' || $encoding == 'nonrecodable') {
             return strcoll($str1, $str2);
         } else {
             return strcoll(self::transcode($str1, 'UTF-8', $encoding), self::transcode($str2, 'UTF-8', $encoding));
         }
     } else {
         return strcmp($str1, $str2);
     }
 }
Example #25
0
 /**
  * Sort callback used by fetchTranslatedNames to compare two country arrays
  *
  * @param array $a Country 1
  * @param array $b Country 2
  * @return bool
  */
 protected static function compareCountryNames( $a, $b )
 {
     return strcoll( $a["Name"], $b["Name"] );
 }
Example #26
0
 /**
  * Compare this time zone to the parameter. The two are compared first on
  * their offsets, and then by name.
  */
 function compare($zone)
 {
     $result = $this->utc_offset > $zone->utc_offset ? 1 : ($zone->utc_offset > $this->utc_offset ? -1 : 0);
     $result = $result == 0 ? strcoll($this->name, $zone->name) : $result;
     return $result == 0 ? 0 : ($result > 0 ? 1 : -1);
 }
 /**
  * Sorts the two records based upon many fields.
  *
  * This method should not be called itself, please call $sort instead.
  * It has been marked as access private as such.
  *
  * @access private
  * @param stdClass $a
  * @param stdClass $b
  * @return int
  */
 public function sort_by_many_fields($a, $b)
 {
     foreach ($this->sortfields as $field => $mult) {
         // Nulls first.
         if (is_null($a->{$field}) && !is_null($b->{$field})) {
             return -$mult;
         }
         if (is_null($b->{$field}) && !is_null($a->{$field})) {
             return $mult;
         }
         if (is_string($a->{$field}) || is_string($b->{$field})) {
             // String fields.
             if ($cmp = strcoll($a->{$field}, $b->{$field})) {
                 return $mult * $cmp;
             }
         } else {
             // Int fields.
             if ($a->{$field} > $b->{$field}) {
                 return $mult;
             }
             if ($a->{$field} < $b->{$field}) {
                 return -$mult;
             }
         }
     }
     return 0;
 }
Example #28
0
 public static function strcmp($str1, $str2, $locale = false)
 {
     if ($locale) {
         $locale0 = setlocale(LC_COLLATE, 0);
         if (!($locale = setlocale(LC_COLLATE, $locale))) {
             $locale = $locale0;
         }
         if (!stristr($locale, 'UTF-8') && stristr($locale, '_') && preg_match('~\\.(\\d+)$~', $locale, $m)) {
             $encoding = 'CP' . $m[1];
         } elseif (stristr($locale, 'UTF-8')) {
             $encoding = 'UTF-8';
         } else {
             $encoding = 'nonrecodable';
         }
         if ($encoding == 'UTF-8' || $encoding == 'nonrecodable') {
             return strcoll($str1, $str2);
         } else {
             return strcoll(self::transcode($str1, 'UTF-8', $encoding), self::transcode($str2, 'UTF-8', $encoding));
         }
     } else {
         return strcmp($str1, $str2);
     }
 }
 /**
  * Compare the labels of two schema types or properties for localized sort purposes
  *
  * @param array $a: first type/property definition array
  * @param array $b: second type/property definition array
  * @return int
  */
 protected function compareLabels($a, $b)
 {
     return strcoll($a['label'], $b['label']);
 }
Example #30
0
 private function _sortVersions($a, $b)
 {
     $a_number = (string) (int) $a['name'][0] === $a['name'][0];
     $b_number = (string) (int) $b['name'][0] === $b['name'][0];
     if ($a_number && $b_number) {
         return version_compare($b['name'], $a['name']);
     }
     if (!$a_number && !$b_number) {
         return strcoll($b['name'], $a['name']);
     }
     return $a_number ? 1 : -1;
 }