1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 #*************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sal.hxx"
31 //------------------------------------------------------------------------
32 //------------------------------------------------------------------------
37 //------------------------------------------------------------------------
38 //------------------------------------------------------------------------
41 #include <sal/types.h>
44 #ifndef _RTL_USTRING_H_
45 #include <rtl/ustring.h>
48 #ifndef _RTL_STRING_HXX_
49 #include <rtl/string.hxx>
52 //------------------------------------------------------------------------
53 //------------------------------------------------------------------------
55 #ifndef _RTL_STRING_UTILS_CONST_H_
56 #include <rtl_String_Utils_Const.h>
59 //------------------------------------------------------------------------
60 //------------------------------------------------------------------------
64 sal_uInt32
AStringLen( const sal_Char
*pAStr
)
66 sal_uInt32 nStrLen
= 0;
70 const sal_Char
*pTempStr
= pAStr
;
77 nStrLen
= (sal_uInt32
)( pTempStr
- pAStr
);
82 sal_Char
* cpystr( sal_Char
* dst
, const sal_Char
* src
)
84 const sal_Char
* psrc
= src
;
87 while( *pdst
++ = *psrc
++ );
91 sal_Char
* cpynstr( sal_Char
* dst
, const sal_Char
* src
, sal_uInt32 cnt
)
94 const sal_Char
* psrc
= src
;
99 if ( len
>= AStringLen(src
) )
101 return( cpystr( dst
, src
) );
104 // copy string by char
105 for( i
= 0; i
< len
; i
++ )
112 //------------------------------------------------------------------------
113 sal_Bool
cmpstr( const sal_Char
* str1
, const sal_Char
* str2
, sal_uInt32 len
)
115 const sal_Char
* pBuf1
= str1
;
116 const sal_Char
* pBuf2
= str2
;
119 while ( (*pBuf1
== *pBuf2
) && i
< len
)
127 //------------------------------------------------------------------------
128 sal_Bool
cmpustr( const sal_Unicode
* str1
, const sal_Unicode
* str2
, sal_uInt32 len
)
130 const sal_Unicode
* pBuf1
= str1
;
131 const sal_Unicode
* pBuf2
= str2
;
134 while ( (*pBuf1
== *pBuf2
) && i
< len
)
143 //-----------------------------------------------------------------------
144 sal_Bool
cmpustr( const sal_Unicode
* str1
, const sal_Unicode
* str2
)
146 const sal_Unicode
* pBuf1
= str1
;
147 const sal_Unicode
* pBuf2
= str2
;
148 sal_Bool res
= sal_True
;
150 while ( (*pBuf1
== *pBuf2
) && *pBuf1
!='\0' && *pBuf2
!= '\0')
155 if (*pBuf1
== '\0' && *pBuf2
== '\0')
162 sal_Char
* createName( sal_Char
* dst
, const sal_Char
* meth
, sal_uInt32 cnt
)
164 sal_Char
* pdst
= dst
;
166 sal_Char
* pstr
= nstr
;
167 rtl_str_valueOfInt32( pstr
, cnt
, 10 );
169 cpystr( pdst
, meth
);
170 cpystr( pdst
+ AStringLen(meth
), "_" );
174 cpystr(pdst
+ AStringLen(pdst
), "0" );
178 cpystr(pdst
+ AStringLen(pdst
), "0" );
181 cpystr( pdst
+ AStringLen(pdst
), nstr
);
185 //------------------------------------------------------------------------
186 // testing the method compareTo( const OString & aStr )
187 //------------------------------------------------------------------------
188 void makeComment( char *com
, const char *str1
, const char *str2
,
192 int str1Length
= AStringLen( str1
);
193 const char *sign
= (sgn
== 0) ? " == " : (sgn
> 0) ? " > " : " < " ;
194 cpystr(com
+ str1Length
, sign
);
195 int signLength
= AStringLen(sign
);
196 cpystr(com
+ str1Length
+ signLength
, str2
);
197 com
[str1Length
+ signLength
+ AStringLen(str2
)] = 0;
201 //------------------------------------------------------------------------
203 sal_Bool
AStringToFloatCompare ( const sal_Char
*pStr
,
208 sal_Bool cmp
= sal_False
;
212 ::rtl::OString
aStr(pStr
);
218 actNum
= aStr
.toFloat();
220 if ( abs( (int)(actNum
- expNum
) ) <= eps
)
227 } // AStringToFloatCompare
229 //------------------------------------------------------------------------
231 sal_Bool
AStringToDoubleCompare ( const sal_Char
*pStr
,
236 sal_Bool cmp
= sal_False
;
240 ::rtl::OString
aStr(pStr
);
246 actNum
= aStr
.toDouble();
248 if ( abs( (int)(actNum
- expNum
) ) <= eps
)
255 } // AStringToDoubleCompare
257 //------------------------------------------------------------------------
260 //------------------------------------------------------------------------
262 sal_uInt32
UStringLen( const sal_Unicode
*pUStr
)
264 sal_uInt32 nUStrLen
= 0;
268 const sal_Unicode
*pTempUStr
= pUStr
;
275 nUStrLen
= (sal_uInt32
)( pTempUStr
- pUStr
);
281 //------------------------------------------------------------------------
283 sal_Bool
AStringIsValid( const sal_Char
*pAStr
)
287 sal_uInt32 nLen
= AStringLen( pAStr
);
290 while ( ( nLen
>= 0 ) && ( *pAStr
) )
292 uChar
= (unsigned char)*pAStr
;
301 // Since we are dealing with unsigned integers
302 // we want to make sure that the last number is
319 //------------------------------------------------------------------------
321 sal_Bool
AStringNIsValid( const sal_Char
*pAStr
,
322 const sal_uInt32 nStrLen
325 sal_uInt32 nLen
= nStrLen
;
328 while ( ( nLen
>= 0 ) && ( *pAStr
) )
330 uChar
= (unsigned char)*pAStr
;
339 // Since we are dealing with unsigned integers
340 // we want to make sure that the last number is
356 //------------------------------------------------------------------------
358 static inline sal_Int32
ACharToUCharCompare( const sal_Unicode
*pUStr
,
359 const sal_Char
*pAStr
363 sal_Int32 nUChar
= (sal_Int32
)*pUStr
;
364 sal_Int32 nChar
= (sal_Int32
)((unsigned char)*pAStr
);
366 nCmp
= nUChar
- nChar
;
369 } // ACharToUCharCompare
371 //------------------------------------------------------------------------
373 sal_Int32
AStringToUStringCompare( const sal_Unicode
*pUStr
,
374 const sal_Char
*pAStr
377 sal_Int32 nCmp
= kErrCompareAStringToUString
;
379 if ( ( pUStr
!= NULL
) && ( pAStr
!= NULL
) )
381 nCmp
= ACharToUCharCompare( pUStr
, pAStr
);
383 while ( ( nCmp
== 0 ) && ( *pAStr
) )
388 nCmp
= ACharToUCharCompare( pUStr
, pAStr
);
393 } // AStringToUStringCompare
395 //------------------------------------------------------------------------
397 sal_Int32
AStringToUStringNCompare( const sal_Unicode
*pUStr
,
398 const sal_Char
*pAStr
,
399 const sal_uInt32 nAStrCount
402 sal_Int32 nCmp
= kErrCompareNAStringToUString
;
404 if ( ( pUStr
!= NULL
) && ( pAStr
!= NULL
) )
406 sal_uInt32 nCount
= nAStrCount
;
408 nCmp
= ACharToUCharCompare( pUStr
, pAStr
);
410 while ( ( nCmp
== 0 ) && ( *pAStr
) && ( nCount
) )
415 nCmp
= ACharToUCharCompare( pUStr
, pAStr
);
417 // Since we are dealing with unsigned integers
418 // we want to make sure that the last number is
433 } // AStringToUStringNCompare
435 //------------------------------------------------------------------------
437 sal_Int32
AStringToRTLUStringCompare( const rtl_uString
*pRTLUStr
,
438 const sal_Char
*pAStr
441 sal_Int32 nCmp
= kErrCompareAStringToRTLUString
;
443 if ( ( pRTLUStr
!= NULL
) && ( pAStr
!= NULL
) )
445 rtl_uString
*pRTLUStrCopy
= NULL
;
447 rtl_uString_newFromString( &pRTLUStrCopy
, pRTLUStr
);
449 if ( pRTLUStrCopy
!= NULL
)
451 const sal_Unicode
*pUStr
= rtl_uString_getStr( pRTLUStrCopy
);
455 nCmp
= AStringToUStringCompare( pUStr
, pAStr
);
458 rtl_uString_release( pRTLUStrCopy
);
465 } // AStringToRTLUStringCompare
467 //------------------------------------------------------------------------
469 sal_Int32
AStringToRTLUStringNCompare( const rtl_uString
*pRTLUStr
,
470 const sal_Char
*pAStr
,
471 const sal_uInt32 nAStrCount
474 sal_Int32 nCmp
= kErrCompareNAStringToRTLUString
;
476 if ( ( pRTLUStr
!= NULL
) && ( pAStr
!= NULL
) )
478 rtl_uString
*pRTLUStrCopy
= NULL
;
480 rtl_uString_newFromString( &pRTLUStrCopy
, pRTLUStr
);
482 if ( pRTLUStrCopy
!= NULL
)
484 const sal_Unicode
*pUStr
= rtl_uString_getStr( pRTLUStrCopy
);
488 nCmp
= AStringToUStringNCompare( pUStr
, pAStr
, nAStrCount
);
491 rtl_uString_release( pRTLUStrCopy
);
498 } // AStringToRTLUStringNCompare
500 //------------------------------------------------------------------------
502 sal_Bool
AStringToUStringCopy( sal_Unicode
*pDest
,
506 sal_Bool bCopied
= sal_False
;
507 sal_uInt32 nCount
= AStringLen( pSrc
);
508 sal_uInt32 nLen
= nCount
;
510 if ( ( pDest
!= NULL
)
512 && ( AStringNIsValid( pSrc
, nLen
) )
515 while ( nCount
>= 0 )
517 *pDest
= (unsigned char)*pSrc
;
522 // Since we are dealing with unsigned integers
523 // we want to make sure that the last number is
543 } // AStringToUStringCopy
545 //------------------------------------------------------------------------
547 sal_Bool
AStringToUStringNCopy( sal_Unicode
*pDest
,
548 const sal_Char
*pSrc
,
549 const sal_uInt32 nSrcLen
552 sal_Bool bCopied
= sal_False
;
553 sal_uInt32 nCount
= nSrcLen
;
554 sal_uInt32 nLen
= nSrcLen
;
556 if ( ( pDest
!= NULL
)
558 && ( AStringNIsValid( pSrc
, nLen
) )
561 while ( nCount
>= 0 )
563 *pDest
= (unsigned char)*pSrc
;
568 // Since we are dealing with unsigned integers
569 // we want to make sure that the last number is
589 } // AStringToUStringNCopy
591 //------------------------------------------------------------------------
592 //------------------------------------------------------------------------