sourcefrog / natsort Goto Github PK
View Code? Open in Web Editor NEWnatural sort order string comparison: "a1" < "a12"
natural sort order string comparison: "a1" < "a12"
Replace the obsolete Travis CI config with GitHub Actions.
The comment says:
The longest run of digits wins. That aside, the greatest
value wins, but we can't know that it will until we've scanned
both numbers to know that they have the same magnitude,
so we remember it in BIAS.
It should be the "longest run of digits ignoring leading zeros wins". E.g., given:
5
8
007
It should sort as 5, 007, 8 and not as 5, 8, 007.
Please note that I'm responding just based on a quick look at the source code.
This is more of a comment than a problem.
The algorithm in JavaScript is case-sensitive (which means output will be ["a", "c", "B"] instead of ["a", "B", "c"].
A solution within the function could be at the very beginning of declaration:
function natcompare(a, b) { a = a?.toLowerCase(); b = b?.toLowerCase(); var ia = 0, ib = 0; ...
Or you have to call natcompare with lower-case text (natcompare(a..toLowerCase(), b.toLowerCase())
First of all thanks for your work.
We use it in MaterialAudiobookPlayer to compare file names. But recently a problem came up.
When a String start with zeros, the ordering gets wrong. I wrote a small unit test to demonstrate it here.
String first = "00 I";
String second = "01 I";
assertTrue(NaturalOrderComparator.naturalCompare(first, second) < 0);
This one fails.
At 76b9abc:
% make test
ccache cc -Wall -g -Werror -c -o strnatcmp.o strnatcmp.c
ccache cc -Wall -g -Werror -c -o natsort.o natsort.c
ccache cc -o natsort strnatcmp.o natsort.o
--- sorted-words 2015-06-05 18:41:31.000000000 -0700
+++ /dev/fd/63 2015-08-22 11:41:54.000000000 -0700
@@ -13,8 +13,8 @@
pic3
pic4
pic 4 else
-pic 5
pic 5
+pic 5
pic 5 something
pic 6
pic 7
Test failed for input file 'test-words'
make: *** [test] Error 1
Clang's scan-build
static analysis tool flags a few issues in natsort.c
. These are easy enough to fix, so that analysis passes. This opens the road for running make analyze
in CI as part of issue #8.
While compiling your library with PlatformIO (ESP32) &these compiler flags:
build_flags =
-std=c++17
-std=gnu++17
-Wall
-Wextra
-Wunreachable-code
I get some warnings:
.pio/libdeps/lolin_d32_pro_sdmmc_pe/natsort/natsort.c:29: warning: "_GNU_SOURCE" redefined
29 | #define _GNU_SOURCE
|
<command-line>: note: this is the location of the previous definition
.pio/libdeps/lolin_d32_pro_sdmmc_pe/natsort/natsort.c: In function 'main':
.pio/libdeps/lolin_d32_pro_sdmmc_pe/natsort/natsort.c:137:26: warning: implicit declaration of function 'getline' [-Wimplicit-function-declaration]
137 | if ((linelen = getline(&line, &bufsize, stdin)) <= 0)
| ^~~~~~~
Any way to get rid this issue? Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.