String compare

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

String compare

Postby wobotzen » Sun Mar 22, 2009 9:44 pm

Hallo
does anyone know why the String compare does the following

'n'='N' false
'n' <='N' true
'n'>='N' true

'n' >'N' false
'n' <'N' false

regards
wolfgang botzenhardt
wobotzen
 
Posts: 4
Joined: Tue Feb 26, 2008 5:12 am

Re: String compare

Postby benvandijk » Sun Mar 22, 2009 11:59 pm

Hi Wolfgang,

As you can see in comments of the implementor of <= in EsString, the compare is done using collating sequence (sorting order).
'n' and N' have the same place In the collating sequence.

The method sameAs: also uses the collating sequence.

Also: 'n' and 'N' are the same, but are not equal.

Greetings, Ben.
benvandijk
 
Posts: 45
Joined: Sun Feb 25, 2007 7:14 am
Location: Arnhem, Netherlands

Re: String compare

Postby wobotzen » Mon Mar 23, 2009 12:40 am

yes
but if n~=N
then either n<=N or n>=N must return false.
and in all VA Versions i had looked #<= is reimplemented at String using <primitive: VMprStringLessEqual>

regards
wolfgang
wobotzen
 
Posts: 4
Joined: Tue Feb 26, 2008 5:12 am

Re: String compare

Postby wembley » Wed Mar 25, 2009 11:40 am

Wolfgang -

It may be counter-intuitive, but #= and #~= refer to object equivalence while #<, #<=, #sameAs:, #>=, and #> all relate to case-insensitive collating sequence comparison. So it is quite possible (and expected based on this definition) to see the results that you got when comparing 'N' and 'n'.
John O'Keefe [|], Principal Smalltalk Architect, Instantiations Inc.
wembley
Moderator
 
Posts: 405
Joined: Mon Oct 16, 2006 3:01 am
Location: Durham, NC

Re: String compare

Postby Yuri » Fri Mar 27, 2009 8:19 am

All,

I discovered a faulty implementation, while porting Seaside GoogleChart from Squeak, regarding Character comparisons in CgScreen>>#parseRGB:digits:

The original code can be found
Code: Select all
parseRGB: spec digits: digits
   "Parse a color specification string spec
    of the form '#RRGGBB' with the given number of digits
    for each of the red, green and blue components.
    Answer a CgRGBColor or nil if there is an error."

   | shift index components component digit |
   shift := 16 - (digits * 4).
   index := 2.
   components := Array new: 3.
   1 to: 3 do: [:i |
      component := 0.
      digits timesRepeat: [
         component := component * 16.
         digit := spec at: index.
         ($0 <= digit and: [digit <= $9])
            ifTrue: [component := component + (digit value - $0 value)]
            ifFalse: [
         ($A <= digit and: [digit <= $F])
            ifTrue: [component := component + (digit value - $A value + 10)]
            ifFalse: [
         ($a <= digit and: [digit <= $f])
            ifTrue: [component := component + (digit value - $a value + 10)]
            ifFalse: [^nil]]].
         index := index + 1].
      components at: i put: (component bitShift: shift)].
   ^CgRGBColor
      red: (components at: 1)
      green: (components at: 2)
      blue: (components at: 3)


I solved the problem as follows:
Code: Select all
parseRGB: spec digits: digits
   "Parse a color specification string spec
    of the form '#RRGGBB' with the given number of digits
    for each of the red, green and blue components.
    Answer a CgRGBColor or nil if there is an error."

   | uppercaseSpec shift index components component digit |
   shift := 16 - (digits * 4).
   index := 2.
   components := Array new: 3.
   uppercaseSpec := spec asUppercase.
   1 to: 3 do: [:i |
      component := 0.
      digits timesRepeat: [
         component := component * 16.
         digit := uppercaseSpec at: index.
         ($0 <= digit and: [digit <= $9])
            ifTrue: [component := component + (digit value - $0 value)]
            ifFalse: [
         ($A <= digit and: [digit <= $F])
            ifTrue: [component := component + (digit value - $A value + 10)]
            ifFalse: [^nil]].
         index := index + 1].
      components at: i put: (component bitShift: shift)].
   ^CgRGBColor
      red: (components at: 1)
      green: (components at: 2)
      blue: (components at: 3)


Of course you can download the fix from http://vastgoodies.com/main/maps/Seaside%2520GoogleChart/yv.51%2520%252B%2520VAST%25208.0beta1 which is included with the nice goodie which I ported from Squeak.

Kind regards and have a nice weekend,

Yuri.
Yuri
 
Posts: 9
Joined: Thu Feb 12, 2009 2:54 am
Location: The Netherlands, Waalwijk or 's-Hertogenbosch

Re: String compare

Postby wembley » Fri Mar 27, 2009 11:11 am

Yuri -

This is great -- thanks for your effort. I loaded it into the latest development build of V8 (Seaside 2.9alpha3 +) and it seems to work very well there.

I have a few comments:

* The Color class is (unfortunately) part of VA Assist, WindowBuilder Pro, and a couple other packages (in the WbKernel common part) and so currently cannot be relied on. I guess I will need to move it down to CommonGraphics in V8.0.1 because GoogleCharts isn't the only Seaside app that references it -- case 39837 opened.

* I see the bug in CgScreen>>#parseRGB:digits: -- case 39839 opened -- fixed in V8.0.0.

* This is not the first place where the difference in the implementation of #asInteger has cause a problem. Some of the Seaside Core test cases fail for the same reason. Doing rounding in #asInteger is what the ANSI Spec calls for.
wembley
Moderator
 
Posts: 405
Joined: Mon Oct 16, 2006 3:01 am
Location: Durham, NC

Re: String compare

Postby bonndias » Sun Apr 05, 2009 10:48 pm

benvandijk wrote:Hi Wolfgang,

As you can see in comments of the implementor of <= in EsString, the compare is done using collating sequence (sorting order).
'n' and N' have the same place In the collating sequence.

The method sameAs: also uses the collating sequence.

Also: 'n' and 'N' are the same, but are not equal.

Greetings, Ben.


When I look at the result of using LcCollate compareString:and: it works exactly as expected on my Windows. And I think we used it for sorting German Strings too. This is from VA 7.02:

Locale current lcCollate compareString: 'n' and: 'N' -> 2
Locale current lcCollate compareString: 'N' and: 'n' -> 3
Locale current lcCollate compareString: 'ä' and: 'b' -> 2
Locale current lcCollate compareString: 'b' and: 'ä' -> 3

Locale current lcCollate compareString: 'ä' and: 'Ä' -> 2 is correct but 'ä' < 'Ä' -> false is not what I expect.

Regards
bonndias
bonndias
 
Posts: 16
Joined: Mon Jun 09, 2008 4:15 am


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest