[Rt-commit] r5481 - in rt/branches/3.6-RELEASE: lib/RT/Interface
ruz at bestpractical.com
ruz at bestpractical.com
Wed Jun 28 13:55:12 EDT 2006
Author: ruz
Date: Wed Jun 28 13:55:11 2006
New Revision: 5481
Modified:
rt/branches/3.6-RELEASE/bin/rt.in
rt/branches/3.6-RELEASE/lib/RT/Interface/REST.pm
Log:
Based on patch from Philip Kime.
* sort bt numbers first then by letters in expand_list
* get rid of warnings
Modified: rt/branches/3.6-RELEASE/bin/rt.in
==============================================================================
--- rt/branches/3.6-RELEASE/bin/rt.in (original)
+++ rt/branches/3.6-RELEASE/bin/rt.in Wed Jun 28 13:55:11 2006
@@ -1328,17 +1328,29 @@
return \@words;
}
+# WARN: this code is duplicated in lib/RT/Interface/REST.pm
+# change both functions at once
sub expand_list {
my ($list) = @_;
- my ($elt, @elts, %elts);
- foreach $elt (split /,/, $list) {
- if ($elt =~ /^(\d+)-(\d+)$/) { push @elts, ($1..$2) }
- else { push @elts, $elt }
+ my @elts;
+ foreach (split /,/, $list) {
+ push @elts, /^(\d+)-(\d+)$/? ($1..$2): $_;
}
- @elts{@elts}=();
- return sort {$a<=>$b} keys %elts;
+ return map $_->[0], # schwartzian transform
+ sort {
+ defined $a->[1] && defined $b->[1]?
+ # both numbers
+ $a->[1] <=> $b->[1]
+ :!defined $a->[1] && !defined $b->[1]?
+ # both letters
+ $a->[2] cmp $b->[2]
+ # mix, number must be first
+ :defined $a->[1]? -1: 1
+ }
+ map [ $_, (defined( /^(\d+)$/ )? $1: undef), lc($_) ],
+ @elts;
}
sub get_type_argument {
Modified: rt/branches/3.6-RELEASE/lib/RT/Interface/REST.pm
==============================================================================
--- rt/branches/3.6-RELEASE/lib/RT/Interface/REST.pm (original)
+++ rt/branches/3.6-RELEASE/lib/RT/Interface/REST.pm Wed Jun 28 13:55:11 2006
@@ -62,17 +62,29 @@
my $field = '[a-zA-Z][a-zA-Z0-9_-]*';
+# WARN: this code is duplicated in bin/rt.in,
+# change both functions at once
sub expand_list {
my ($list) = @_;
- my ($elt, @elts, %elts);
- foreach $elt (split /,/, $list) {
- if ($elt =~ /^(\d+)-(\d+)$/) { push @elts, ($1..$2) }
- else { push @elts, $elt }
- }
-
- @elts{@elts}=();
- return sort {$a<=>$b} keys %elts;
+ my @elts;
+ foreach (split /,/, $list) {
+ push @elts, /^(\d+)-(\d+)$/? ($1..$2): $_;
+ }
+
+ return map $_->[0], # schwartzian transform
+ sort {
+ defined $a->[1] && defined $b->[1]?
+ # both numbers
+ $a->[1] <=> $b->[1]
+ :!defined $a->[1] && !defined $b->[1]?
+ # both letters
+ $a->[2] cmp $b->[2]
+ # mix, number must be first
+ :defined $a->[1]? -1: 1
+ }
+ map [ $_, (defined( /^(\d+)$/ )? $1: undef), lc($_) ],
+ @elts;
}
# Returns a reference to an array of parsed forms.
More information about the Rt-commit
mailing list