diff options
author | Sébastien Le Ray <sebastien-libreoffice@orniz.org> | 2011-02-10 16:54:04 +0100 |
---|---|---|
committer | Cédric Bosdonnat <cedricbosdo@openoffice.org> | 2011-02-10 16:54:04 +0100 |
commit | 5cb80049f5a9472260947056a25d89fef31d86b1 (patch) | |
tree | ef7881b28c5f9680d392f2e589b398dc92630856 /sal/rtl | |
parent | b1ca63cb764cfea0eb7e6e924b6ec0023e9d1cd1 (diff) |
Add compareToNumeric to OUString & Co
Diffstat (limited to 'sal/rtl')
-rw-r--r-- | sal/rtl/source/strtmpl.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/sal/rtl/source/strtmpl.c b/sal/rtl/source/strtmpl.c index 98c09f15a..18bc95983 100644 --- a/sal/rtl/source/strtmpl.c +++ b/sal/rtl/source/strtmpl.c @@ -60,6 +60,8 @@ inline void rtl_str_ImplCopy( IMPL_RTL_STRCODE* pDest, } \ } +#define IS_DIGIT(CHAR) (((CHAR) >= 48) && ((CHAR <= 57))) + /* ======================================================================= */ /* C-String functions which could be used without the String-Class */ /* ======================================================================= */ @@ -91,6 +93,51 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compare )( const IMPL_RTL_STRCODE* pStr1, /* ----------------------------------------------------------------------- */ +sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compare_Numeric )( const IMPL_RTL_STRCODE* pStr1, + const IMPL_RTL_STRCODE* pStr2 ) +{ + sal_Int32 nRet; + do { + while ( ((nRet = ((sal_Int32)(IMPL_RTL_USTRCODE(*pStr1)))- + ((sal_Int32)(IMPL_RTL_USTRCODE(*pStr2)))) == 0) && + *pStr2 ) + { + pStr1++; + pStr2++; + } + + if(*pStr1 && *pStr2) + { + IMPL_RTL_STRCODE c1 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr1 ); + IMPL_RTL_STRCODE c2 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr2 ); + sal_Int64 number1 = 0; + sal_Int64 number2 = 0; + if(IS_DIGIT(c1) && IS_DIGIT(c2)) + { + do + { + number1 = number1 * 10 + (c1 - '0'); + pStr1++; + c1 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr1 ); + } while(IS_DIGIT(c1)); + + do + { + number2 = number2 * 10 + (c2 - '0'); + pStr2++; + c2 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr2 ); + } while(IS_DIGIT(c2)); + + nRet = number1 - number2; + } + } + } while(nRet == 0 && *pStr1 && *pStr2); + + return nRet; +} + +/* ----------------------------------------------------------------------- */ + sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compare_WithLength )( const IMPL_RTL_STRCODE* pStr1, sal_Int32 nStr1Len, const IMPL_RTL_STRCODE* pStr2, |