Sign in Join

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

Mailing lists / fpc-pascal / 2013-11

Bug in AnsiCompareText of cwstring

6 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Mattias Gaertner

Hi all,

When using the cwstring widestringmanager the function AnsiCompareText seems to have a bug.

For example:

{$mode objfpc}{$H+}
uses
  Classes, SysUtils, cwstring;
begin
  writeln('o   and .   gives ',AnsiCompareText('o','.'));
  writeln('oc  and .o  gives ',AnsiCompareText('oc','.o'));
  writeln('oce and .ou gives ',AnsiCompareText('oce','.ou'));
end.

Result:

o and . gives 1
oc and .o gives 1
oce and .ou gives -18

I tested on Linux 64bit with fpc 2.6.2 and 2.7.1 (rev 25875).

See bug report
http://bugs.freepascal.org/view.php?id=25378

What is the state of the cwstring manager?

Mattias

Reply by email

Jonas Maebe
to Mattias Gaertner
Mattias Gaertner wrote 22 lines
When using the cwstring widestringmanager the function AnsiCompareText seems to have a bug. For example: {$mode objfpc}{$H+} uses Classes, SysUtils, cwstring; begin writeln('o and . gives ',AnsiCompareText('o','.')); writeln('oc and .o gives ',AnsiCompareText('oc','.o')); writeln('oce and .ou gives ',AnsiCompareText('oce','.ou')); end. Result: o and . gives 1 oc and .o gives 1 oce and .ou gives -18 I tested on Linux 64bit with fpc 2.6.2 and 2.7.1 (rev 25875).

Under Mac OS X 10.5 I get:

o and . gives 33
oc and .o gives 33
oce and .ou gives 33

Under Linux I get the same as you with an UTF-8 locale. With LANG=C, I get "1" as result for each comparison under Linux though.

See bug report http://bugs.freepascal.org/view.php?id=25378 What is the state of the cwstring manager?

Fully functional and supported. It can of course nevertheless contain bugs. This looks more like a potential bug in glibc though, but I'd have to check in more detail to confirm that (for which I don't have time right now).

Jonas

Reply by email

Martin Schreiber
to Mattias Gaertner: When using the cwstring widestringmanager the function AnsiCompareText seems to have a…
Mattias Gaertner wrote 23 lines
Hi all, When using the cwstring widestringmanager the function AnsiCompareText seems to have a bug. For example: {$mode objfpc}{$H+} uses Classes, SysUtils, cwstring; begin writeln('o and . gives ',AnsiCompareText('o','.')); writeln('oc and .o gives ',AnsiCompareText('oc','.o')); writeln('oce and .ou gives ',AnsiCompareText('oce','.ou')); end. Result: o and . gives 1 oc and .o gives 1 oce and .ou gives -18

Possibly as intended because the collation of the current locale ignores punctuation.

Martin

Reply by email

Jonas Maebe
to Martin Schreiber
Martin Schreiber wrote 10 lines
On Wednesday 27 November 2013 13:05:29 Mattias Gaertner wrote: > Result: > > o and . gives 1 > oc and .o gives 1 > oce and .ou gives -18 > Possibly as intended because the collation of the current locale ignores punctuation.

You're right: https://www.gnu.org/software/coreutils/faq/#Sort-does-not-sort-in-normal-order_0021

So there is no bug in either FPC or glibc. The locale is simply defined like that on Linux.

Jonas

Reply by email