Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
V
views_natural_sort
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
1
Merge Requests
1
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
views_natural_sort
Commits
f5ad56c3
Commit
f5ad56c3
authored
Dec 22, 2016
by
generalredneck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2790345
: Negative Decimal Numbers sort Incorrectly
parent
2444865c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
7 deletions
+14
-7
tests/modules/views_natural_sort_test/views_natural_sort_test.module
...es/views_natural_sort_test/views_natural_sort_test.module
+1
-1
views_natural_sort.inc
views_natural_sort.inc
+12
-5
views_natural_sort.test
views_natural_sort.test
+1
-1
No files found.
tests/modules/views_natural_sort_test/views_natural_sort_test.module
View file @
f5ad56c3
...
...
@@ -94,7 +94,7 @@ function views_natural_sort_test_views_create_test_content() {
'10 apples'
,
'-1 apples'
,
'-10 apples'
,
'-2 app
el
s'
,
'-2 app
le
s'
,
'-3.550 apples'
,
'-3.5501 apples'
,
'3.5501 apples'
,
...
...
views_natural_sort.inc
View file @
f5ad56c3
...
...
@@ -131,8 +131,10 @@ function _views_natural_sort_number_transform_match_callback(array $match) {
// Remove commas and leading zeros from whole number.
$whole
=
(
string
)
(
int
)
str_replace
(
','
,
''
,
(
isset
(
$match
[
4
])
&&
strlen
(
$match
[
4
])
>
0
)
?
$match
[
4
]
:
$match
[
2
]);
// Remove traililng 0's from fraction, then add the decimal and one trailing
// 0.
$fraction
=
trim
(
'.'
.
$match
[
3
],
'0'
)
.
'0'
;
// 0 and a space. The space serves as a way to always sort shorter decimal
// numbers that match exactly as less than longer ones.
// Ex: 3.05 and 3.05011.
$fraction
=
trim
(
'.'
.
$match
[
3
],
'0'
)
.
'0 '
;
$encode
=
sprintf
(
'%02u'
,
strlen
(
$whole
))
.
$whole
.
$fraction
;
if
(
strlen
(
$match
[
1
]))
{
// Negative number. Make 10's complement. Put back any leading white space
...
...
@@ -140,9 +142,14 @@ function _views_natural_sort_number_transform_match_callback(array $match) {
// digit. str_replace() seems to work by copying the source to the result,
// then successively replacing within it, rather than replacing from the
// source to the result.
$digits
=
array
(
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
);
$intermediate
=
array
(
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
,
'g'
,
'h'
,
'i'
,
'j'
);
$rev_digits
=
array
(
'9'
,
'8'
,
'7'
,
'6'
,
'5'
,
'4'
,
'3'
,
'2'
,
'1'
,
'0'
);
// In this case since rules are reverced we also have to use a character
// that would be sorted higher than a space when a number is being compared
// against a longer one that is identical in negative numbers. This is so
// that longer numbers are always LESS than sorter numbers that have
// identical beginnings. Ex: -3.05 and -3.05011
$digits
=
array
(
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
' '
);
$intermediate
=
array
(
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
,
'g'
,
'h'
,
'i'
,
'j'
,
'k'
);
$rev_digits
=
array
(
'9'
,
'8'
,
'7'
,
'6'
,
'5'
,
'4'
,
'3'
,
'2'
,
'1'
,
'0'
,
':'
);
$encode
=
$match
[
1
]
.
str_replace
(
$intermediate
,
$rev_digits
,
str_replace
(
$digits
,
$intermediate
,
$encode
));
}
return
$encode
;
...
...
views_natural_sort.test
View file @
f5ad56c3
...
...
@@ -97,7 +97,7 @@ class ViewsNaturalSortBasicTest extends ViewsTestCase {
'10 apples'
,
'-1 apples'
,
'-10 apples'
,
'-2 app
el
s'
,
'-2 app
le
s'
,
'-3.550 apples'
,
'-3.5501 apples'
,
'3.5501 apples'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment