1*87d2adbcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*87d2adbcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*87d2adbcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*87d2adbcSAndrew Rist  * distributed with this work for additional information
6*87d2adbcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*87d2adbcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*87d2adbcSAndrew Rist  * "License"); you may not use this file except in compliance
9*87d2adbcSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*87d2adbcSAndrew Rist  *
11*87d2adbcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*87d2adbcSAndrew Rist  *
13*87d2adbcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*87d2adbcSAndrew Rist  * software distributed under the License is distributed on an
15*87d2adbcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*87d2adbcSAndrew Rist  * KIND, either express or implied.  See the License for the
17*87d2adbcSAndrew Rist  * specific language governing permissions and limitations
18*87d2adbcSAndrew Rist  * under the License.
19*87d2adbcSAndrew Rist  *
20*87d2adbcSAndrew Rist  *************************************************************/
21*87d2adbcSAndrew Rist 
22*87d2adbcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sal.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir //------------------------------------------------------------------------
28cdf0e10cSrcweir //------------------------------------------------------------------------
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <math.h>
31cdf0e10cSrcweir #include <stdlib.h>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir //------------------------------------------------------------------------
34cdf0e10cSrcweir //------------------------------------------------------------------------
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #ifndef _SAL_TYPES_H_
37cdf0e10cSrcweir 	#include <sal/types.h>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #ifndef _RTL_USTRING_H_
41cdf0e10cSrcweir 	#include <rtl/ustring.h>
42cdf0e10cSrcweir #endif
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #ifndef _RTL_STRING_HXX_
45cdf0e10cSrcweir 	#include <rtl/string.hxx>
46cdf0e10cSrcweir #endif
47cdf0e10cSrcweir 
48cdf0e10cSrcweir //------------------------------------------------------------------------
49cdf0e10cSrcweir //------------------------------------------------------------------------
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #ifndef _RTL_STRING_UTILS_CONST_H_
52cdf0e10cSrcweir 	#include <rtl_String_Utils_Const.h>
53cdf0e10cSrcweir #endif
54cdf0e10cSrcweir 
55cdf0e10cSrcweir //------------------------------------------------------------------------
56cdf0e10cSrcweir //------------------------------------------------------------------------
57cdf0e10cSrcweir 
58cdf0e10cSrcweir using namespace rtl;
59cdf0e10cSrcweir 
AStringLen(const sal_Char * pAStr)60cdf0e10cSrcweir sal_uInt32 AStringLen( const sal_Char *pAStr )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	sal_uInt32  nStrLen = 0;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 	if ( pAStr != NULL )
65cdf0e10cSrcweir 	{
66cdf0e10cSrcweir 		const sal_Char *pTempStr = pAStr;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 		while( *pTempStr )
69cdf0e10cSrcweir 		{
70cdf0e10cSrcweir 			pTempStr++;
71cdf0e10cSrcweir 		} // while
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 		nStrLen = (sal_uInt32)( pTempStr - pAStr );
74cdf0e10cSrcweir 	} // if
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 	return nStrLen;
77cdf0e10cSrcweir } // AStringLen
78cdf0e10cSrcweir /* disable assignment within condition expression */
79cdf0e10cSrcweir #ifdef WNT
80cdf0e10cSrcweir #pragma warning( disable : 4706 )
81cdf0e10cSrcweir #endif
cpystr(sal_Char * dst,const sal_Char * src)82cdf0e10cSrcweir sal_Char* cpystr( sal_Char* dst, const sal_Char* src )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir     const sal_Char* psrc = src;
85cdf0e10cSrcweir     sal_Char* pdst = dst;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     while( (*pdst++ = *psrc++) );
88cdf0e10cSrcweir     return ( dst );
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
cpynstr(sal_Char * dst,const sal_Char * src,sal_uInt32 cnt)91cdf0e10cSrcweir sal_Char* cpynstr( sal_Char* dst, const sal_Char* src, sal_uInt32 cnt )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     const sal_Char* psrc = src;
95cdf0e10cSrcweir     sal_Char* pdst = dst;
96cdf0e10cSrcweir     sal_uInt32 len = cnt;
97cdf0e10cSrcweir     sal_uInt32 i;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     if ( len >= AStringLen(src) )
100cdf0e10cSrcweir     {
101cdf0e10cSrcweir         return( cpystr( dst, src ) );
102cdf0e10cSrcweir     }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     // copy string by char
105cdf0e10cSrcweir     for( i = 0; i < len; i++ )
106cdf0e10cSrcweir         *pdst++ = *psrc++;
107cdf0e10cSrcweir     *pdst = '\0';
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     return ( dst );
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir //------------------------------------------------------------------------
cmpstr(const sal_Char * str1,const sal_Char * str2,sal_uInt32 len)113cdf0e10cSrcweir sal_Bool cmpstr( const sal_Char* str1, const sal_Char* str2, sal_uInt32 len )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     const sal_Char* pBuf1 = str1;
116cdf0e10cSrcweir     const sal_Char* pBuf2 = str2;
117cdf0e10cSrcweir     sal_uInt32 i = 0;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     while ( (*pBuf1 == *pBuf2) && i < len )
120cdf0e10cSrcweir     {
121cdf0e10cSrcweir         (pBuf1)++;
122cdf0e10cSrcweir         (pBuf2)++;
123cdf0e10cSrcweir         i++;
124cdf0e10cSrcweir     }
125cdf0e10cSrcweir     return( i == len );
126cdf0e10cSrcweir }
127cdf0e10cSrcweir //-----------------------------------------------------------------------
cmpstr(const sal_Char * str1,const sal_Char * str2)128cdf0e10cSrcweir sal_Bool cmpstr( const sal_Char* str1, const sal_Char* str2 )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir     const sal_Char* pBuf1 = str1;
131cdf0e10cSrcweir     const sal_Char* pBuf2 = str2;
132cdf0e10cSrcweir     sal_Bool res = sal_True;
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     while ( (*pBuf1 == *pBuf2) && *pBuf1 !='\0' && *pBuf2 != '\0')
135cdf0e10cSrcweir     {
136cdf0e10cSrcweir         (pBuf1)++;
137cdf0e10cSrcweir         (pBuf2)++;
138cdf0e10cSrcweir     }
139cdf0e10cSrcweir     if (*pBuf1 == '\0' && *pBuf2 == '\0')
140cdf0e10cSrcweir         res = sal_True;
141cdf0e10cSrcweir     else
142cdf0e10cSrcweir         res = sal_False;
143cdf0e10cSrcweir     return (res);
144cdf0e10cSrcweir }
145cdf0e10cSrcweir //------------------------------------------------------------------------
cmpustr(const sal_Unicode * str1,const sal_Unicode * str2,sal_uInt32 len)146cdf0e10cSrcweir sal_Bool cmpustr( const sal_Unicode* str1, const sal_Unicode* str2, sal_uInt32 len )
147cdf0e10cSrcweir {
148cdf0e10cSrcweir     const sal_Unicode* pBuf1 = str1;
149cdf0e10cSrcweir     const sal_Unicode* pBuf2 = str2;
150cdf0e10cSrcweir     sal_uInt32 i = 0;
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     while ( (*pBuf1 == *pBuf2) && i < len )
153cdf0e10cSrcweir     {
154cdf0e10cSrcweir         (pBuf1)++;
155cdf0e10cSrcweir         (pBuf2)++;
156cdf0e10cSrcweir         i++;
157cdf0e10cSrcweir     }
158cdf0e10cSrcweir     return( i == len );
159cdf0e10cSrcweir }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir //-----------------------------------------------------------------------
cmpustr(const sal_Unicode * str1,const sal_Unicode * str2)162cdf0e10cSrcweir sal_Bool cmpustr( const sal_Unicode* str1, const sal_Unicode* str2 )
163cdf0e10cSrcweir {
164cdf0e10cSrcweir     const sal_Unicode* pBuf1 = str1;
165cdf0e10cSrcweir     const sal_Unicode* pBuf2 = str2;
166cdf0e10cSrcweir     sal_Bool res = sal_True;
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     while ( (*pBuf1 == *pBuf2) && *pBuf1 !='\0' && *pBuf2 != '\0')
169cdf0e10cSrcweir     {
170cdf0e10cSrcweir         (pBuf1)++;
171cdf0e10cSrcweir         (pBuf2)++;
172cdf0e10cSrcweir     }
173cdf0e10cSrcweir     if (*pBuf1 == '\0' && *pBuf2 == '\0')
174cdf0e10cSrcweir         res = sal_True;
175cdf0e10cSrcweir     else
176cdf0e10cSrcweir         res = sal_False;
177cdf0e10cSrcweir     return (res);
178cdf0e10cSrcweir }
179cdf0e10cSrcweir 
createName(sal_Char * dst,const sal_Char * meth,sal_uInt32 cnt)180cdf0e10cSrcweir sal_Char* createName( sal_Char* dst, const sal_Char* meth, sal_uInt32 cnt )
181cdf0e10cSrcweir {
182cdf0e10cSrcweir     sal_Char* pdst = dst;
183cdf0e10cSrcweir     sal_Char nstr[16];
184cdf0e10cSrcweir     sal_Char* pstr = nstr;
185cdf0e10cSrcweir     rtl_str_valueOfInt32( pstr, cnt, 10 );
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     cpystr( pdst, meth );
188cdf0e10cSrcweir     cpystr( pdst+ AStringLen(meth), "_" );
189cdf0e10cSrcweir 
190cdf0e10cSrcweir     if ( cnt < 100 )
191cdf0e10cSrcweir     {
192cdf0e10cSrcweir         cpystr(pdst + AStringLen(pdst), "0" );
193cdf0e10cSrcweir     }
194cdf0e10cSrcweir     if ( cnt < 10 )
195cdf0e10cSrcweir     {
196cdf0e10cSrcweir         cpystr(pdst + AStringLen(pdst), "0" );
197cdf0e10cSrcweir     }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir     cpystr( pdst + AStringLen(pdst), nstr );
200cdf0e10cSrcweir     return( pdst );
201cdf0e10cSrcweir }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir //------------------------------------------------------------------------
204cdf0e10cSrcweir //  testing the method compareTo( const OString & aStr )
205cdf0e10cSrcweir //------------------------------------------------------------------------
makeComment(char * com,const char * str1,const char * str2,sal_Int32 sgn)206cdf0e10cSrcweir void makeComment( char *com, const char *str1, const char *str2,
207cdf0e10cSrcweir                                                             sal_Int32 sgn )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir     cpystr(com, str1);
210cdf0e10cSrcweir     int str1Length = AStringLen( str1 );
211cdf0e10cSrcweir     const char *sign = (sgn == 0) ? " == " : (sgn > 0) ? " > " : " < " ;
212cdf0e10cSrcweir     cpystr(com + str1Length, sign);
213cdf0e10cSrcweir     int signLength = AStringLen(sign);
214cdf0e10cSrcweir     cpystr(com + str1Length + signLength, str2);
215cdf0e10cSrcweir     com[str1Length + signLength + AStringLen(str2)] = 0;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 
219cdf0e10cSrcweir //------------------------------------------------------------------------
220cdf0e10cSrcweir 
AStringToFloatCompare(const sal_Char * pStr,const float nX,const float nEPS)221cdf0e10cSrcweir sal_Bool AStringToFloatCompare ( const sal_Char  *pStr,
222cdf0e10cSrcweir                                  const float      nX,
223cdf0e10cSrcweir                                  const float      nEPS
224cdf0e10cSrcweir                                 )
225cdf0e10cSrcweir {
226cdf0e10cSrcweir 	sal_Bool cmp = sal_False;
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 	if ( pStr != NULL )
229cdf0e10cSrcweir 	{
230cdf0e10cSrcweir 		::rtl::OString aStr(pStr);
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 		float actNum = 0;
233cdf0e10cSrcweir 		float expNum = nX;
234cdf0e10cSrcweir 		float eps    = nEPS;
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 		actNum = aStr.toFloat();
237cdf0e10cSrcweir 
238cdf0e10cSrcweir         if ( abs( (int)(actNum - expNum) ) <= eps )
239cdf0e10cSrcweir 		{
240cdf0e10cSrcweir 			cmp = sal_True;
241cdf0e10cSrcweir 		} // if
242cdf0e10cSrcweir 	} // if
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 	return cmp;
245cdf0e10cSrcweir } // AStringToFloatCompare
246cdf0e10cSrcweir 
247cdf0e10cSrcweir //------------------------------------------------------------------------
248cdf0e10cSrcweir 
AStringToDoubleCompare(const sal_Char * pStr,const double nX,const double nEPS)249cdf0e10cSrcweir sal_Bool AStringToDoubleCompare ( const sal_Char  *pStr,
250cdf0e10cSrcweir                                   const double     nX,
251cdf0e10cSrcweir                                   const double     nEPS
252cdf0e10cSrcweir                                 )
253cdf0e10cSrcweir {
254cdf0e10cSrcweir 	sal_Bool cmp = sal_False;
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 	if ( pStr != NULL )
257cdf0e10cSrcweir 	{
258cdf0e10cSrcweir 		::rtl::OString aStr(pStr);
259cdf0e10cSrcweir 
260cdf0e10cSrcweir 		double actNum = 0;
261cdf0e10cSrcweir 		double expNum = nX;
262cdf0e10cSrcweir 		double eps    = nEPS;
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 		actNum = aStr.toDouble();
265cdf0e10cSrcweir 
266cdf0e10cSrcweir         if ( abs( (int)(actNum - expNum) ) <= eps )
267cdf0e10cSrcweir 		{
268cdf0e10cSrcweir 			cmp = sal_True;
269cdf0e10cSrcweir 		} // if
270cdf0e10cSrcweir 	} // if
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 	return cmp;
273cdf0e10cSrcweir } // AStringToDoubleCompare
274cdf0e10cSrcweir 
275cdf0e10cSrcweir //------------------------------------------------------------------------
276cdf0e10cSrcweir 
277cdf0e10cSrcweir 
278cdf0e10cSrcweir //------------------------------------------------------------------------
279cdf0e10cSrcweir 
UStringLen(const sal_Unicode * pUStr)280cdf0e10cSrcweir sal_uInt32 UStringLen( const sal_Unicode *pUStr )
281cdf0e10cSrcweir {
282cdf0e10cSrcweir 	sal_uInt32 nUStrLen = 0;
283cdf0e10cSrcweir 
284cdf0e10cSrcweir 	if ( pUStr != NULL )
285cdf0e10cSrcweir 	{
286cdf0e10cSrcweir 		const sal_Unicode *pTempUStr = pUStr;
287cdf0e10cSrcweir 
288cdf0e10cSrcweir 		while( *pTempUStr )
289cdf0e10cSrcweir 		{
290cdf0e10cSrcweir 			pTempUStr++;
291cdf0e10cSrcweir 		} // while
292cdf0e10cSrcweir 
293cdf0e10cSrcweir 		nUStrLen = (sal_uInt32)( pTempUStr - pUStr );
294cdf0e10cSrcweir 	} // if
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 	return nUStrLen;
297cdf0e10cSrcweir } // UStringLen
298cdf0e10cSrcweir 
299cdf0e10cSrcweir //------------------------------------------------------------------------
300cdf0e10cSrcweir 
AStringIsValid(const sal_Char * pAStr)301cdf0e10cSrcweir sal_Bool AStringIsValid( const sal_Char  *pAStr )
302cdf0e10cSrcweir {
303cdf0e10cSrcweir 	if ( pAStr != NULL )
304cdf0e10cSrcweir 	{
305cdf0e10cSrcweir 		sal_uInt32 nLen  = AStringLen( pAStr );
306cdf0e10cSrcweir 		sal_uChar  uChar = 0;
307cdf0e10cSrcweir 
308cdf0e10cSrcweir 		while ( *pAStr )
309cdf0e10cSrcweir 		{
310cdf0e10cSrcweir 			uChar = (unsigned char)*pAStr;
311cdf0e10cSrcweir 
312cdf0e10cSrcweir 			if ( uChar > 127 )
313cdf0e10cSrcweir 			{
314cdf0e10cSrcweir 				return sal_False;
315cdf0e10cSrcweir 			} // if
316cdf0e10cSrcweir 
317cdf0e10cSrcweir 			pAStr++;
318cdf0e10cSrcweir 
319cdf0e10cSrcweir 			// Since we are dealing with unsigned integers
320cdf0e10cSrcweir 			// we want to make sure that the last number is
321cdf0e10cSrcweir 			// indeed zero.
322cdf0e10cSrcweir 
323cdf0e10cSrcweir 			if ( nLen > 0 )
324cdf0e10cSrcweir 			{
325cdf0e10cSrcweir 				nLen--;
326cdf0e10cSrcweir 			} // if
327cdf0e10cSrcweir 			else
328cdf0e10cSrcweir 			{
329cdf0e10cSrcweir 				break;
330cdf0e10cSrcweir 			} // else
331cdf0e10cSrcweir 		} // while
332cdf0e10cSrcweir 	} // if
333cdf0e10cSrcweir 
334cdf0e10cSrcweir 	return sal_True;
335cdf0e10cSrcweir } // AStringIsValid
336cdf0e10cSrcweir 
337cdf0e10cSrcweir //------------------------------------------------------------------------
338cdf0e10cSrcweir 
AStringNIsValid(const sal_Char * pAStr,const sal_uInt32 nStrLen)339cdf0e10cSrcweir sal_Bool AStringNIsValid( const sal_Char   *pAStr,
340cdf0e10cSrcweir                           const sal_uInt32  nStrLen
341cdf0e10cSrcweir                         )
342cdf0e10cSrcweir {
343cdf0e10cSrcweir 	sal_uInt32 nLen  = nStrLen;
344cdf0e10cSrcweir 	sal_uChar  uChar = 0;
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 	while ( *pAStr )
347cdf0e10cSrcweir 	{
348cdf0e10cSrcweir 		uChar = (unsigned char)*pAStr;
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 		if ( uChar > 127 )
351cdf0e10cSrcweir 		{
352cdf0e10cSrcweir 			return sal_False;
353cdf0e10cSrcweir 		} // if
354cdf0e10cSrcweir 
355cdf0e10cSrcweir 		pAStr++;
356cdf0e10cSrcweir 
357cdf0e10cSrcweir 		// Since we are dealing with unsigned integers
358cdf0e10cSrcweir 		// we want to make sure that the last number is
359cdf0e10cSrcweir 		// indeed zero.
360cdf0e10cSrcweir 
361cdf0e10cSrcweir 		if ( nLen > 0 )
362cdf0e10cSrcweir 		{
363cdf0e10cSrcweir 			nLen--;
364cdf0e10cSrcweir 		} // if
365cdf0e10cSrcweir 		else
366cdf0e10cSrcweir 		{
367cdf0e10cSrcweir 			break;
368cdf0e10cSrcweir 		} // else
369cdf0e10cSrcweir 	} // while
370cdf0e10cSrcweir 
371cdf0e10cSrcweir 	return sal_True;
372cdf0e10cSrcweir } // AStringNIsValid
373cdf0e10cSrcweir 
374cdf0e10cSrcweir //------------------------------------------------------------------------
375cdf0e10cSrcweir 
ACharToUCharCompare(const sal_Unicode * pUStr,const sal_Char * pAStr)376cdf0e10cSrcweir static inline sal_Int32 ACharToUCharCompare( const sal_Unicode *pUStr,
377cdf0e10cSrcweir                                              const sal_Char    *pAStr
378cdf0e10cSrcweir                                            )
379cdf0e10cSrcweir {
380cdf0e10cSrcweir 	sal_Int32  nCmp   = 0;
381cdf0e10cSrcweir 	sal_Int32  nUChar = (sal_Int32)*pUStr;
382cdf0e10cSrcweir 	sal_Int32  nChar  = (sal_Int32)((unsigned char)*pAStr);
383cdf0e10cSrcweir 
384cdf0e10cSrcweir 	nCmp = nUChar - nChar;
385cdf0e10cSrcweir 
386cdf0e10cSrcweir 	return  nCmp;
387cdf0e10cSrcweir } // ACharToUCharCompare
388cdf0e10cSrcweir 
389cdf0e10cSrcweir //------------------------------------------------------------------------
390cdf0e10cSrcweir 
AStringToUStringCompare(const sal_Unicode * pUStr,const sal_Char * pAStr)391cdf0e10cSrcweir sal_Int32 AStringToUStringCompare( const sal_Unicode *pUStr,
392cdf0e10cSrcweir                                    const sal_Char    *pAStr
393cdf0e10cSrcweir                                  )
394cdf0e10cSrcweir {
395cdf0e10cSrcweir  	sal_Int32 nCmp = kErrCompareAStringToUString;
396cdf0e10cSrcweir 
397cdf0e10cSrcweir 	if ( ( pUStr != NULL ) && ( pAStr != NULL ) )
398cdf0e10cSrcweir 	{
399cdf0e10cSrcweir 		nCmp = ACharToUCharCompare( pUStr, pAStr );
400cdf0e10cSrcweir 
401cdf0e10cSrcweir 		while ( ( nCmp == 0 ) && ( *pAStr ) )
402cdf0e10cSrcweir 		{
403cdf0e10cSrcweir 			pUStr++;
404cdf0e10cSrcweir 			pAStr++;
405cdf0e10cSrcweir 
406cdf0e10cSrcweir 			nCmp = ACharToUCharCompare( pUStr, pAStr );
407cdf0e10cSrcweir 		} // while
408cdf0e10cSrcweir 	} // if
409cdf0e10cSrcweir 
410cdf0e10cSrcweir 	return nCmp;
411cdf0e10cSrcweir } // AStringToUStringCompare
412cdf0e10cSrcweir 
413cdf0e10cSrcweir //------------------------------------------------------------------------
414cdf0e10cSrcweir 
AStringToUStringNCompare(const sal_Unicode * pUStr,const sal_Char * pAStr,const sal_uInt32 nAStrCount)415cdf0e10cSrcweir sal_Int32 AStringToUStringNCompare( const sal_Unicode  *pUStr,
416cdf0e10cSrcweir                                     const sal_Char     *pAStr,
417cdf0e10cSrcweir                                     const sal_uInt32    nAStrCount
418cdf0e10cSrcweir                                    )
419cdf0e10cSrcweir {
420cdf0e10cSrcweir 	sal_Int32 nCmp = kErrCompareNAStringToUString;
421cdf0e10cSrcweir 
422cdf0e10cSrcweir 	if ( ( pUStr != NULL ) && ( pAStr != NULL ) )
423cdf0e10cSrcweir 	{
424cdf0e10cSrcweir 		sal_uInt32 nCount = nAStrCount;
425cdf0e10cSrcweir 
426cdf0e10cSrcweir 		nCmp = ACharToUCharCompare( pUStr, pAStr );
427cdf0e10cSrcweir 
428cdf0e10cSrcweir 		while ( ( nCmp == 0 ) && ( *pAStr ) && ( nCount ) )
429cdf0e10cSrcweir 		{
430cdf0e10cSrcweir 			pUStr++;
431cdf0e10cSrcweir 			pAStr++;
432cdf0e10cSrcweir 
433cdf0e10cSrcweir 			nCmp = ACharToUCharCompare( pUStr, pAStr );
434cdf0e10cSrcweir 
435cdf0e10cSrcweir 			// Since we are dealing with unsigned integers
436cdf0e10cSrcweir 			// we want to make sure that the last number is
437cdf0e10cSrcweir 			// indeed zero.
438cdf0e10cSrcweir 
439cdf0e10cSrcweir 			if ( nCount > 0 )
440cdf0e10cSrcweir 			{
441cdf0e10cSrcweir 				nCount--;
442cdf0e10cSrcweir 			} // if
443cdf0e10cSrcweir 			else
444cdf0e10cSrcweir 			{
445cdf0e10cSrcweir 				break;
446cdf0e10cSrcweir 			} // else
447cdf0e10cSrcweir 		} // while
448cdf0e10cSrcweir 	} // if
449cdf0e10cSrcweir 
450cdf0e10cSrcweir 	return nCmp;
451cdf0e10cSrcweir } // AStringToUStringNCompare
452cdf0e10cSrcweir 
453cdf0e10cSrcweir //------------------------------------------------------------------------
454cdf0e10cSrcweir 
AStringToRTLUStringCompare(const rtl_uString * pRTLUStr,const sal_Char * pAStr)455cdf0e10cSrcweir sal_Int32 AStringToRTLUStringCompare( const rtl_uString  *pRTLUStr,
456cdf0e10cSrcweir                                       const sal_Char     *pAStr
457cdf0e10cSrcweir                                     )
458cdf0e10cSrcweir {
459cdf0e10cSrcweir 	sal_Int32 nCmp = kErrCompareAStringToRTLUString;
460cdf0e10cSrcweir 
461cdf0e10cSrcweir 	if ( ( pRTLUStr != NULL ) && ( pAStr != NULL ) )
462cdf0e10cSrcweir 	{
463cdf0e10cSrcweir 		rtl_uString *pRTLUStrCopy = NULL;
464cdf0e10cSrcweir 
465cdf0e10cSrcweir 		rtl_uString_newFromString( &pRTLUStrCopy, pRTLUStr );
466cdf0e10cSrcweir 
467cdf0e10cSrcweir 		if ( pRTLUStrCopy != NULL )
468cdf0e10cSrcweir 		{
469cdf0e10cSrcweir 			const sal_Unicode *pUStr = rtl_uString_getStr( pRTLUStrCopy );
470cdf0e10cSrcweir 
471cdf0e10cSrcweir 			if ( pUStr != NULL )
472cdf0e10cSrcweir 			{
473cdf0e10cSrcweir 				nCmp = AStringToUStringCompare( pUStr, pAStr );
474cdf0e10cSrcweir 			} // if
475cdf0e10cSrcweir 
476cdf0e10cSrcweir 			rtl_uString_release( pRTLUStrCopy );
477cdf0e10cSrcweir 
478cdf0e10cSrcweir 			pRTLUStrCopy = NULL;
479cdf0e10cSrcweir 		} // if
480cdf0e10cSrcweir 	} // if
481cdf0e10cSrcweir 
482cdf0e10cSrcweir 	return nCmp;
483cdf0e10cSrcweir } // AStringToRTLUStringCompare
484cdf0e10cSrcweir 
485cdf0e10cSrcweir //------------------------------------------------------------------------
486cdf0e10cSrcweir 
AStringToRTLUStringNCompare(const rtl_uString * pRTLUStr,const sal_Char * pAStr,const sal_uInt32 nAStrCount)487cdf0e10cSrcweir sal_Int32 AStringToRTLUStringNCompare( const rtl_uString  *pRTLUStr,
488cdf0e10cSrcweir                                        const sal_Char     *pAStr,
489cdf0e10cSrcweir                                        const sal_uInt32    nAStrCount
490cdf0e10cSrcweir                                      )
491cdf0e10cSrcweir {
492cdf0e10cSrcweir 	sal_Int32 nCmp = kErrCompareNAStringToRTLUString;
493cdf0e10cSrcweir 
494cdf0e10cSrcweir 	if ( ( pRTLUStr != NULL ) && ( pAStr != NULL ) )
495cdf0e10cSrcweir 	{
496cdf0e10cSrcweir 		rtl_uString *pRTLUStrCopy = NULL;
497cdf0e10cSrcweir 
498cdf0e10cSrcweir 		rtl_uString_newFromString( &pRTLUStrCopy, pRTLUStr );
499cdf0e10cSrcweir 
500cdf0e10cSrcweir 		if ( pRTLUStrCopy != NULL )
501cdf0e10cSrcweir 		{
502cdf0e10cSrcweir 			const sal_Unicode  *pUStr = rtl_uString_getStr( pRTLUStrCopy );
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 			if ( pUStr != NULL )
505cdf0e10cSrcweir 			{
506cdf0e10cSrcweir 				nCmp = AStringToUStringNCompare( pUStr, pAStr, nAStrCount );
507cdf0e10cSrcweir 			} // if
508cdf0e10cSrcweir 
509cdf0e10cSrcweir 			rtl_uString_release( pRTLUStrCopy );
510cdf0e10cSrcweir 
511cdf0e10cSrcweir 			pRTLUStrCopy = NULL;
512cdf0e10cSrcweir 		} // if
513cdf0e10cSrcweir 	} // if
514cdf0e10cSrcweir 
515cdf0e10cSrcweir 	return nCmp;
516cdf0e10cSrcweir } // AStringToRTLUStringNCompare
517cdf0e10cSrcweir 
518cdf0e10cSrcweir //------------------------------------------------------------------------
519cdf0e10cSrcweir 
AStringToUStringCopy(sal_Unicode * pDest,const sal_Char * pSrc)520cdf0e10cSrcweir sal_Bool AStringToUStringCopy( sal_Unicode     *pDest,
521cdf0e10cSrcweir                                const sal_Char  *pSrc
522cdf0e10cSrcweir                              )
523cdf0e10cSrcweir {
524cdf0e10cSrcweir 	sal_Bool    bCopied = sal_False;
525cdf0e10cSrcweir 	sal_uInt32  nCount  = AStringLen( pSrc );
526cdf0e10cSrcweir 	sal_uInt32  nLen    = nCount;
527cdf0e10cSrcweir 
528cdf0e10cSrcweir 	if (    ( pDest != NULL )
529cdf0e10cSrcweir 	     && ( pSrc  != NULL )
530cdf0e10cSrcweir 	     && ( AStringNIsValid( pSrc, nLen ) )
531cdf0e10cSrcweir 	   )
532cdf0e10cSrcweir 	{
533cdf0e10cSrcweir 		for (;;)
534cdf0e10cSrcweir 		{
535cdf0e10cSrcweir 			*pDest = (unsigned char)*pSrc;
536cdf0e10cSrcweir 
537cdf0e10cSrcweir 			pDest++;
538cdf0e10cSrcweir 			pSrc++;
539cdf0e10cSrcweir 
540cdf0e10cSrcweir 			// Since we are dealing with unsigned integers
541cdf0e10cSrcweir 			// we want to make sure that the last number is
542cdf0e10cSrcweir 			// indeed zero.
543cdf0e10cSrcweir 
544cdf0e10cSrcweir 			if ( nCount > 0 )
545cdf0e10cSrcweir 			{
546cdf0e10cSrcweir 				nCount--;
547cdf0e10cSrcweir 			} // if
548cdf0e10cSrcweir 			else
549cdf0e10cSrcweir 			{
550cdf0e10cSrcweir 				break;
551cdf0e10cSrcweir 			} // else
552cdf0e10cSrcweir 		} // while
553cdf0e10cSrcweir 
554cdf0e10cSrcweir 		if ( nCount == 0 )
555cdf0e10cSrcweir 		{
556cdf0e10cSrcweir 			bCopied = sal_True;
557cdf0e10cSrcweir 		} // if
558cdf0e10cSrcweir 	} // if
559cdf0e10cSrcweir 
560cdf0e10cSrcweir 	return  bCopied;
561cdf0e10cSrcweir } // AStringToUStringCopy
562cdf0e10cSrcweir 
563cdf0e10cSrcweir //------------------------------------------------------------------------
564cdf0e10cSrcweir 
AStringToUStringNCopy(sal_Unicode * pDest,const sal_Char * pSrc,const sal_uInt32 nSrcLen)565cdf0e10cSrcweir sal_Bool AStringToUStringNCopy( sal_Unicode       *pDest,
566cdf0e10cSrcweir                                 const sal_Char    *pSrc,
567cdf0e10cSrcweir                                 const sal_uInt32   nSrcLen
568cdf0e10cSrcweir                               )
569cdf0e10cSrcweir {
570cdf0e10cSrcweir 	sal_Bool    bCopied = sal_False;
571cdf0e10cSrcweir 	sal_uInt32  nCount  = nSrcLen;
572cdf0e10cSrcweir 	sal_uInt32  nLen    = nSrcLen;
573cdf0e10cSrcweir 
574cdf0e10cSrcweir 	if (    ( pDest != NULL )
575cdf0e10cSrcweir 	     && ( pSrc  != NULL )
576cdf0e10cSrcweir 	     && ( AStringNIsValid( pSrc, nLen ) )
577cdf0e10cSrcweir 	   )
578cdf0e10cSrcweir 	{
579cdf0e10cSrcweir         for (;;)
580cdf0e10cSrcweir 		{
581cdf0e10cSrcweir 			*pDest = (unsigned char)*pSrc;
582cdf0e10cSrcweir 
583cdf0e10cSrcweir 			pDest++;
584cdf0e10cSrcweir 			pSrc++;
585cdf0e10cSrcweir 
586cdf0e10cSrcweir 			// Since we are dealing with unsigned integers
587cdf0e10cSrcweir 			// we want to make sure that the last number is
588cdf0e10cSrcweir 			// indeed zero.
589cdf0e10cSrcweir 
590cdf0e10cSrcweir 			if ( nCount > 0 )
591cdf0e10cSrcweir 			{
592cdf0e10cSrcweir 				nCount--;
593cdf0e10cSrcweir 			} // if
594cdf0e10cSrcweir 			else
595cdf0e10cSrcweir 			{
596cdf0e10cSrcweir 				break;
597cdf0e10cSrcweir 			} // else
598cdf0e10cSrcweir 		} // while
599cdf0e10cSrcweir 
600cdf0e10cSrcweir 		if ( nCount == 0 )
601cdf0e10cSrcweir 		{
602cdf0e10cSrcweir 			bCopied = sal_True;
603cdf0e10cSrcweir 		} // if
604cdf0e10cSrcweir 	} // if
605cdf0e10cSrcweir 
606cdf0e10cSrcweir 	return  bCopied;
607cdf0e10cSrcweir } // AStringToUStringNCopy
608cdf0e10cSrcweir 
609cdf0e10cSrcweir //------------------------------------------------------------------------
610cdf0e10cSrcweir //------------------------------------------------------------------------
611cdf0e10cSrcweir 
612