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