Back to index

php5  5.3.10
Public Member Functions | Static Public Member Functions | Public Attributes
Collator Class Reference

Collator class. More...

List of all members.

Public Member Functions

 __construct ($locale)
 Create a collator.
 getErrorCode ()
 Get collator's last error code.
 getErrorMessage ()
 Return error text for the last ICU operation.
 compare ($str1, $str2)
 Compare two strings using PHP strcmp() semantics.
 sort ($arr, $sort_flags)
 Equivalent to standard PHP sort() using Collator.
 asort ($arr, $sort_flags)
 Sort array maintaining index association.
 sortWithSortKeys ($arr)
 Equivalent to standard PHP sort() using Collator.
 getAttribute ($attr)
 Get collation attribute value.
 setAttribute ($attr, $val)
 Set collation attribute.
 getStrength ()
 Get current collation strength.
 setStrength ($strength)
 Set collation strength.
 getLocale ($type)
 Get the locale name of the collator.

Static Public Member Functions

static create ($locale)
 Create a collator.

Public Attributes

const ULOC_ACTUAL_LOCALE = 0
 Locale-related constants.
const ULOC_VALID_LOCALE = 1
const ULOC_REQUESTED_LOCALE = 2
const DEFAULT_VALUE = 'UCOL_DEFAULT'
 Valid attribute values.
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'
const FRENCH_COLLATION = 'UCOL_FRENCH_COLLATION'
 Valid attribute names.
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'

Detailed Description

Collator class.

This is a wrapper around ICU Collator C API (declared in ucol.h).

Example:

See also:
http://www.icu-project.org/apiref/icu4c/ucol_8h.html
http://www.icu-project.org/apiref/icu4c/classCollator.html

Definition at line 20 of file collator_api.php.


Constructor & Destructor Documentation

Collator::__construct ( locale)

Create a collator.

Parameters:
string$localeThe 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.
Returns:
Collator New instance of Collator object.

Definition at line 90 of file collator_api.php.

{}

Member Function Documentation

Collator::asort ( arr,
sort_flags 
)

Sort array maintaining index association.

Equivalent to standard PHP asort() using Collator.

Parameters:
array$arrArray of strings to sort
int$sort_flagsOptional sorting type
Returns:
bool true on success or false on failure.
See also:
Collator::sort()

Definition at line 165 of file collator_api.php.

{}
Collator::compare ( str1,
str2 
)

Compare two strings using PHP strcmp() semantics.

Wrapper around ICU ucol_strcoll().

Parameters:
string$str1First string to compare.
string$str2Second string to compare.
Returns:
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.

Definition at line 137 of file collator_api.php.

{}
static Collator::create ( locale) [static]

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().

Returns:
Collator Newly created Collator instance, or null on error.
See also:
__construct()
collator_create()

Definition at line 106 of file collator_api.php.

{}

Here is the caller graph for this function:

Get collation attribute value.

Todo:
Do we want to support other standard PHP sort functions: ksort, rsort, asort?

Wrapper around ICU ucol_getAttribute().

Parameters:
int$attrAttribute to get value for.
Returns:
int Attribute value, or false on error.

Definition at line 192 of file collator_api.php.

{}

Get collator's last error code.

Returns:
int Error code returned by the last Collator method call.

Definition at line 114 of file collator_api.php.

{}

Return error text for the last ICU operation.

Returns:
string Description of an error occured in the last Collator method call.

Definition at line 122 of file collator_api.php.

{}
Collator::getLocale ( type)

Get the locale name of the collator.

Wrapper around ICU ucol_getLocaleByType().

Parameters:
int$typeYou can choose between requested, valid and actual locale (ULOC_REQUESTED_LOCALE, ULOC_VALID_LOCALE, ULOC_ACTUAL_LOCALE, respectively).
Returns:
string Real locale name from which the collation data comes. If the collator was instantiated from rules or an error occured, returns false.

Definition at line 242 of file collator_api.php.

{}

Get current collation strength.

Wrapper around ICU ucol_getStrength().

Returns:
int Current collation strength, or false on error.

Definition at line 213 of file collator_api.php.

{}
Collator::setAttribute ( attr,
val 
)

