kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #26877
Re: StrNumCmp
Le 04/12/2016 à 12:00, Michael Steinberg a écrit :
> Hello all,
>
> when doing other stuff I ran into one of a gazillion cases that can make StrNumCmp starting in
> common/string.cpp:214 crash. There are quite a few unchecked iterator dereferences, the aLength
> parameter is not correctly taken into account, etc.. The comment on the function's declaration is
> not enough specification for me to rewrite it properly. If somebody would come up with a spec for me
> I would happily rewrite the function.
>
> Cheers!
> Michael
>
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.
This is especially useful to sort component references or value.
For instance:
when the 2 strings U12 and U2 are compared by ASCII value:
In usual comparison (from ASCII value), U120 is sorted before U20
In StrNumCmp:
120 is read as a integer value
20 is read as a integer value
and comparisons are between U<120> and U<20> where <120> and <20> are integers, not chars.
and U120 is sorted after U20
--
Jean-Pierre CHARRAS
Follow ups
References
-
StrNumCmp
From: Michael Steinberg, 2016-12-04