| 3759 | |
| 3760 | namespace { |
| 3761 | bool VersionCompare(cmSystemTools::CompareOp op, char const* lhss, |
| 3762 | char const* rhss) |
| 3763 | { |
| 3764 | char const* endl = lhss; |
| 3765 | char const* endr = rhss; |
| 3766 | |
| 3767 | while (((*endl >= '0') && (*endl <= '9')) || |
| 3768 | ((*endr >= '0') && (*endr <= '9'))) { |
| 3769 | // Do component-wise comparison, ignoring leading zeros |
| 3770 | // (components are treated as integers, not as mantissas) |
| 3771 | while (*endl == '0') { |
| 3772 | endl++; |
| 3773 | } |
| 3774 | while (*endr == '0') { |
| 3775 | endr++; |
| 3776 | } |
| 3777 | |
| 3778 | char const* beginl = endl; |
| 3779 | char const* beginr = endr; |
| 3780 | |
| 3781 | // count significant digits |
| 3782 | while ((*endl >= '0') && (*endl <= '9')) { |
| 3783 | endl++; |
| 3784 | } |
| 3785 | while ((*endr >= '0') && (*endr <= '9')) { |
| 3786 | endr++; |
| 3787 | } |
| 3788 | |
| 3789 | // compare number of digits first |
| 3790 | ptrdiff_t r = ((endl - beginl) - (endr - beginr)); |
| 3791 | if (r == 0) { |
| 3792 | // compare the digits if number of digits is equal |
| 3793 | r = strncmp(beginl, beginr, endl - beginl); |
| 3794 | } |
| 3795 | |
| 3796 | if (r < 0) { |
| 3797 | // lhs < rhs, so true if operation is LESS |
| 3798 | return (op & cmSystemTools::OP_LESS) != 0; |
| 3799 | } |
| 3800 | if (r > 0) { |
| 3801 | // lhs > rhs, so true if operation is GREATER |
| 3802 | return (op & cmSystemTools::OP_GREATER) != 0; |
| 3803 | } |
| 3804 | |
| 3805 | if (*endr == '.') { |
| 3806 | endr++; |
| 3807 | } |
| 3808 | |
| 3809 | if (*endl == '.') { |
| 3810 | endl++; |
| 3811 | } |
| 3812 | } |
| 3813 | // lhs == rhs, so true if operation is EQUAL |
| 3814 | return (op & cmSystemTools::OP_EQUAL) != 0; |
| 3815 | } |
| 3816 | } |
| 3817 | |
| 3818 | bool cmSystemTools::VersionCompare(cmSystemTools::CompareOp op, |
no outgoing calls
no test coverage detected
searching dependent graphs…