Set collation attribute.

Wrapper around ICU ucol_setAttribute().

Parameters:
int$attrAttribute.
int$valAttribute value.
Returns:
bool true on success, false otherwise.

Definition at line 204 of file collator_api.php.

{}
Collator::setStrength ( strength)

Set collation strength.

Wrapper around ICU ucol_setStrength().

Parameters:
int$strengthStrength to set.
Returns:
bool true on success, false otherwise.

Definition at line 224 of file collator_api.php.

{}
Collator::sort ( arr,
sort_flags 
)

Equivalent to standard PHP sort() using Collator.

Parameters:
array$arrArray of strings to sort
int$sort_flagsOptional 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.
Returns:
bool true on success or false on failure.

Definition at line 151 of file collator_api.php.

{}

Equivalent to standard PHP sort() using Collator.

Similar to Collator::sort(). Uses ICU ucol_getSortKey() to gain more speed on large arrays.

Parameters:
array$arrArray of strings to sort
Returns:
bool true on success or false on failure.

Definition at line 177 of file collator_api.php.

{}

Member Data Documentation

const Collator::ALTERNATE_HANDLING = 'UCOL_ALTERNATE_HANDLING'

Definition at line 69 of file collator_api.php.

const Collator::CASE_FIRST = 'UCOL_CASE_FIRST'

Definition at line 70 of file collator_api.php.

const Collator::CASE_LEVEL = 'UCOL_CASE_LEVEL'

Definition at line 71 of file collator_api.php.

const Collator::DEFAULT_STRENGTH = 'UCOL_DEFAULT_STRENGTH'

Definition at line 52 of file collator_api.php.

const Collator::DEFAULT_VALUE = 'UCOL_DEFAULT'

Valid attribute values.

See also:
Collator::setAttribute()
collator_set_attribute()

Definition at line 48 of file collator_api.php.

const Collator::FRENCH_COLLATION = 'UCOL_FRENCH_COLLATION'

Valid attribute names.

See also:
Collator::setAttribute()
collator_set_attribute()

Definition at line 68 of file collator_api.php.

const Collator::HIRAGANA_QUATERNARY_MODE = 'UCOL_HIRAGANA_QUATERNARY_MODE'

Definition at line 74 of file collator_api.php.

const Collator::IDENTICAL = 'UCOL_IDENTICAL'

Definition at line 54 of file collator_api.php.

const Collator::LOWER_FIRST = 'UCOL_LOWER_FIRST'

Definition at line 59 of file collator_api.php.

const Collator::NON_IGNORABLE = 'UCOL_NON_IGNORABLE'

Definition at line 58 of file collator_api.php.

const Collator::NORMALIZATION_MODE = 'UCOL_NORMALIZATION_MODE'

Definition at line 72 of file collator_api.php.

const Collator::NUMERIC_COLLATION = 'UCOL_NUMERIC_COLLATION'

Definition at line 75 of file collator_api.php.

const Collator::OFF = 'UCOL_OFF'

Definition at line 55 of file collator_api.php.

const Collator::ON = 'UCOL_ON'

Definition at line 56 of file collator_api.php.

const Collator::PRIMARY = 'UCOL_PRIMARY'

Definition at line 49 of file collator_api.php.

const Collator::QUATERNARY = 'UCOL_QUATERNARY'

Definition at line 53 of file collator_api.php.

const Collator::SECONDARY = 'UCOL_SECONDARY'

Definition at line 50 of file collator_api.php.

const Collator::SHIFTED = 'UCOL_SHIFTED'

Definition at line 57 of file collator_api.php.

const Collator::STRENGTH = 'UCOL_STRENGTH'

Definition at line 73 of file collator_api.php.

const Collator::TERTIARY = 'UCOL_TERTIARY'

Definition at line 51 of file collator_api.php.

Locale-related constants.

These will be moved out of Collator when Locale class is created.

Definition at line 30 of file collator_api.php.

Definition at line 32 of file collator_api.php.

Definition at line 31 of file collator_api.php.

const Collator::UPPER_FIRST = 'UCOL_UPPER_FIRST'

Definition at line 60 of file collator_api.php.


The documentation for this class was generated from the following file: