MCPcopy Create free account
hub / github.com/KiCad/kicad-source-mirror / StrNumCmp

Function StrNumCmp

common/string_utils.cpp:825–907  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

823
824
825int StrNumCmp( const wxString& aString1, const wxString& aString2, bool aIgnoreCase )
826{
827 int nb1 = 0, nb2 = 0;
828
829 auto str1 = aString1.begin();
830 auto str2 = aString2.begin();
831
832 const auto str1End = aString1.end();
833 const auto str2End = aString2.end();
834
835 while( str1 != str1End && str2 != str2End )
836 {
837 wxUniChar c1 = *str1;
838 wxUniChar c2 = *str2;
839
840 if( wxIsdigit( c1 ) && wxIsdigit( c2 ) ) // Both characters are digits, do numeric compare.
841 {
842 nb1 = 0;
843 nb2 = 0;
844
845 do
846 {
847 c1 = *str1;
848 nb1 = nb1 * 10 + (int) c1 - '0';
849 ++str1;
850 } while( str1 != str1End && wxIsdigit( *str1 ) );
851
852 do
853 {
854 c2 = *str2;
855 nb2 = nb2 * 10 + (int) c2 - '0';
856 ++str2;
857 } while( str2 != str2End && wxIsdigit( *str2 ) );
858
859 if( nb1 < nb2 )
860 return -1;
861
862 if( nb1 > nb2 )
863 return 1;
864
865 c1 = ( str1 != str1End ) ? *str1 : wxUniChar( 0 );
866 c2 = ( str2 != str2End ) ? *str2 : wxUniChar( 0 );
867 }
868
869 // Any numerical comparisons to here are identical.
870 if( aIgnoreCase )
871 {
872 if( c1 != c2 )
873 {
874 wxUniChar uc1 = wxToupper( c1 );
875 wxUniChar uc2 = wxToupper( c2 );
876
877 if( uc1 != uc2 )
878 return uc1 < uc2 ? -1 : 1;
879 }
880 }
881 else
882 {

Callers 15

operator()Method · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
operator<Function · 0.85
AssignIntrinsicRanksMethod · 0.85
SortVariantNamesFunction · 0.85
operator<Function · 0.85
operator <Function · 0.85
getListContentMethod · 0.85
GetValueMethod · 0.85
cmpMethod · 0.85

Calls 2

beginMethod · 0.45
endMethod · 0.45

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.68
TestPinToPinMethod · 0.68