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 /* ======================================================================= */
29 /* Internal C-String help functions which could be used without the */
31 /* ======================================================================= */
34 inline void rtl_str_ImplCopy( IMPL_RTL_STRCODE* pDest,
35 const IMPL_RTL_STRCODE* pSrc,
48 #define rtl_str_ImplCopy( _pDest, _pSrc, _nCount ) \
50 IMPL_RTL_STRCODE* __mm_pDest = _pDest; \
51 const IMPL_RTL_STRCODE* __mm_pSrc = _pSrc; \
52 sal_Int32 __mm_nCount = _nCount; \
53 while ( __mm_nCount > 0 ) \
55 *__mm_pDest = *__mm_pSrc; \
62 /* ======================================================================= */
63 /* C-String functions which could be used without the String-Class */
64 /* ======================================================================= */
66 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( getLength
)( const IMPL_RTL_STRCODE
* pStr
)
68 const IMPL_RTL_STRCODE
* pTempStr
= pStr
;
74 /* ----------------------------------------------------------------------- */
76 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( compare
)( const IMPL_RTL_STRCODE
* pStr1
,
77 const IMPL_RTL_STRCODE
* pStr2
)
80 while ( ((nRet
= ((sal_Int32
)(IMPL_RTL_USTRCODE(*pStr1
)))-
81 ((sal_Int32
)(IMPL_RTL_USTRCODE(*pStr2
)))) == 0) &&
91 /* ----------------------------------------------------------------------- */
93 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( compare_WithLength
)( const IMPL_RTL_STRCODE
* pStr1
,
95 const IMPL_RTL_STRCODE
* pStr2
,
98 sal_Int32 nRet
= nStr1Len
- nStr2Len
;
99 int nCount
= (nRet
<= 0) ? nStr1Len
: nStr2Len
;
103 while( (--nCount
>= 0) && (*++pStr1
== *++pStr2
) );
106 nRet
= ((sal_Int32
)(IMPL_RTL_USTRCODE( *pStr1
)))
107 - ((sal_Int32
)(IMPL_RTL_USTRCODE( *pStr2
)));
112 /* ----------------------------------------------------------------------- */
114 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( shortenedCompare_WithLength
)( const IMPL_RTL_STRCODE
* pStr1
,
116 const IMPL_RTL_STRCODE
* pStr2
,
118 sal_Int32 nShortenedLength
)
120 const IMPL_RTL_STRCODE
* pStr1End
= pStr1
+ nStr1Len
;
121 const IMPL_RTL_STRCODE
* pStr2End
= pStr2
+ nStr2Len
;
123 while ( (nShortenedLength
> 0) &&
124 (pStr1
< pStr1End
) && (pStr2
< pStr2End
) )
126 nRet
= ((sal_Int32
)(IMPL_RTL_USTRCODE( *pStr1
)))-
127 ((sal_Int32
)(IMPL_RTL_USTRCODE( *pStr2
)));
136 if ( nShortenedLength
<= 0 )
138 return nStr1Len
- nStr2Len
;
141 /* ----------------------------------------------------------------------- */
143 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( reverseCompare_WithLength
)( const IMPL_RTL_STRCODE
* pStr1
,
145 const IMPL_RTL_STRCODE
* pStr2
,
148 const IMPL_RTL_STRCODE
* pStr1Run
= pStr1
+nStr1Len
;
149 const IMPL_RTL_STRCODE
* pStr2Run
= pStr2
+nStr2Len
;
151 while ( (pStr1
< pStr1Run
) && (pStr2
< pStr2Run
) )
155 nRet
= ((sal_Int32
)(IMPL_RTL_USTRCODE( *pStr1Run
)))-
156 ((sal_Int32
)(IMPL_RTL_USTRCODE( *pStr2Run
)));
161 return nStr1Len
- nStr2Len
;
164 /* ----------------------------------------------------------------------- */
166 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( compareIgnoreAsciiCase
)( const IMPL_RTL_STRCODE
* pStr1
,
167 const IMPL_RTL_STRCODE
* pStr2
)
174 /* If character between 'A' and 'Z', than convert it to lowercase */
175 c1
= (sal_Int32
)IMPL_RTL_USTRCODE( *pStr1
);
176 c2
= (sal_Int32
)IMPL_RTL_USTRCODE( *pStr2
);
177 if ( (c1
>= 65) && (c1
<= 90) )
179 if ( (c2
>= 65) && (c2
<= 90) )
193 /* ----------------------------------------------------------------------- */
195 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( compareIgnoreAsciiCase_WithLength
)( const IMPL_RTL_STRCODE
* pStr1
,
197 const IMPL_RTL_STRCODE
* pStr2
,
200 const IMPL_RTL_STRCODE
* pStr1End
= pStr1
+ nStr1Len
;
201 const IMPL_RTL_STRCODE
* pStr2End
= pStr2
+ nStr2Len
;
205 while ( (pStr1
< pStr1End
) && (pStr2
< pStr2End
) )
207 /* If character between 'A' and 'Z', than convert it to lowercase */
208 c1
= (sal_Int32
)IMPL_RTL_USTRCODE( *pStr1
);
209 c2
= (sal_Int32
)IMPL_RTL_USTRCODE( *pStr2
);
210 if ( (c1
>= 65) && (c1
<= 90) )
212 if ( (c2
>= 65) && (c2
<= 90) )
222 return nStr1Len
- nStr2Len
;
225 /* ----------------------------------------------------------------------- */
227 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( shortenedCompareIgnoreAsciiCase_WithLength
)( const IMPL_RTL_STRCODE
* pStr1
,
229 const IMPL_RTL_STRCODE
* pStr2
,
231 sal_Int32 nShortenedLength
)
233 const IMPL_RTL_STRCODE
* pStr1End
= pStr1
+ nStr1Len
;
234 const IMPL_RTL_STRCODE
* pStr2End
= pStr2
+ nStr2Len
;
238 while ( (nShortenedLength
> 0) &&
239 (pStr1
< pStr1End
) && (pStr2
< pStr2End
) )
241 /* If character between 'A' and 'Z', than convert it to lowercase */
242 c1
= (sal_Int32
)IMPL_RTL_USTRCODE( *pStr1
);
243 c2
= (sal_Int32
)IMPL_RTL_USTRCODE( *pStr2
);
244 if ( (c1
>= 65) && (c1
<= 90) )
246 if ( (c2
>= 65) && (c2
<= 90) )
257 if ( nShortenedLength
<= 0 )
259 return nStr1Len
- nStr2Len
;
262 /* ----------------------------------------------------------------------- */
264 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( hashCode
)( const IMPL_RTL_STRCODE
* pStr
)
266 return IMPL_RTL_STRNAME( hashCode_WithLength
)( pStr
, IMPL_RTL_STRNAME( getLength
)( pStr
) );
269 /* ----------------------------------------------------------------------- */
271 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( hashCode_WithLength
)( const IMPL_RTL_STRCODE
* pStr
,
280 h
= (h
*37) + IMPL_RTL_USTRCODE( *pStr
);
288 const IMPL_RTL_STRCODE
* pEndStr
= pStr
+nLen
-5;
290 /* only sample some characters */
291 /* the first 3, some characters between, and the last 5 */
292 h
= (h
*39) + IMPL_RTL_USTRCODE( *pStr
);
294 h
= (h
*39) + IMPL_RTL_USTRCODE( *pStr
);
296 h
= (h
*39) + IMPL_RTL_USTRCODE( *pStr
);
306 h
= (h
*39) + IMPL_RTL_USTRCODE( *pStr
);
311 h
= (h
*39) + IMPL_RTL_USTRCODE( *pEndStr
);
313 h
= (h
*39) + IMPL_RTL_USTRCODE( *pEndStr
);
315 h
= (h
*39) + IMPL_RTL_USTRCODE( *pEndStr
);
317 h
= (h
*39) + IMPL_RTL_USTRCODE( *pEndStr
);
319 h
= (h
*39) + IMPL_RTL_USTRCODE( *pEndStr
);
325 /* ----------------------------------------------------------------------- */
327 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( indexOfChar
)( const IMPL_RTL_STRCODE
* pStr
,
330 const IMPL_RTL_STRCODE
* pTempStr
= pStr
;
333 if ( *pTempStr
== c
)
334 return pTempStr
-pStr
;
342 /* ----------------------------------------------------------------------- */
344 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( indexOfChar_WithLength
)( const IMPL_RTL_STRCODE
* pStr
,
348 const IMPL_RTL_STRCODE
* pTempStr
= pStr
;
351 if ( *pTempStr
== c
)
352 return pTempStr
-pStr
;
361 /* ----------------------------------------------------------------------- */
363 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( lastIndexOfChar
)( const IMPL_RTL_STRCODE
* pStr
,
366 return IMPL_RTL_STRNAME( lastIndexOfChar_WithLength
)( pStr
, IMPL_RTL_STRNAME( getLength
)( pStr
), c
);
369 /* ----------------------------------------------------------------------- */
371 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( lastIndexOfChar_WithLength
)( const IMPL_RTL_STRCODE
* pStr
,
388 /* ----------------------------------------------------------------------- */
390 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( indexOfStr
)( const IMPL_RTL_STRCODE
* pStr
,
391 const IMPL_RTL_STRCODE
* pSubStr
)
393 return IMPL_RTL_STRNAME( indexOfStr_WithLength
)( pStr
, IMPL_RTL_STRNAME( getLength
)( pStr
),
394 pSubStr
, IMPL_RTL_STRNAME( getLength
)( pSubStr
) );
397 /* ----------------------------------------------------------------------- */
399 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( indexOfStr_WithLength
)( const IMPL_RTL_STRCODE
* pStr
,
401 const IMPL_RTL_STRCODE
* pSubStr
,
404 /* faster search for a single character */
407 /* an empty SubString is always not foundable */
410 IMPL_RTL_STRCODE c
= *pSubStr
;
411 const IMPL_RTL_STRCODE
* pTempStr
= pStr
;
412 while ( nStrLen
> 0 )
414 if ( *pTempStr
== c
)
415 return pTempStr
-pStr
;
424 const IMPL_RTL_STRCODE
* pTempStr
= pStr
;
425 while ( nStrLen
> 0 )
427 if ( *pTempStr
== *pSubStr
)
429 /* Compare SubString */
430 if ( nSubLen
<= nStrLen
)
432 const IMPL_RTL_STRCODE
* pTempStr1
= pTempStr
;
433 const IMPL_RTL_STRCODE
* pTempStr2
= pSubStr
;
434 sal_Int32 nTempLen
= nSubLen
;
437 if ( *pTempStr1
!= *pTempStr2
)
446 return pTempStr
-pStr
;
460 /* ----------------------------------------------------------------------- */
462 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( lastIndexOfStr
)( const IMPL_RTL_STRCODE
* pStr
,
463 const IMPL_RTL_STRCODE
* pSubStr
)
465 return IMPL_RTL_STRNAME( lastIndexOfStr_WithLength
)( pStr
, IMPL_RTL_STRNAME( getLength
)( pStr
),
466 pSubStr
, IMPL_RTL_STRNAME( getLength
)( pSubStr
) );
469 /* ----------------------------------------------------------------------- */
471 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( lastIndexOfStr_WithLength
)( const IMPL_RTL_STRCODE
* pStr
,
473 const IMPL_RTL_STRCODE
* pSubStr
,
476 /* faster search for a single character */
479 /* an empty SubString is always not foundable */
482 IMPL_RTL_STRCODE c
= *pSubStr
;
484 while ( nStrLen
> 0 )
499 while ( nStrLen
>= 0 )
501 const IMPL_RTL_STRCODE
* pTempStr1
= pStr
;
502 const IMPL_RTL_STRCODE
* pTempStr2
= pSubStr
;
503 sal_Int32 nTempLen
= nSubLen
;
506 if ( *pTempStr1
!= *pTempStr2
)
525 /* ----------------------------------------------------------------------- */
527 void SAL_CALL
IMPL_RTL_STRNAME( replaceChar
)( IMPL_RTL_STRCODE
* pStr
,
528 IMPL_RTL_STRCODE cOld
,
529 IMPL_RTL_STRCODE cNew
)
540 /* ----------------------------------------------------------------------- */
542 void SAL_CALL
IMPL_RTL_STRNAME( replaceChar_WithLength
)( IMPL_RTL_STRCODE
* pStr
,
544 IMPL_RTL_STRCODE cOld
,
545 IMPL_RTL_STRCODE cNew
)
557 /* ----------------------------------------------------------------------- */
559 void SAL_CALL
IMPL_RTL_STRNAME( toAsciiLowerCase
)( IMPL_RTL_STRCODE
* pStr
)
563 /* Between A-Z (65-90), than to lowercase (+32) */
564 if ( (*pStr
>= 65) && (*pStr
<= 90) )
571 /* ----------------------------------------------------------------------- */
573 void SAL_CALL
IMPL_RTL_STRNAME( toAsciiLowerCase_WithLength
)( IMPL_RTL_STRCODE
* pStr
,
578 /* Between A-Z (65-90), than to lowercase (+32) */
579 if ( (*pStr
>= 65) && (*pStr
<= 90) )
587 /* ----------------------------------------------------------------------- */
589 void SAL_CALL
IMPL_RTL_STRNAME( toAsciiUpperCase
)( IMPL_RTL_STRCODE
* pStr
)
593 /* Between a-z (97-122), than to uppercase (-32) */
594 if ( (*pStr
>= 97) && (*pStr
<= 122) )
601 /* ----------------------------------------------------------------------- */
603 void SAL_CALL
IMPL_RTL_STRNAME( toAsciiUpperCase_WithLength
)( IMPL_RTL_STRCODE
* pStr
,
608 /* Between a-z (97-122), than to uppercase (-32) */
609 if ( (*pStr
>= 97) && (*pStr
<= 122) )
617 /* ----------------------------------------------------------------------- */
619 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( trim
)( IMPL_RTL_STRCODE
* pStr
)
621 return IMPL_RTL_STRNAME( trim_WithLength
)( pStr
, IMPL_RTL_STRNAME( getLength
)( pStr
) );
624 /* ----------------------------------------------------------------------- */
626 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( trim_WithLength
)( IMPL_RTL_STRCODE
* pStr
, sal_Int32 nLen
)
628 sal_Int32 nPreSpaces
= 0;
629 sal_Int32 nPostSpaces
= 0;
630 sal_Int32 nIndex
= nLen
-1;
632 while ( (nPreSpaces
< nLen
) && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE(*(pStr
+nPreSpaces
)) ) )
635 while ( (nIndex
> nPreSpaces
) && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE(*(pStr
+nIndex
)) ) )
649 IMPL_RTL_STRCODE
* pNewStr
= pStr
+nPreSpaces
;
667 /* ----------------------------------------------------------------------- */
669 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( valueOfBoolean
)( IMPL_RTL_STRCODE
* pStr
, sal_Bool b
)
701 /* ----------------------------------------------------------------------- */
703 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( valueOfChar
)( IMPL_RTL_STRCODE
* pStr
,
711 /* ----------------------------------------------------------------------- */
713 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( valueOfInt32
)( IMPL_RTL_STRCODE
* pStr
,
717 sal_Char aBuf
[RTL_STR_MAX_VALUEOFINT32
];
718 sal_Char
* pBuf
= aBuf
;
722 /* Radix must be valid */
723 if ( (nRadix
< RTL_STR_MIN_RADIX
) || (nRadix
> RTL_STR_MAX_RADIX
) )
726 /* is value negativ */
732 nValue
= -n
; /* FIXME this code is not portable for n == -2147483648
733 (smallest negative value for sal_Int32) */
738 /* create a recursive buffer with all values, except the last one */
741 sal_Char nDigit
= (sal_Char
)(nValue
% nRadix
);
744 *pBuf
= (nDigit
-10) + 'a';
746 *pBuf
= (nDigit
+ '0' );
749 while ( nValue
> 0 );
751 /* copy the values in the right direction into the destination buffer */
759 while ( pBuf
!= aBuf
);
765 /* ----------------------------------------------------------------------- */
767 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( valueOfInt64
)( IMPL_RTL_STRCODE
* pStr
,
771 sal_Char aBuf
[RTL_STR_MAX_VALUEOFINT64
];
772 sal_Char
* pBuf
= aBuf
;
776 /* Radix must be valid */
777 if ( (nRadix
< RTL_STR_MIN_RADIX
) || (nRadix
> RTL_STR_MAX_RADIX
) )
780 /* is value negativ */
786 nValue
= -n
; /* FIXME this code is not portable for
787 n == -9223372036854775808 (smallest negative value for
793 /* create a recursive buffer with all values, except the last one */
796 sal_Char nDigit
= (sal_Char
)(nValue
% nRadix
);
799 *pBuf
= (nDigit
-10) + 'a';
801 *pBuf
= (nDigit
+ '0' );
804 while ( nValue
> 0 );
806 /* copy the values in the right direction into the destination buffer */
814 while ( pBuf
!= aBuf
);
820 /* ----------------------------------------------------------------------- */
822 sal_Bool SAL_CALL
IMPL_RTL_STRNAME( toBoolean
)( const IMPL_RTL_STRCODE
* pStr
)
827 if ( (*pStr
== 'T') || (*pStr
== 't') )
830 if ( (*pStr
== 'R') || (*pStr
== 'r') )
833 if ( (*pStr
== 'U') || (*pStr
== 'u') )
836 if ( (*pStr
== 'E') || (*pStr
== 'e') )
845 /* ----------------------------------------------------------------------- */
847 sal_Int32 SAL_CALL
IMPL_RTL_STRNAME( toInt32
)( const IMPL_RTL_STRCODE
* pStr
,
854 if ( (nRadix
< RTL_STR_MIN_RADIX
) || (nRadix
> RTL_STR_MAX_RADIX
) )
857 /* Skip whitespaces */
858 while ( *pStr
&& rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE( *pStr
) ) )
875 nDigit
= rtl_ImplGetDigit( IMPL_RTL_USTRCODE( *pStr
), nRadix
);
891 /* ----------------------------------------------------------------------- */
893 sal_Int64 SAL_CALL
IMPL_RTL_STRNAME( toInt64
)( const IMPL_RTL_STRCODE
* pStr
,
900 if ( (nRadix
< RTL_STR_MIN_RADIX
) || (nRadix
> RTL_STR_MAX_RADIX
) )
903 /* Skip whitespaces */
904 while ( *pStr
&& rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE( *pStr
) ) )
921 nDigit
= rtl_ImplGetDigit( IMPL_RTL_USTRCODE( *pStr
), nRadix
);
937 /* ======================================================================= */
938 /* Internal String-Class help functions */
939 /* ======================================================================= */
941 static IMPL_RTL_STRINGDATA
* IMPL_RTL_STRINGNAME( ImplAlloc
)( sal_Int32 nLen
)
943 IMPL_RTL_STRINGDATA
* pData
944 = (SAL_INT_CAST(sal_uInt32
, nLen
)
945 <= ((SAL_MAX_UINT32
- sizeof (IMPL_RTL_STRINGDATA
))
946 / sizeof (IMPL_RTL_STRCODE
)))
947 ? (IMPL_RTL_STRINGDATA
*) rtl_allocateMemory(
948 sizeof (IMPL_RTL_STRINGDATA
) + nLen
* sizeof (IMPL_RTL_STRCODE
))
952 pData
->length
= nLen
;
953 pData
->buffer
[nLen
] = 0;
958 /* ----------------------------------------------------------------------- */
960 static IMPL_RTL_STRCODE
* IMPL_RTL_STRINGNAME( ImplNewCopy
)( IMPL_RTL_STRINGDATA
** ppThis
,
961 IMPL_RTL_STRINGDATA
* pStr
,
964 IMPL_RTL_STRCODE
* pDest
;
965 const IMPL_RTL_STRCODE
* pSrc
;
966 IMPL_RTL_STRINGDATA
* pData
= IMPL_RTL_STRINGNAME( ImplAlloc
)( pStr
->length
);
967 OSL_ASSERT(pData
!= NULL
);
969 pDest
= pData
->buffer
;
983 /* ======================================================================= */
984 /* String-Class functions */
985 /* ======================================================================= */
987 #define IMPL_RTL_AQUIRE( pThis ) \
989 if (!SAL_STRING_IS_STATIC (pThis)) \
990 osl_incrementInterlockedCount( &((pThis)->refCount) ); \
993 /* ----------------------------------------------------------------------- */
995 void SAL_CALL
IMPL_RTL_STRINGNAME( acquire
)( IMPL_RTL_STRINGDATA
* pThis
)
997 IMPL_RTL_AQUIRE( pThis
);
1000 /* ----------------------------------------------------------------------- */
1002 void SAL_CALL
IMPL_RTL_STRINGNAME( release
)( IMPL_RTL_STRINGDATA
* pThis
)
1004 if (SAL_STRING_IS_STATIC (pThis
))
1007 /* OString doesn't have an 'intern' */
1008 #ifdef IMPL_RTL_INTERN
1009 if (SAL_STRING_IS_INTERN (pThis
))
1011 internRelease (pThis
);
1016 if ( pThis
->refCount
== 1 ||
1017 !osl_decrementInterlockedCount( &(pThis
->refCount
) ) )
1019 rtl_freeMemory( pThis
);
1023 /* ----------------------------------------------------------------------- */
1025 void SAL_CALL
IMPL_RTL_STRINGNAME( new )( IMPL_RTL_STRINGDATA
** ppThis
)
1028 IMPL_RTL_STRINGNAME( release
)( *ppThis
);
1030 *ppThis
= (IMPL_RTL_STRINGDATA
*) (&IMPL_RTL_EMPTYSTRING
);
1031 IMPL_RTL_AQUIRE( *ppThis
);
1034 /* ----------------------------------------------------------------------- */
1036 void SAL_CALL
IMPL_RTL_STRINGNAME( new_WithLength
)( IMPL_RTL_STRINGDATA
** ppThis
, sal_Int32 nLen
)
1039 IMPL_RTL_STRINGNAME( new )( ppThis
);
1043 IMPL_RTL_STRINGNAME( release
)( *ppThis
);
1045 *ppThis
= IMPL_RTL_STRINGNAME( ImplAlloc
)( nLen
);
1046 OSL_ASSERT(*ppThis
!= NULL
);
1047 (*ppThis
)->length
= 0;
1050 IMPL_RTL_STRCODE
* pTempStr
= (*ppThis
)->buffer
;
1061 /* ----------------------------------------------------------------------- */
1063 void SAL_CALL
IMPL_RTL_STRINGNAME( newFromString
)( IMPL_RTL_STRINGDATA
** ppThis
,
1064 const IMPL_RTL_STRINGDATA
* pStr
)
1066 IMPL_RTL_STRINGDATA
* pOrg
;
1068 if ( !pStr
->length
)
1070 IMPL_RTL_STRINGNAME( new )( ppThis
);
1075 *ppThis
= IMPL_RTL_STRINGNAME( ImplAlloc
)( pStr
->length
);
1076 OSL_ASSERT(*ppThis
!= NULL
);
1077 rtl_str_ImplCopy( (*ppThis
)->buffer
, pStr
->buffer
, pStr
->length
);
1079 /* must be done at least, if pStr == *ppThis */
1081 IMPL_RTL_STRINGNAME( release
)( pOrg
);
1084 /* ----------------------------------------------------------------------- */
1086 void SAL_CALL
IMPL_RTL_STRINGNAME( newFromStr
)( IMPL_RTL_STRINGDATA
** ppThis
,
1087 const IMPL_RTL_STRCODE
* pCharStr
)
1089 IMPL_RTL_STRCODE
* pBuffer
;
1090 IMPL_RTL_STRINGDATA
* pOrg
;
1095 const IMPL_RTL_STRCODE
* pTempStr
= pCharStr
;
1098 nLen
= pTempStr
-pCharStr
;
1105 IMPL_RTL_STRINGNAME( new )( ppThis
);
1110 *ppThis
= IMPL_RTL_STRINGNAME( ImplAlloc
)( nLen
);
1111 OSL_ASSERT(*ppThis
!= NULL
);
1112 pBuffer
= (*ppThis
)->buffer
;
1115 *pBuffer
= *pCharStr
;
1119 while ( *pCharStr
);
1121 /* must be done at least, if pCharStr == *ppThis */
1123 IMPL_RTL_STRINGNAME( release
)( pOrg
);
1126 /* ----------------------------------------------------------------------- */
1128 void SAL_CALL
IMPL_RTL_STRINGNAME( newFromStr_WithLength
)( IMPL_RTL_STRINGDATA
** ppThis
,
1129 const IMPL_RTL_STRCODE
* pCharStr
,
1132 IMPL_RTL_STRINGDATA
* pOrg
;
1134 if ( !pCharStr
|| (nLen
<= 0) )
1136 IMPL_RTL_STRINGNAME( new )( ppThis
);
1141 *ppThis
= IMPL_RTL_STRINGNAME( ImplAlloc
)( nLen
);
1142 OSL_ASSERT(*ppThis
!= NULL
);
1143 rtl_str_ImplCopy( (*ppThis
)->buffer
, pCharStr
, nLen
);
1145 /* must be done at least, if pCharStr == *ppThis */
1147 IMPL_RTL_STRINGNAME( release
)( pOrg
);
1150 /* ----------------------------------------------------------------------- */
1152 void SAL_CALL
IMPL_RTL_STRINGNAME( assign
)( IMPL_RTL_STRINGDATA
** ppThis
,
1153 IMPL_RTL_STRINGDATA
* pStr
)
1155 /* must be done at first, if pStr == *ppThis */
1156 IMPL_RTL_AQUIRE( pStr
);
1159 IMPL_RTL_STRINGNAME( release
)( *ppThis
);
1164 /* ----------------------------------------------------------------------- */
1166 sal_Int32 SAL_CALL
IMPL_RTL_STRINGNAME( getLength
)( const IMPL_RTL_STRINGDATA
* pThis
)
1168 return pThis
->length
;
1171 /* ----------------------------------------------------------------------- */
1173 IMPL_RTL_STRCODE
* SAL_CALL
IMPL_RTL_STRINGNAME( getStr
)( IMPL_RTL_STRINGDATA
* pThis
)
1175 return pThis
->buffer
;
1178 /* ----------------------------------------------------------------------- */
1180 void SAL_CALL
IMPL_RTL_STRINGNAME( newConcat
)( IMPL_RTL_STRINGDATA
** ppThis
,
1181 IMPL_RTL_STRINGDATA
* pLeft
,
1182 IMPL_RTL_STRINGDATA
* pRight
)
1184 IMPL_RTL_STRINGDATA
* pOrg
= *ppThis
;
1186 /* Test for 0-Pointer - if not, change newReplaceStrAt! */
1187 if ( !pRight
|| !pRight
->length
)
1190 IMPL_RTL_AQUIRE( pLeft
);
1192 else if ( !pLeft
|| !pLeft
->length
)
1195 IMPL_RTL_AQUIRE( pRight
);
1199 IMPL_RTL_STRINGDATA
* pTempStr
= IMPL_RTL_STRINGNAME( ImplAlloc
)( pLeft
->length
+ pRight
->length
);
1200 OSL_ASSERT(pTempStr
!= NULL
);
1201 rtl_str_ImplCopy( pTempStr
->buffer
, pLeft
->buffer
, pLeft
->length
);
1202 rtl_str_ImplCopy( pTempStr
->buffer
+pLeft
->length
, pRight
->buffer
, pRight
->length
);
1206 /* must be done at least, if left or right == *ppThis */
1208 IMPL_RTL_STRINGNAME( release
)( pOrg
);
1211 /* ----------------------------------------------------------------------- */
1213 void SAL_CALL
IMPL_RTL_STRINGNAME( newReplaceStrAt
)( IMPL_RTL_STRINGDATA
** ppThis
,
1214 IMPL_RTL_STRINGDATA
* pStr
,
1217 IMPL_RTL_STRINGDATA
* pNewSubStr
)
1220 if ( nIndex
>= pStr
->length
)
1222 /* newConcat test, if pNewSubStr is 0 */
1223 IMPL_RTL_STRINGNAME( newConcat
)( ppThis
, pStr
, pNewSubStr
);
1227 /* negativ index? */
1234 /* not more than the String length could be deleted */
1235 if ( nCount
>= pStr
->length
-nIndex
)
1237 nCount
= pStr
->length
-nIndex
;
1239 /* Assign of NewSubStr? */
1240 if ( !nIndex
&& (nCount
>= pStr
->length
) )
1243 IMPL_RTL_STRINGNAME( new )( ppThis
);
1245 IMPL_RTL_STRINGNAME( assign
)( ppThis
, pNewSubStr
);
1250 /* Assign of Str? */
1251 if ( !nCount
&& (!pNewSubStr
|| !pNewSubStr
->length
) )
1253 IMPL_RTL_STRINGNAME( assign
)( ppThis
, pStr
);
1258 IMPL_RTL_STRINGDATA
* pOrg
= *ppThis
;
1259 IMPL_RTL_STRCODE
* pBuffer
;
1262 /* Calculate length of the new string */
1263 nNewLen
= pStr
->length
-nCount
;
1265 nNewLen
+= pNewSubStr
->length
;
1267 /* Alloc New Buffer */
1268 *ppThis
= IMPL_RTL_STRINGNAME( ImplAlloc
)( nNewLen
);
1269 OSL_ASSERT(*ppThis
!= NULL
);
1270 pBuffer
= (*ppThis
)->buffer
;
1273 rtl_str_ImplCopy( pBuffer
, pStr
->buffer
, nIndex
);
1276 if ( pNewSubStr
&& pNewSubStr
->length
)
1278 rtl_str_ImplCopy( pBuffer
, pNewSubStr
->buffer
, pNewSubStr
->length
);
1279 pBuffer
+= pNewSubStr
->length
;
1281 rtl_str_ImplCopy( pBuffer
, pStr
->buffer
+nIndex
+nCount
, pStr
->length
-nIndex
-nCount
);
1283 /* must be done at least, if pStr or pNewSubStr == *ppThis */
1285 IMPL_RTL_STRINGNAME( release
)( pOrg
);
1289 /* ----------------------------------------------------------------------- */
1291 void SAL_CALL
IMPL_RTL_STRINGNAME( newReplace
)( IMPL_RTL_STRINGDATA
** ppThis
,
1292 IMPL_RTL_STRINGDATA
* pStr
,
1293 IMPL_RTL_STRCODE cOld
,
1294 IMPL_RTL_STRCODE cNew
)
1296 IMPL_RTL_STRINGDATA
* pOrg
= *ppThis
;
1298 sal_Int32 nLen
= pStr
->length
;
1299 const IMPL_RTL_STRCODE
* pCharStr
= pStr
->buffer
;
1303 if ( *pCharStr
== cOld
)
1306 IMPL_RTL_STRCODE
* pNewCharStr
= IMPL_RTL_STRINGNAME( ImplNewCopy
)( ppThis
, pStr
, pCharStr
-pStr
->buffer
);
1308 /* replace/copy rest of the string */
1311 *pNewCharStr
= cNew
;
1318 if ( *pCharStr
== cOld
)
1319 *pNewCharStr
= cNew
;
1321 *pNewCharStr
= *pCharStr
;
1340 IMPL_RTL_AQUIRE( pStr
);
1343 /* must be done at least, if pStr == *ppThis */
1345 IMPL_RTL_STRINGNAME( release
)( pOrg
);
1348 /* ----------------------------------------------------------------------- */
1350 void SAL_CALL
IMPL_RTL_STRINGNAME( newToAsciiLowerCase
)( IMPL_RTL_STRINGDATA
** ppThis
,
1351 IMPL_RTL_STRINGDATA
* pStr
)
1353 IMPL_RTL_STRINGDATA
* pOrg
= *ppThis
;
1355 sal_Int32 nLen
= pStr
->length
;
1356 const IMPL_RTL_STRCODE
* pCharStr
= pStr
->buffer
;
1360 /* Between A-Z (65-90), than to lowercase (+32) */
1361 if ( (*pCharStr
>= 65) && (*pCharStr
<= 90) )
1364 IMPL_RTL_STRCODE
* pNewCharStr
= IMPL_RTL_STRINGNAME( ImplNewCopy
)( ppThis
, pStr
, pCharStr
-pStr
->buffer
);
1366 /* replace/copy rest of the string */
1369 /* to lowercase (+32) */
1370 *pNewCharStr
= *pCharStr
+32;
1377 /* Between A-Z (65-90), than to lowercase (+32) */
1378 if ( (*pCharStr
>= 65) && (*pCharStr
<= 90) )
1379 *pNewCharStr
= *pCharStr
+32;
1381 *pNewCharStr
= *pCharStr
;
1400 IMPL_RTL_AQUIRE( pStr
);
1403 /* must be done at least, if pStr == *ppThis */
1405 IMPL_RTL_STRINGNAME( release
)( pOrg
);
1408 /* ----------------------------------------------------------------------- */
1410 void SAL_CALL
IMPL_RTL_STRINGNAME( newToAsciiUpperCase
)( IMPL_RTL_STRINGDATA
** ppThis
,
1411 IMPL_RTL_STRINGDATA
* pStr
)
1413 IMPL_RTL_STRINGDATA
* pOrg
= *ppThis
;
1415 sal_Int32 nLen
= pStr
->length
;
1416 const IMPL_RTL_STRCODE
* pCharStr
= pStr
->buffer
;
1420 /* Between a-z (97-122), than to uppercase (-32) */
1421 if ( (*pCharStr
>= 97) && (*pCharStr
<= 122) )
1424 IMPL_RTL_STRCODE
* pNewCharStr
= IMPL_RTL_STRINGNAME( ImplNewCopy
)( ppThis
, pStr
, pCharStr
-pStr
->buffer
);
1426 /* replace/copy rest of the string */
1429 /* to uppercase (-32) */
1430 *pNewCharStr
= *pCharStr
-32;
1437 /* Between a-z (97-122), than to uppercase (-32) */
1438 if ( (*pCharStr
>= 97) && (*pCharStr
<= 122) )
1439 *pNewCharStr
= *pCharStr
-32;
1441 *pNewCharStr
= *pCharStr
;
1460 IMPL_RTL_AQUIRE( pStr
);
1463 /* must be done at least, if pStr == *ppThis */
1465 IMPL_RTL_STRINGNAME( release
)( pOrg
);
1468 /* ----------------------------------------------------------------------- */
1470 void SAL_CALL
IMPL_RTL_STRINGNAME( newTrim
)( IMPL_RTL_STRINGDATA
** ppThis
,
1471 IMPL_RTL_STRINGDATA
* pStr
)
1473 IMPL_RTL_STRINGDATA
* pOrg
= *ppThis
;
1474 const IMPL_RTL_STRCODE
* pCharStr
= pStr
->buffer
;
1475 sal_Int32 nPreSpaces
= 0;
1476 sal_Int32 nPostSpaces
= 0;
1477 sal_Int32 nLen
= pStr
->length
;
1478 sal_Int32 nIndex
= nLen
-1;
1480 while ( (nPreSpaces
< nLen
) && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE(*(pCharStr
+nPreSpaces
)) ) )
1483 while ( (nIndex
> nPreSpaces
) && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE(*(pCharStr
+nIndex
)) ) )
1489 if ( !nPreSpaces
&& !nPostSpaces
)
1492 IMPL_RTL_AQUIRE( pStr
);
1496 nLen
-= nPostSpaces
+nPreSpaces
;
1497 *ppThis
= IMPL_RTL_STRINGNAME( ImplAlloc
)( nLen
);
1498 OSL_ASSERT(*ppThis
!= NULL
);
1500 rtl_str_ImplCopy( (*ppThis
)->buffer
, pStr
->buffer
+nPreSpaces
, nLen
);
1503 /* must be done at least, if pStr == *ppThis */
1505 IMPL_RTL_STRINGNAME( release
)( pOrg
);
1508 /* ----------------------------------------------------------------------- */
1510 sal_Int32 SAL_CALL
IMPL_RTL_STRINGNAME( getToken
)( IMPL_RTL_STRINGDATA
** ppThis
,
1511 IMPL_RTL_STRINGDATA
* pStr
,
1513 IMPL_RTL_STRCODE cTok
,
1516 const IMPL_RTL_STRCODE
* pCharStr
= pStr
->buffer
;
1517 const IMPL_RTL_STRCODE
* pCharStrStart
;
1518 const IMPL_RTL_STRCODE
* pOrgCharStr
;
1519 sal_Int32 nLen
= pStr
->length
-nIndex
;
1520 sal_Int32 nTokCount
= 0;
1522 // Set ppThis to an empty string and return -1 if either nToken or nIndex is
1529 pOrgCharStr
= pCharStr
;
1530 pCharStrStart
= pCharStr
;
1533 if ( *pCharStr
== cTok
)
1537 if ( nTokCount
== nToken
)
1538 pCharStrStart
= pCharStr
+1;
1541 if ( nTokCount
> nToken
)
1550 if ( (nToken
< 0) || (nTokCount
< nToken
) || (pCharStr
== pCharStrStart
) )
1552 IMPL_RTL_STRINGNAME( new )( ppThis
);
1553 if( (nToken
< 0) || (nTokCount
< nToken
) )
1556 return nIndex
+(pCharStr
-pOrgCharStr
)+1;
1561 IMPL_RTL_STRINGNAME( newFromStr_WithLength
)( ppThis
, pCharStrStart
, pCharStr
-pCharStrStart
);
1563 return nIndex
+(pCharStr
-pOrgCharStr
)+1;