← Back to team overview

kicad-developers team mailing list archive

Re: StrNumCmp

 

Le 04/12/2016 à 22:24, Michael Steinberg a écrit :
> 
>>> It is similar to a string comparison (for string sorting) but unlike the usual strncmp() or
>>> strncasecmp() functions, when digits are encountered in a string, they are converted to a number and
>>> this is the number value which is taken in account for comparison.
>> I've written my own back then for the pin table, factored out into
>> eeschema/pin_number.cpp. This should be merged with the other
>> implementations then in the same process, and possibly generalized
>> (there is special treatment of "V" as a decimal point if it is placed
>> between numbers, for example, that may not always be appropriate).
>>
> Okay, I came up with a solution for which I'm not so sure if it would be generally accepted:
> http://pastebin.com/Y7rVzHV1
> It should compile as is.
> The big part of that code is made off the class CONST_WX_STRING_VIEW, which does nothing more than
> encapsulate a pair of wxString iterators, dereferencing yields the beginning character, incrementing
> increments the begin iterator etc. like in "ranges". I found such a range helper immensely helpful
> for parsing generally, but it might be a bit bulky to include only for StrNumCmp.
> Simon, I tried to mimic the behaviour of your function, see the below the comment "Gyros-Mode", I
> doubt that the float-parsing is particularly clever however. Feel free to drop me compatible code
> that I could use instead.
> 
> Cheers!
> Michael

Be careful with floating points: a separator can be a point or a comma, and you don't know what
separator was used when creating a string.
Never expect the separator is always a point or always a comma.
You can find a mix of these 2 notations.

And generally speaking, a point or a comma inside a string with digits is not necessary a fp separator.

As I said previously, StrNumCmp in mainly intended to sort references in list.
Most of time, for a component value, you cannot know the meaning of separator
You can have 4,7K or 4.7K or 4K7 but also 7400,DIP14


-- 
Jean-Pierre CHARRAS


Follow ups

References