| 823 | |
| 824 | |
| 825 | int 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 | { |