#sorting #order #human #natural

human-sort

Human sort (natural sort) implementation

16 releases

0.2.2 Apr 14, 2019
0.2.1 Feb 5, 2019
0.1.14 Jan 28, 2019

#720 in Algorithms

Download history 2904/week @ 2024-06-15 2755/week @ 2024-06-22 2183/week @ 2024-06-29 2568/week @ 2024-07-06 2483/week @ 2024-07-13 2712/week @ 2024-07-20 2584/week @ 2024-07-27 3141/week @ 2024-08-03 3284/week @ 2024-08-10 3546/week @ 2024-08-17 2306/week @ 2024-08-24 2792/week @ 2024-08-31 2083/week @ 2024-09-07 1834/week @ 2024-09-14 2610/week @ 2024-09-21 2423/week @ 2024-09-28

9,559 downloads per month
Used in 31 crates (15 directly)

MIT license

6KB
61 lines

Crates.io Build Status

human-sort

Utilities to sort and compare strings with numeric symbols in human-friendly order.

It built over iterators and compare string slices char by char (except for numerals) until the first difference found without creating Strings or another structures with whole data from provided &str, so doesn't require lots of memory.

Examples

use human_sort::sort;

let mut arr = ["file10.txt", "file2.txt", "file1.txt"];
sort(&mut arr);

assert_eq!(arr, ["file1.txt", "file2.txt", "file10.txt"]);
use std::cmp::Ordering;
use human_sort::compare;

assert_eq!(compare("item200", "item3"), Ordering::Greater);

License

Licensed under MIT license.


lib.rs:

Utilities to sort and compare strings with numeric symbols in human-friendly order.

It built over iterators and compare string slices char by char (except for numerals) until the first difference found without creating Strings or another structures with whole data from provided &str, so doesn't require lots of memory.

Examples

use human_sort::sort;

let mut arr = ["file10.txt", "file2.txt", "file1.txt"];
sort(&mut arr);

assert_eq!(arr, ["file1.txt", "file2.txt", "file10.txt"]);
use std::cmp::Ordering;
use human_sort::compare;

assert_eq!(compare("item200", "item3"), Ordering::Greater);

No runtime deps