/** * Sorts the elements in an array of Unicode or ASCII strings, in the ascending order, case-insensitively, using * natural order comparison. * * To illustrate natural order with an example, an array with strings "a100", "a20", "a3" would be sorted into the * same array with `sortUStringsCi` method, but as "a3", "a20", "a100" with this method, which is the order a human * being would choose. * * @param array $array The array to be sorted. * @param bitfield $collationFlags **OPTIONAL. Default is** `CUString::COLLATION_DEFAULT`. The Unicode collation * option(s) to be used for string comparison. See the [CUString](CUString.html) class for information on collation * options. * @param CULocale $inLocale **OPTIONAL. Default is** *the application's default locale*. The locale in which * strings are to be compared with each other. * * @return void * * @link CUString.html CUString */ public static function sortUStringsNatCi($array, $collationFlags = CUString::COLLATION_DEFAULT, CULocale $inLocale = null) { assert('is_carray($array)', vs(isset($this), get_defined_vars())); $array = splarray($array); $locale = isset($inLocale) ? $inLocale->name() : CULocale::defaultLocaleName(); $coll = CUString::collatorObject(true, true, $locale, $collationFlags); $pArray = self::toPArray($array); $res = $coll->sort($pArray); assert('$res', vs(isset($this), get_defined_vars())); self::assignArrayToMap($array, $pArray); }
/** * Determines the order in which two strings should appear in a place where it matters, assuming the ascending * order, comparing the strings case-insensitively, and using natural order comparison. * * To illustrate natural order with an example, the strings "a100" and "a20" would get ordered as such with * `compareCi` method, but as "a20" and "a100" with this method, which is the order a human being would choose. * * @param string $string The first string for comparison. * @param string $toString The second string for comparison. * @param bitfield $collationFlags **OPTIONAL. Default is** `COLLATION_DEFAULT`. The collation option(s) to be * used for the comparison. The available collation options are `COLLATION_IGNORE_ACCENTS`, * `COLLATION_IGNORE_NONWORD`, `COLLATION_UPPERCASE_FIRST`, and `COLLATION_FRENCH` (see [Summary](#summary)). * @param CULocale $inLocale **OPTIONAL. Default is** *the application's default locale*. The locale in which the * strings are to be compared. * * @return int `-1` if the first string should go before the second string, `1` if the other way around, and `0` if * the two strings are equal, ignoring the letter case of the characters. */ public static function compareNatCi($string, $toString, $collationFlags = self::COLLATION_DEFAULT, CULocale $inLocale = null) { assert('is_cstring($string) && is_cstring($toString) && is_bitfield($collationFlags)', vs(isset($this), get_defined_vars())); $locale = isset($inLocale) ? $inLocale->name() : CULocale::defaultLocaleName(); $coll = self::collatorObject(true, true, $locale, $collationFlags); $res = $coll->compare($string, $toString); if (is_int($res)) { return $res; } else { assert('false', vs(isset($this), get_defined_vars())); return -1; } }
public function testAddKeyword() { $locale = new CULocale("de_DE"); $locale->addKeyword("keyword0", "value0"); $locale->addKeyword("keyword1", "value1"); $this->assertTrue($locale->name()->equals("de_DE@keyword0=value0;keyword1=value1")); }
/** * Returns the human-readable name of a time zone, written in the language of a specified locale. * * @param enum $style **OPTIONAL. Default is** `STYLE_LONG`. The display style of the name. The available styles * are `STYLE_SHORT` and `STYLE_LONG`. * @param CULocale $inLocale **OPTIONAL. Default is** *the application's default locale*. The locale in which the * name is to be displayed. * * @return CUStringObject The human-readable name of the time zone. */ public function dispName($style = self::STYLE_LONG, CULocale $inLocale = null) { assert('is_enum($style)', vs(isset($this), get_defined_vars())); $itzStyle; switch ($style) { case self::STYLE_SHORT: $itzStyle = IntlTimeZone::DISPLAY_SHORT; break; case self::STYLE_LONG: $itzStyle = IntlTimeZone::DISPLAY_LONG; break; default: assert('false', vs(isset($this), get_defined_vars())); break; } $itz = $this->ITimeZone(); $locale = isset($inLocale) ? $inLocale->name() : CULocale::defaultLocaleName(); $dispName = $itz->getDisplayName(false, $itzStyle, $locale); if (is_cstring($dispName)) { return $dispName; } else { assert('false', vs(isset($this), get_defined_vars())); return ""; } }
/** * Formats a point in time as a string in a specified time zone according to a specified pattern and the formatting * rules used in the default or some other locale and returns the formatted string. * * The formatting patterns that you can use to format a point in time with this method are described in * [Date Format Patterns](http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns) of the Unicode * Technical Standard #35. * * @param CTime $time The point in time to be formatted. * @param CTimeZone $timeZone The time zone in which the components in the resulting string are to appear. * @param string $pattern The formatting pattern. * @param CULocale $inLocale **OPTIONAL. Default is** *the application's default locale*. The locale in which the * point in time is to be formatted. * * @return CUStringObject A string with the formatted point in time. */ public static function timeWithPattern(CTime $time, CTimeZone $timeZone, $pattern, CULocale $inLocale = null) { assert('is_cstring($pattern)', vs(isset($this), get_defined_vars())); $locale = isset($inLocale) ? $inLocale->name() : CULocale::defaultLocaleName(); $intlDateFormatter = new IntlDateFormatter($locale, IntlDateFormatter::FULL, IntlDateFormatter::FULL, $timeZone->ITimeZone(), null, $pattern); $strTime = $intlDateFormatter->format($time->UTime()); if (is_cstring($strTime)) { return $strTime; } else { assert('false', vs(isset($this), get_defined_vars())); return ""; } }