Sign in Join

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

Mailing lists / lazarus / 2015-08

Error in UTF8CompareText comment

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Jürgen Hestermann

There is a comment for UTF8CompareText in LazUTF8 which is contradictorily:

// Returns: < 0 if S1 < S2, 0 if S1 = S2, > 0 if S2 > S1.

But S1 < S2 is the same as S2 > S1.
In the first case the result should be < 0 and in the second one > 0.

It cannot even be retrieved from the code how it realy works (unless you are fit in assembler). So when will the result be positive and when negative?

Reply by email

Mattias Gaertner
to Jürgen Hestermann
Show quoted text 5 lines
There is a comment for UTF8CompareText in LazUTF8 which is contradictorily: // Returns: < 0 if S1 < S2, 0 if S1 = S2, > 0 if S2 > S1. But S1 < S2 is the same as S2 > S1.

It should be >0 if S1 > S2. I changed the comment.

In the first case the result should be < 0 and in the second one > 0. It cannot even be retrieved from the code how it realy works (unless you are fit in assembler). So when will the result be positive and when negative?

Under Linux it does not use Assembler.
Internally it uses UTF8CompareStr, which uses CompareMemRange, which returns -1 if a byte of S1 is lower than S2.
I added the comment.

Mattias

Reply by email

Jürgen Hestermann
to Mattias Gaertner
Mattias Gaertner wrote 9 lines
On Thu, 13 Aug 2015 11:52:26 +0200 J?rgen Hestermann wrote: > There is a comment for UTF8CompareText in LazUTF8 which is contradictorily: > > // Returns: < 0 if S1 < S2, 0 if S1 = S2, > 0 if S2 > S1. > > But S1 < S2 is the same as S2 > S1. It should be >0 if S1 > S2. I changed the comment.

Thanks.

Reply by email