1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
|
<?php
#############################################################################
# Object-oriented API
#############################################################################
/**
* Collator class.
*
* This is a wrapper around ICU Collator C API (declared in ucol.h).
*
* Example:
* <code>
*
* </code>
*
* @see http://www.icu-project.org/apiref/icu4c/ucol_8h.html
* @see http://www.icu-project.org/apiref/icu4c/classCollator.html
*
*/
class Collator {
#############################################################################
# Common constants.
#############################################################################
/**
* Locale-related constants.
*
* These will be moved out of Collator when Locale class is created.
*/
const ULOC_ACTUAL_LOCALE = 0;
const ULOC_VALID_LOCALE = 1;
const ULOC_REQUESTED_LOCALE = 2;
/*
* WARNING:
* The values described here are NOT the actual values in PHP code.
* They are references to the ICU C definitions, so the line
* const DEFAULT_STRENGTH = 'UCOL_DEFAULT_STRENGTH';
* actually means that Collator::DEFAULT_STRENGTH is the same as
* UCOL_DEFAULT_STRENGTH constant in the ICU library.
*/
/**
* Valid attribute values.
*
* @see Collator::setAttribute()
* @see collator_set_attribute()
*/
const DEFAULT_VALUE = 'UCOL_DEFAULT';
const PRIMARY = 'UCOL_PRIMARY';
const SECONDARY = 'UCOL_SECONDARY';
const TERTIARY = 'UCOL_TERTIARY';
const DEFAULT_STRENGTH = 'UCOL_DEFAULT_STRENGTH';
const QUATERNARY = 'UCOL_QUATERNARY';
const IDENTICAL = 'UCOL_IDENTICAL';
const OFF = 'UCOL_OFF';
const ON = 'UCOL_ON';
const SHIFTED = 'UCOL_SHIFTED';
const NON_IGNORABLE = 'UCOL_NON_IGNORABLE';
const LOWER_FIRST = 'UCOL_LOWER_FIRST';
const UPPER_FIRST = 'UCOL_UPPER_FIRST';
/**
* Valid attribute names.
*
* @see Collator::setAttribute()
* @see collator_set_attribute()
*/
const FRENCH_COLLATION = 'UCOL_FRENCH_COLLATION';
const ALTERNATE_HANDLING = 'UCOL_ALTERNATE_HANDLING';
const CASE_FIRST = 'UCOL_CASE_FIRST';
const CASE_LEVEL = 'UCOL_CASE_LEVEL';
const NORMALIZATION_MODE = 'UCOL_NORMALIZATION_MODE';
const STRENGTH = 'UCOL_STRENGTH';
const HIRAGANA_QUATERNARY_MODE = 'UCOL_HIRAGANA_QUATERNARY_MODE';
const NUMERIC_COLLATION = 'UCOL_NUMERIC_COLLATION';
/**
* Create a collator
*
* @param string $locale The locale whose collation rules
* should be used. Special values for
* locales can be passed in - if null is
* passed for the locale, the default
* locale collation rules will be used. If
* empty string ("") or "root" are passed,
* UCA rules will be used.
*
* @return Collator New instance of Collator object.
*/
public function __construct( $locale ) {}
/**
* Create a collator
*
* Creates a new instance of Collator.
*
* This method is useful when you prefer just to get null on error,
* as if you called collator_create().
*
* @return Collator Newly created Collator instance,
* or null on error.
*
* @see __construct()
* @see collator_create()
*/
public static function create( $locale ) {}
/**
* Get collator's last error code.
*
* @return int Error code returned by the last
* Collator method call.
*/
public function getErrorCode() {}
/**
* Return error text for the last ICU operation.
*
* @return string Description of an error occurred in the last
* Collator method call.
*/
public function getErrorMessage() {}
/**
* Compare two strings using PHP strcmp() semantics.
*
* Wrapper around ICU ucol_strcoll().
*
* @param string $str1 First string to compare.
* @param string $str2 Second string to compare.
*
* @return int 1 if $str1 is greater than $str2;
* 0 if $str1 is equal to $str2;
* -1 if $str1 is less than $str2.
* On error false is returned.
*/
public function compare( $str1, $str2 ) {}
/**
* Equivalent to standard PHP sort() using Collator.
*
* @param array $arr Array of strings to sort
* @param int $sort_flags Optional sorting type, one of the following:
* - SORT_REGULAR - compare items normally (don't change types)
* - SORT_NUMERIC - compare items numerically
* - SORT_STRING - compare items as strings
* Default sorting type is SORT_REGULAR.
*
* @return bool true on success or false on failure.
*/
public function sort( $arr, $sort_flags ) {}
/**
* Sort array maintaining index association.
*
* Equivalent to standard PHP asort() using Collator.
*
* @param array $arr Array of strings to sort
* @param int $sort_flags Optional sorting type
*
* @return bool true on success or false on failure.
*
* @see Collator::sort()
*/
public function asort( $arr, $sort_flags ) {}
/**
* Equivalent to standard PHP sort() using Collator.
*
* Similar to Collator::sort().
* Uses ICU ucol_getSortKey() to gain more speed on large arrays.
*
* @param array $arr Array of strings to sort
*
* @return bool true on success or false on failure.
*/
public function sortWithSortKeys( $arr ) {}
/**
* @todo Do we want to support other standard PHP sort functions: ksort, rsort, asort?
*/
/**
* Get collation attribute value.
*
* Wrapper around ICU ucol_getAttribute().
*
* @param int $attr Attribute to get value for.
*
* @return int Attribute value, or false on error.
*/
public function getAttribute( $attr ) {}
/**
* Set collation attribute.
*
* Wrapper around ICU ucol_setAttribute().
*
* @param int $attr Attribute.
* @param int $val Attribute value.
*
* @return bool true on success, false otherwise.
*/
public function setAttribute( $attr, $val ) {}
/**
* Get current collation strength.
*
* Wrapper around ICU ucol_getStrength().
*
* @return int Current collation strength, or false on error.
*/
public function getStrength() {}
/**
* Set collation strength.
*
* Wrapper around ICU ucol_setStrength().
*
* @param int $strength Strength to set.
*
* @return bool true on success, false otherwise.
*/
public function setStrength( $strength ) {}
/**
* Get the locale name of the collator.
*
* Wrapper around ICU ucol_getLocaleByType().
*
* @param int $type You can choose between requested, valid
* and actual locale
* (ULOC_REQUESTED_LOCALE,
* ULOC_VALID_LOCALE, ULOC_ACTUAL_LOCALE,
* respectively).
*
* @return string Real locale name from which the
* collation data comes. If the collator
* was instantiated from rules or an error occurred,
* returns false.
*/
public function getLocale( $type ) {}
}
#############################################################################
# Procedural API
#############################################################################
/**
* Create collator.
*
* @param string $locale The locale containing the required
* collation rules. Special values for
* locales can be passed in - if null is
* passed for the locale, the default
* locale collation rules will be used. If
* empty string ("") or "root" are passed,
* UCA rules will be used.
*
* @return Collator New instance of Collator object, or null on error.
*/
function collator_create( $locale ) {}
/**
* Compare two strings.
*
* The strings will be compared using the options already
* specified.
*
* @param Collator $coll Collator object.
* @param string $str1 The first string to compare.
* @param string $str2 The second string to compare.
*
* @return int 1 if $str1 is greater than $str2;
* 0 if $str1 is equal to $str2;
* -1 if $str1 is less than $str2.
* On error false is returned.
*
*/
function collator_compare( $coll, $str1, $str2 ) {}
/**
* Sort array using specified collator.
*
* @param Collator $coll Collator object.
* @param array $arr Array of strings to sort.
* @param int $sort_flags Optional sorting type, one of the following:
* - SORT_REGULAR - compare items normally (don't change types)
* - SORT_NUMERIC - compare items numerically
* - SORT_STRING - compare items as strings
* Default sorting type is SORT_REGULAR.
*
* @return bool true on success or false on failure.
*/
function collator_sort( $coll, $arr, $sort_flags ) {}
/**
* Sort array maintaining index association.
*
* @param Collator $coll Collator object.
* @param array $arr Array of strings to sort.
* @param int $sort_flags Optional sorting type.
*
* @return bool true on success or false on failure.
*
* @see collator_sort()
*/
function collator_asort( $coll, $arr, $sort_flags ) {}
/**
* Sort array using specified collator.
*
* Similar to collator_sort().
* Uses ICU ucol_getSortKey() to gain more speed on large arrays.
*
* @param Collator $coll Collator object.
* @param array $arr Array of strings to sort
*
* @return bool true on success or false on failure.
*/
function collator_sort_with_sort_keys( $coll, $arr ) {}
/**
* Get the locale name of the collator.
*
* @param Collator $coll Collator object.
* @param int $type You can choose between valid and
* actual locale
* (ULOC_VALID_LOCALE, ULOC_ACTUAL_LOCALE
* respectively).
*
* @return string Real locale name from which the
* collation data comes. If the collator
* was instantiated from rules or an error occurred,
* returns false.
*/
function collator_get_locale( $coll, $type ) {}
/**
* Get collation attribute value.
*
* @param Collator $coll Collator object.
* @param int $attr Attribute to get value for.
*
* @return int Attribute value, or false on error.
*/
function collator_get_attribute( $coll, $attr ) {}
/**
* Get current collation strength.
*
* @param Collator $coll Collator object.
*
* @return int Current collation strength, or false on error.
*/
function collator_get_strength( $coll ) {}
/**
* Set collation strength.
*
* @param Collator $coll Collator object.
* @param int $strength Strength to set.
*
* @return bool true on success, false otherwise.
*/
function collator_set_strength( $coll, $strength ) {}
/**
* Set collation attribute.
*
* @param Collator $coll Collator object.
* @param int $attr Attribute.
* @param int $val Attribute value.
*
* @return bool true on success, false otherwise.
*/
function collator_set_attribute( $coll, $attr, $val ) {}
/**
* Get collator's last error code.
*
* @param Collator $coll Collator object.
*
* @return int Error code returned by the last
* Collator API function call.
*/
function collator_get_error_code( $coll ) {}
/**
* Get text for collator's last error code.
*
* @param Collator $coll Collator object.
*
* @return string Description of an error occurred in the last
* Collator API function call.
*/
function collator_get_error_message( $coll ) {}
|