compare method
Compare two strings in a locale-dependant manner.
The CollationOptions.usage can specify whether to use this for searching
for a string, or sorting a list of strings. The
CollationOptions.sensitivity regulates how exact the comparison should
be. Setting CollationOptions.numeric means that numbers are not sorted
alphabetically, but by their value. The
CollationOptions.caseFirst parameter sets if upper or lowercase letters
should take preference.
The return value is according to the Comparable interface.
import 'package:intl4x/collation.dart';
void main() {
final collation = Collation(locale: Locale('de'));
final list = ['a', 'ä', 'b'];
list.sort(collation.compare);
print(list); // Prints [a, b, ä]
}
Implementation
int compare(String a, String b) {
if (isInTest) {
return a.compareTo(b);
} else {
return _collationImpl.compareImpl(a, b);
}
}