Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2018-04

Case of string

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bart

Hi,

Case of string evaluation seems to have changed from 3.0.4 to trunk.

program Project1;
{$mode objfpc}
{$h+}
var
  s: string;
begin
  repeat
    readln(s);
    case s of
      'Hello', 'Hello2': writeln('In Hello');
      'a'..'z': writeln('In ''a''..''z''');
      else
        writeln('In else');
    end;
  until (s = '');
end.

With 3.0.4 when the inout is 'qwerty' the output is 'In 'a'..'z'.

In trunk (r37889) the output will be:
'In Hello' for 'Hello' and 'Hello2'
'In 'a'..'z' only when the inout is 'a'
'In else' for every other input.

The 3.0.4 behaviour makes sense to me:( 'qwerty' > 'a') evaluates to TRUE, as does ('qwerty' < 'z').
This might be unexpected to the programmer, but to me this indicates using ranges with case of string is a bit dangerous.

The trunk behaviour makes no sense to this a bug, or was it changed by design? If the latter, why?

Bart

Reply by email

Alexander Klenin
to Bart
Bart wrote 19 lines
Hi, With 3.0.4 when the inout is 'qwerty' the output is 'In 'a'..'z'. In trunk (r37889) the output will be: 'In Hello' for 'Hello' and 'Hello2' 'In 'a'..'z' only when the inout is 'a' 'In else' for every other input. The 3.0.4 behaviour makes sense to me:( 'qwerty' > 'a') evaluates to TRUE, as does ('qwerty' < 'z'). This might be unexpected to the programmer, but to me this indicates using ranges with case of string is a bit dangerous. The trunk behaviour makes no sense to me at all. Is this a bug, or was it changed by design? If the latter, why?

Since I was involved in the design and implementation of 'case of string', I can confirm that this change breaks original intent.

Alexander S. Klenin

Reply by email

Sven Barth
to Bart
Bart wrote 7 lines
On Fri, Apr 27, 2018 at 5:49 PM, Sven Barth via fpc-devel wrote: > It's a bug due to refactoring. I'll commit the fix once I got to run the > testsuite. So, I need not file a bugreport then?

Nope, fixed in r38860. :)

Regards,
Sven

Reply by email