mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Compare as strings holding indices/version numbers.
This commit is contained in:
@@ -149,6 +149,75 @@ namespace bx
|
||||
return strCmpI(_lhs, _rhs.getPtr(), _rhs.getLength() );
|
||||
}
|
||||
|
||||
int32_t strCmpV(const char* _lhs, const char* _rhs, int32_t _max)
|
||||
{
|
||||
int32_t ii = 0;
|
||||
int32_t idx = 0;
|
||||
bool zero = true;
|
||||
|
||||
for (
|
||||
; 0 < _max && _lhs[ii] == _rhs[ii]
|
||||
; ++ii, --_max
|
||||
)
|
||||
{
|
||||
const uint8_t ch = _lhs[ii];
|
||||
if ('\0' == ch
|
||||
|| '\0' == _rhs[ii])
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (!isNumeric(ch) )
|
||||
{
|
||||
idx = ii+1;
|
||||
zero = true;
|
||||
}
|
||||
else if ('0' != ch)
|
||||
{
|
||||
zero = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == _max)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ('0' != _lhs[idx]
|
||||
&& '0' != _rhs[idx])
|
||||
{
|
||||
int32_t jj = 0;
|
||||
for (jj = ii
|
||||
; 0 < _max && isNumeric(_lhs[jj])
|
||||
; ++jj, --_max
|
||||
)
|
||||
{
|
||||
if (!isNumeric(_rhs[jj]) )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (isNumeric(_rhs[jj]))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (zero
|
||||
&& idx < ii
|
||||
&& (isNumeric(_lhs[ii]) || isNumeric(_rhs[ii]) ) )
|
||||
{
|
||||
return (_lhs[ii] - '0') - (_rhs[ii] - '0');
|
||||
}
|
||||
|
||||
return 0 == _max ? 0 : _lhs[ii] - _rhs[ii];
|
||||
}
|
||||
|
||||
int32_t strCmpV(const char* _lhs, const StringView& _rhs)
|
||||
{
|
||||
return strCmpV(_lhs, _rhs.getPtr(), _rhs.getLength() );
|
||||
}
|
||||
|
||||
int32_t strLen(const char* _str, int32_t _max)
|
||||
{
|
||||
if (NULL == _str)
|
||||
|
||||
Reference in New Issue
Block a user