Rework BCollator API
- Strength is now set once, instead of at each comparison, to improve performance and fix potential locking issues - Add a way to enable "numeric" collation (aka "natural order")
This commit is contained in:
@@ -35,9 +35,9 @@
|
||||
natural number sorting so that 2 is sorted before 10 unlike byte-based
|
||||
sorting.
|
||||
|
||||
\warning This class is not multithread-safe, as Compare() change the
|
||||
ICUCollator (the strength). So if you want to use a BCollator
|
||||
from more than one thread you need to protect it with a lock.
|
||||
\warning This class is not multithread-safe. So if you want to use a
|
||||
BCollator from more than one thread you need to protect it with
|
||||
a lock.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
@@ -121,12 +121,9 @@
|
||||
|
||||
|
||||
/*!
|
||||
\fn void BCollator::SetDefaultStrength(int8 strength)
|
||||
\fn void BCollator::SetStrength(int8 strength)
|
||||
\brief Set the \a strength of the collator.
|
||||
|
||||
Note that the \a strength can also be chosen on a case-by-case basis
|
||||
when calling other methods.
|
||||
|
||||
\param strength The collator class provide four level of \a strength.
|
||||
\li \c B_COLLATE_PRIMARY doesn't differentiate e from é,
|
||||
\li \c B_COLLATE_SECONDARY takes letter accents into account,
|
||||
@@ -138,16 +135,6 @@
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn int8 BCollator::DefaultStrength() const
|
||||
\brief Get the current strength of this catalog.
|
||||
|
||||
\returns The current strength of the catalog.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn void BCollator::SetIgnorePunctuation(bool ignore)
|
||||
\brief Enable or disable punctuation handling.
|
||||
@@ -172,8 +159,21 @@
|
||||
|
||||
|
||||
/*!
|
||||
\fn status_t BCollator::GetSortKey(const char* string, BString* key,
|
||||
int8 strength) const
|
||||
\fn void BCollator::SetNumericSorting(bool ignore)
|
||||
\brief Enable or disable numeric order sorting.
|
||||
|
||||
Numeric sorting enables the collator to identify strings of digits as
|
||||
numbers, and sort them in ascending number. For example, the string "123"
|
||||
is sorted after "234". Numbers and other characters can be mixed in the
|
||||
same string.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn status_t BCollator::GetSortKey(const char* string, BString* key)
|
||||
const
|
||||
\brief Compute the sortkey of a \a string.
|
||||
|
||||
The sortkey is a modified version of the input \a string that you can use
|
||||
@@ -184,7 +184,6 @@
|
||||
|
||||
\param string String from which to compute the sortkey.
|
||||
\param key The resulting sortkey.
|
||||
\param strength The \a strength to use to compute the sortkey.
|
||||
|
||||
\retval B_OK if everything went well.
|
||||
\retval B_ERROR if an error occurred generating the sortkey.
|
||||
@@ -194,17 +193,15 @@
|
||||
|
||||
|
||||
/*!
|
||||
\fn int BCollator::Compare(const char* s1, const char* s2,
|
||||
int8 strength) const
|
||||
\brief Returns the difference betweens the two strings according to the
|
||||
collation defined by the \a strength parameter.
|
||||
\fn int BCollator::Compare(const char* s1, const char* s2)
|
||||
const
|
||||
\brief Returns the difference betweens the two strings.
|
||||
|
||||
This method should be used in place of the strcmp() function to perform
|
||||
locale-aware comparisons.
|
||||
|
||||
\param s1 The first string to compare.
|
||||
\param s2 The second string to compare.
|
||||
\param strength The \a strength to use for the string comparison.
|
||||
|
||||
\returns An integer value representing how the strings compare to each
|
||||
other.
|
||||
@@ -219,8 +216,8 @@
|
||||
|
||||
|
||||
/*!
|
||||
\fn bool BCollator::Equal(const char* s1, const char* s2,
|
||||
int8 strength) const
|
||||
\fn bool BCollator::Equal(const char* s1, const char* s2)
|
||||
const
|
||||
\brief Compares two strings for equality.
|
||||
|
||||
Note that strings that are not byte-by-byte identical may end up being
|
||||
@@ -232,7 +229,6 @@
|
||||
|
||||
\param s1 The first string to compare.
|
||||
\param s2 The second string to compare.
|
||||
\param strength The \a strength to use for the string comparison.
|
||||
|
||||
\returns \c true if the strings are identical, \c false otherwise.
|
||||
|
||||
@@ -241,8 +237,8 @@
|
||||
|
||||
|
||||
/*!
|
||||
\fn bool BCollator::Greater(const char* s1, const char* s2,
|
||||
int8 strength = B_COLLATE_DEFAULT) const
|
||||
\fn bool BCollator::Greater(const char* s1, const char* s2)
|
||||
const
|
||||
\brief Determine if a string is greater than another.
|
||||
|
||||
\note !Greater(s1, s2) is the same as GreaterOrEqual(s2, s1). This means
|
||||
@@ -250,7 +246,6 @@
|
||||
|
||||
\param s1 The first string to compare.
|
||||
\param s2 The second string to compare.
|
||||
\param strength The \a strength to use for the string comparison.
|
||||
|
||||
\returns \c true if s1 is greater than, but not equal to, s2.
|
||||
|
||||
@@ -259,15 +254,14 @@
|
||||
|
||||
|
||||
/*!
|
||||
\fn bool BCollator::GreaterOrEqual(const char* s1, const char* s2,
|
||||
int8 strength = B_COLLATE_DEFAULT) const
|
||||
\fn bool BCollator::GreaterOrEqual(const char* s1, const char* s2)
|
||||
const
|
||||
\brief Determines if one string is greater than another.
|
||||
|
||||
\note !GreaterOrEqual(s1, s2) is the same as Greater(s2, s1).
|
||||
|
||||
\param s1 The first string to compare.
|
||||
\param s2 The second string to compare.
|
||||
\param strength The \a strength to use for the string comparison.
|
||||
|
||||
\returns \c true if s1 is greater or equal than s2.
|
||||
|
||||
@@ -280,9 +274,7 @@
|
||||
\brief Unarchive the collator
|
||||
|
||||
This method allows you to restore a collator that you previously
|
||||
archived. It is faster to archive and unarchive a collator than it is
|
||||
to create a new one up each time you need a BCollator object with the
|
||||
same settings.
|
||||
archived.
|
||||
|
||||
\param archive The message to restore the collator from.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user