lexical_sort 1.0.2
lexical_sort: ^1.0.2 copied to clipboard
Lexicographic and natural sort comparators for Dart, ported from the lexical_sort Rust crate.
// ignore_for_file: avoid_print
import 'package:lexical_sort/lexical_sort.dart';
void main() {
print(naturalLexicalCmp('50', '100') < 0); // true — 50 < 100
print(naturalLexicalCmp('ß', 'world') < 0); // true — ß → ss, before world
print(naturalLexicalCmp('é', 'hello') < 0); // true — é → e, before hello
print(naturalLexicalCmp('B!', 'é') < 0); // true — non-alnum before alnum
print(naturalLexicalCmp('.', '50') < 0); // true — non-alnum before alnum
print(lexicalCmp('aaa', 'AAb') < 0); // true — case-insensitive
print(lexicalCmp('äáa', 'aab') < 0); // true — ä → a, sorts before aab
print(naturalCmp('T-1', 'T-5') < 0); // true
print(onlyAlnumCmp('_ad', '_æ') < 0); // true — non-alnum skipped
print(naturalLexicalOnlyAlnumCmp('T-27a', 'T27b') < 0); // true
// naturalLexicalCmp vs Dart's default String.compareTo:
//
// input: ['ß', 'é', '100', 'hello', 'world', '50', '.', 'B!']
//
// naturalLexicalCmp: [., 50, 100, B!, é, hello, ß, world]
// String.compareTo: [!, 100, 50, B, hello, world, ß, é, .]
// ^ ^^^^^
// numbers out of order accents and punct at wrong end
}