Permalink
Browse files

various small fixes related to parsing of decimal numbers

  • Loading branch information...
1 parent e48488d commit 32fbcde82fba4f713fb0887533dc9799b6c0d28a @squentin committed May 13, 2012
Showing with 15 additions and 15 deletions.
  1. +3 −3 gmusicbrowser.pl
  2. +1 −1 gmusicbrowser_layout.pm
  3. +11 −11 gmusicbrowser_songs.pm
View
@@ -856,14 +856,14 @@ sub dates_to_timestamps
}
sub ConvertTime # convert date pattern into nb of seconds
-{ my ($date,$unit)= $_[0]=~m/^\s*(\d+|\d*?[.]\d+)\s*([a-zA-Z]*)\s*$/;
+{ my ($date,$unit)= $_[0]=~m/^\s*(\d*\.?\d+)\s*([a-zA-Z]*)\s*$/;
return 0 unless $date;
if (my $ref= $DATEUNITS{$unit}) { $date*= $ref->[0] }
elsif ($unit) { warn "ignoring unknown unit '$unit'\n" }
return time-$date;
}
sub ConvertSize
-{ my ($size,$unit)= $_[0]=~m/^\s*(\d+|\d*?[.]\d+)\s*([a-zA-Z]*)\s*$/;
+{ my ($size,$unit)= $_[0]=~m/^\s*(\d*\.?\d+)\s*([a-zA-Z]*)\s*$/;
return 0 unless $size;
if (my $ref= $SIZEUNITS{lc$unit}) { $size*= $ref->[0] }
elsif ($unit) { warn "ignoring unknown unit '$unit'\n" }
@@ -7973,7 +7973,7 @@ sub AddRow
my $table=$self->{table};
my $row=$self->{row}++;
my $deleted;
- my ($inverse,$weight,$type,$extra)=$params=~m/^(-?)([0-9.]+)([a-zA-Z])(.*)$/;
+ my ($inverse,$weight,$type,$extra)=$params=~m/^(-?)(\d*\.?\d+)([a-zA-Z])(.*)$/;
return unless $type;
my $frame=Gtk2::Frame->new( $Random::ScoreTypes{$type}{desc} );
$frame->{type}=$type;
View
@@ -2047,7 +2047,7 @@ sub _compute_pos
::setlocale(::LC_NUMERIC, 'C'); # so that decimal separator is the dot
# can parse strings such as : +3s/2-w-p/2+20
for my $v ($def=~m/([-+][^-+]+)/g)
- { if ($v=~m#([-+](?:\d*\.)?\d*)([pws])(?:/([0-9]+))?#)
+ { if ($v=~m#([-+]\d*\.?\d*)([pws])(?:/([0-9]+))?#)
{ $h{$2}= ($1 eq '+' ? 1 : $1 eq '-' ? -1 : $1) / ($3||1);
}
elsif ($v=~m/^[-+]\d+$/) { $h{n}=$v }
View
@@ -432,7 +432,7 @@ our %timespan_menu=
bits => 16,
init => '____=""; ___value[0]=undef;',
set => 'vec(____,#ID#,#bits#) = ___gid{#VAL#}||= do { push(@___value, #VAL#+0)-1; }',
- check => '#VAL#= #VAL# =~m/^(\d*(?:\.\d+)?)$/ ? $1 : 0;',
+ check => '#VAL#= #VAL# =~m/^(-?\d*\.?\d+)$/ ? $1 : 0;',
displayformat => '%d',
},
integer =>
@@ -462,7 +462,7 @@ our %timespan_menu=
check => '#VAL#= #VAL# =~m/^(-?\d*\.?\d+(?:e[-+]\d+)?)$/i ? $1 : #novalue#;',
# FIXME make sure that locale is set to C (=> '.' as decimal separator) when needed
'editwidget:all'=> sub { my $field=$_[0]; GMB::TagEdit::EntryNumber->new(@_,min=>$Def{$field}{edit_min},max=>$Def{$field}{edit_max},signed=>1,digits=>2,mode=>'allow_empty'); },
- autofill_re => '(?:\\d+\\.)?\\.\\d+',
+ autofill_re => '-?\\d*\\.?\\d+',
'filterpat:value' => [digits => 2, signed=>1, ],
n_sort => 'do {my $v=#_#; $v != $v ? "-inf" : $v}', # use the fact that NaN != NaN
'filter:defined' => 'do {my $v=#_#; .!!. $v==$v}', #
@@ -1474,7 +1474,7 @@ sub Field_filter_choices
}
return \%filters;
}
-sub filter_prep_numbers { $_[0]=~m/(-?\d+(?:\.\d+)?)/; return $1 || 0 }
+sub filter_prep_numbers { $_[0]=~m/(-?\d*\.?\d+)/; return $1 || 0 }
sub FilterCode
{ my ($field,$cmd,$pat,$inv)=@_;
my ($code,$convert)=LookupCode($field, "filter:$cmd", "filter_prep:$cmd");
@@ -4067,7 +4067,7 @@ sub new_from_smartstring
sub _smartstring_moreless
{ my ($pat,$op,$casesens,$field)=@_;
$pat=~s/,/./g; #use dot as decimal separator
- return undef unless $pat=~m/^-?[0-9.]+[a-zA-Z]?$/; # FIXME could check if support units
+ return undef unless $pat=~m/^-?\d*\.?\d+[a-zA-Z]?$/; # FIXME could check if support units
$op= $op eq '<=' ? '->' : $op eq '>=' ? '-<' : $op;
return $op.':'.$pat;
}
@@ -4086,22 +4086,22 @@ sub _smartstring_date_moreless
sub _smartstring_number
{ my ($pat,$op,$casesens,$field)=@_;
$pat=~s/,/./g; #use dot as decimal separator
- if ($op ne '=' || $pat!~m/^-[0-9.]+[a-zA-Z]?$/) {$pat=~s/^-/../} # allow ranges using - unless = with negative number (could also check if field support negative values ?)
+ if ($pat!~m#\.\.# && ($op ne '=' || $pat!~m/^-\d*\.?\d+[a-zA-Z]?$/)) {$pat=~s/-($|-|\d*\.?\d+[a-zA-Z]?$)/..$1/} # allow ranges using - unless = with negative number (could also check if field support negative values ?)
if ($pat=~m/\.\./)
{ my ($s1,$s2)= split /\s*\.\.\s*/,$pat,2;
return (length $s1 && length $s2) ? "b:$s1 $s2":
(length $s1 && !length$s2) ? "-<:".$s1 :
(!length$s1 && length $s2) ? "->:".$s2 : undef;
}
- return undef unless $pat=~m/^-?[0-9.]+[a-zA-Z]?$/; # FIXME could check if support units
+ return undef unless $pat=~m/^-?\d*\.?\d+[a-zA-Z]?$/; # FIXME could check if support units
$op= $op eq ':' ? 's' : 'e';
return $op.':'.$pat;
}
sub _smartstring_date
{ my ($pat,$op,$casesens,$field)=@_;
my $suffix='';
my $date1= my $date2='';
- if ($pat=~m#\d# and ($date1,$date2)= $pat=~m#^(\d+[smhdwMy])?(?:\.\.|-)(\d+[smhdwMy])?$#i) # relative date filter
+ if ($pat=~m#\d# and ($date1,$date2)= $pat=~m#^(\d*\.?\d+[smhdwMy])?(?:\.\.|-)(\d*\.?\d+[smhdwMy])?$#i) # relative date filter
{ $suffix='ago';
if ($date1 && $date1!~m/[1-9]/) {$date1=''}
elsif ($date1 && $date2 && $date2!~m/[1-9]/) {$date2=$date1; $date1=''}
@@ -4145,8 +4145,8 @@ sub _is_subset # returns true if $f2 must be a subset of $f1 #$f1 and $f2 must
return 0 if $field1 ne $field2 || $op1 ne $op2;
if ($op1 eq 's'|| $op1 eq 'si') { return index($pat2,$pat1)!=-1 } # handle case-i ?
elsif ($op1 eq '-s'|| $op1 eq '-si') { return index($pat1,$pat2)!=-1 } # handle case-i ?
- elsif ($op1 eq '>' || $op1 eq '-<') { return ($pat1."\x00".$pat2) =~m/(-?\d+)(\w*)\x00(-?\d+)\2/ && $3>$1 }
- elsif ($op1 eq '<' || $op1 eq '->') { return ($pat1."\x00".$pat2) =~m/(-?\d+)(\w*)\x00(-?\d+)\2/ && $3<$1 }
+ elsif ($op1 eq '>' || $op1 eq '-<') { return ($pat1."\x00".$pat2) =~m/^(-?\d*\.?\d+)(\w*)\x00(-?\d*\.?\d+)\2$/ && $3>$1 }
+ elsif ($op1 eq '<' || $op1 eq '->') { return ($pat1."\x00".$pat2) =~m/^(-?\d*\.?\d+)(\w*)\x00(-?\d*\.?\d+)\2$/ && $3<$1 }
# FIXME check these filters : b bago >ago <ago ?
return 0;
}
@@ -4709,7 +4709,7 @@ sub make
my @scores;
::setlocale(::LC_NUMERIC, 'C');
for my $s ( split /\x1D/, $self->{string} )
- { my ($inverse,$weight,$type,$extra)=$s=~m/^(-?)([0-9.]+)([a-zA-Z])(.*)/;
+ { my ($inverse,$weight,$type,$extra)=$s=~m/^(-?)(\d*\.?\d+)([a-zA-Z])(.*)/;
next unless $type;
my $score;
if (my $value=$ScoreTypes{$type}{value})
@@ -4906,7 +4906,7 @@ sub CalcScore
sub MakeExample
{ my ($class,$string,$ID)=@_;
::setlocale(::LC_NUMERIC, 'C');
- my ($inverse,$weight,$type,$extra)=$string=~m/^(-?)([0-9.]+)([a-zA-Z])(.*)/;
+ my ($inverse,$weight,$type,$extra)=$string=~m/^(-?)(\d*\.?\d+)([a-zA-Z])(.*)/;
return 'error' unless $type;
my $round=$ScoreTypes{$type}{round}||'%s';
my $unit= $ScoreTypes{$type}{unit}||'';

0 comments on commit 32fbcde

Please sign in to comment.