Compare as strings holding indices/version numbers.

This commit is contained in:
Branimir Karadžić
2017-07-16 19:30:39 -07:00
parent e95f6a08c9
commit 462a5969c2
3 changed files with 138 additions and 0 deletions

View File

@@ -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)