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
cpystr(sal_Char * dst,const sal_Char * src)78cdf0e10cSrcweir sal_Char* cpystr( sal_Char* dst, const sal_Char* src )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir const sal_Char* psrc = src;
81cdf0e10cSrcweir sal_Char* pdst = dst;
82cdf0e10cSrcweir
83cdf0e10cSrcweir while( *pdst++ = *psrc++ );
84cdf0e10cSrcweir return ( dst );
85cdf0e10cSrcweir }
86cdf0e10cSrcweir
cpynstr(sal_Char * dst,const sal_Char * src,sal_uInt32 cnt)87cdf0e10cSrcweir sal_Char* cpynstr( sal_Char* dst, const sal_Char* src, sal_uInt32 cnt )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir
90cdf0e10cSrcweir const sal_Char* psrc = src;
91cdf0e10cSrcweir sal_Char* pdst = dst;
92cdf0e10cSrcweir sal_uInt32 len = cnt;
93cdf0e10cSrcweir sal_uInt32 i;
94cdf0e10cSrcweir
95cdf0e10cSrcweir if ( len >= AStringLen(src) )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir return( cpystr( dst, src ) );
98cdf0e10cSrcweir }
99cdf0e10cSrcweir
100cdf0e10cSrcweir // copy string by char
101cdf0e10cSrcweir for( i = 0; i < len; i++ )
102cdf0e10cSrcweir *pdst++ = *psrc++;
103cdf0e10cSrcweir *pdst = '\0';
104cdf0e10cSrcweir
105cdf0e10cSrcweir return ( dst );
106cdf0e10cSrcweir }
107cdf0e10cSrcweir
108cdf0e10cSrcweir //------------------------------------------------------------------------
cmpstr(const sal_Char * str1,const sal_Char * str2,sal_uInt32 len)109cdf0e10cSrcweir sal_Bool cmpstr( const sal_Char* str1, const sal_Char* str2, sal_uInt32 len )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir const sal_Char* pBuf1 = str1;
112cdf0e10cSrcweir const sal_Char* pBuf2 = str2;
113cdf0e10cSrcweir sal_uInt32 i = 0;
114cdf0e10cSrcweir
115cdf0e10cSrcweir while ( (*pBuf1 == *pBuf2) && i < len )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir (pBuf1)++;
118cdf0e10cSrcweir (pBuf2)++;
119cdf0e10cSrcweir i++;
120cdf0e10cSrcweir }
121cdf0e10cSrcweir return( i == len );
122cdf0e10cSrcweir }
123cdf0e10cSrcweir //------------------------------------------------------------------------
cmpustr(const sal_Unicode * str1,const sal_Unicode * str2,sal_uInt32 len)124cdf0e10cSrcweir sal_Bool cmpustr( const sal_Unicode* str1, const sal_Unicode* str2, sal_uInt32 len )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir const sal_Unicode* pBuf1 = str1;
127cdf0e10cSrcweir const sal_Unicode* pBuf2 = str2;
128cdf0e10cSrcweir sal_uInt32 i = 0;
129cdf0e10cSrcweir
130cdf0e10cSrcweir while ( (*pBuf1 == *pBuf2) && i < len )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir (pBuf1)++;
133cdf0e10cSrcweir (pBuf2)++;
134cdf0e10cSrcweir i++;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir return( i == len );
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir //-----------------------------------------------------------------------
cmpustr(const sal_Unicode * str1,const sal_Unicode * str2)140cdf0e10cSrcweir sal_Bool cmpustr( const sal_Unicode* str1, const sal_Unicode* str2 )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir const sal_Unicode* pBuf1 = str1;
143cdf0e10cSrcweir const sal_Unicode* pBuf2 = str2;
144cdf0e10cSrcweir sal_Bool res = sal_True;
145cdf0e10cSrcweir
146cdf0e10cSrcweir while ( (*pBuf1 == *pBuf2) && *pBuf1 !='\0' && *pBuf2 != '\0')
147cdf0e10cSrcweir {
148cdf0e10cSrcweir (pBuf1)++;
149cdf0e10cSrcweir (pBuf2)++;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir if (*pBuf1 == '\0' && *pBuf2 == '\0')
152cdf0e10cSrcweir res = sal_True;
153cdf0e10cSrcweir else
154cdf0e10cSrcweir res = sal_False;
155cdf0e10cSrcweir return (res);
156cdf0e10cSrcweir }
157cdf0e10cSrcweir
createName(sal_Char * dst,const sal_Char * meth,sal_uInt32 cnt)158cdf0e10cSrcweir sal_Char* createName( sal_Char* dst, const sal_Char* meth, sal_uInt32 cnt )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir sal_Char* pdst = dst;
161cdf0e10cSrcweir sal_Char nstr[16];
162cdf0e10cSrcweir sal_Char* pstr = nstr;
163cdf0e10cSrcweir rtl_str_valueOfInt32( pstr, cnt, 10 );
164cdf0e10cSrcweir
165cdf0e10cSrcweir cpystr( pdst, meth );
166cdf0e10cSrcweir cpystr( pdst+ AStringLen(meth), "_" );
167cdf0e10cSrcweir
168cdf0e10cSrcweir if ( cnt < 100 )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir cpystr(pdst + AStringLen(pdst), "0" );
171cdf0e10cSrcweir }
172cdf0e10cSrcweir if ( cnt < 10 )
173cdf0e10cSrcweir {
174cdf0e10cSrcweir cpystr(pdst + AStringLen(pdst), "0" );
175cdf0e10cSrcweir }
176cdf0e10cSrcweir
177cdf0e10cSrcweir cpystr( pdst + AStringLen(pdst), nstr );
178cdf0e10cSrcweir return( pdst );
179cdf0e10cSrcweir }
180cdf0e10cSrcweir
181cdf0e10cSrcweir //------------------------------------------------------------------------
182cdf0e10cSrcweir // testing the method compareTo( const OString & aStr )
183cdf0e10cSrcweir //------------------------------------------------------------------------
makeComment(char * com,const char * str1,const char * str2,sal_Int32 sgn)184cdf0e10cSrcweir void makeComment( char *com, const char *str1, const char *str2,
185cdf0e10cSrcweir sal_Int32 sgn )
186cdf0e10cSrcweir {
187cdf0e10cSrcweir cpystr(com, str1);
188cdf0e10cSrcweir int str1Length = AStringLen( str1 );
189cdf0e10cSrcweir const char *sign = (sgn == 0) ? " == " : (sgn > 0) ? " > " : " < " ;
190cdf0e10cSrcweir cpystr(com + str1Length, sign);
191cdf0e10cSrcweir int signLength = AStringLen(sign);
192cdf0e10cSrcweir cpystr(com + str1Length + signLength, str2);
193cdf0e10cSrcweir com[str1Length + signLength + AStringLen(str2)] = 0;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir
196cdf0e10cSrcweir
197cdf0e10cSrcweir //------------------------------------------------------------------------
198cdf0e10cSrcweir
AStringToFloatCompare(const sal_Char * pStr,const float nX,const float nEPS)199cdf0e10cSrcweir sal_Bool AStringToFloatCompare ( const sal_Char *pStr,
200cdf0e10cSrcweir const float nX,
201cdf0e10cSrcweir const float nEPS
202cdf0e10cSrcweir )
203cdf0e10cSrcweir {
204cdf0e10cSrcweir sal_Bool cmp = sal_False;
205cdf0e10cSrcweir
206cdf0e10cSrcweir if ( pStr != NULL )
207cdf0e10cSrcweir {
208cdf0e10cSrcweir ::rtl::OString aStr(pStr);
209cdf0e10cSrcweir
210cdf0e10cSrcweir float actNum = 0;
211cdf0e10cSrcweir float expNum = nX;
212cdf0e10cSrcweir float eps = nEPS;
213cdf0e10cSrcweir
214cdf0e10cSrcweir actNum = aStr.toFloat();
215cdf0e10cSrcweir
216cdf0e10cSrcweir if ( abs( (int)(actNum - expNum) ) <= eps )
217cdf0e10cSrcweir {
218cdf0e10cSrcweir cmp = sal_True;
219cdf0e10cSrcweir } // if
220cdf0e10cSrcweir } // if
221cdf0e10cSrcweir
222cdf0e10cSrcweir return cmp;
223cdf0e10cSrcweir } // AStringToFloatCompare
224cdf0e10cSrcweir
225cdf0e10cSrcweir //------------------------------------------------------------------------
226cdf0e10cSrcweir
AStringToDoubleCompare(const sal_Char * pStr,const double nX,const double nEPS)227cdf0e10cSrcweir sal_Bool AStringToDoubleCompare ( const sal_Char *pStr,
228cdf0e10cSrcweir const double nX,
229cdf0e10cSrcweir const double nEPS
230cdf0e10cSrcweir )
231cdf0e10cSrcweir {
232cdf0e10cSrcweir sal_Bool cmp = sal_False;
233cdf0e10cSrcweir
234cdf0e10cSrcweir if ( pStr != NULL )
235cdf0e10cSrcweir {
236cdf0e10cSrcweir ::rtl::OString aStr(pStr);
237cdf0e10cSrcweir
238cdf0e10cSrcweir double actNum = 0;
239cdf0e10cSrcweir double expNum = nX;
240cdf0e10cSrcweir double eps = nEPS;
241cdf0e10cSrcweir
242cdf0e10cSrcweir actNum = aStr.toDouble();
243cdf0e10cSrcweir
244cdf0e10cSrcweir if ( abs( (int)(actNum - expNum) ) <= eps )
245cdf0e10cSrcweir {
246cdf0e10cSrcweir cmp = sal_True;
247cdf0e10cSrcweir } // if
248cdf0e10cSrcweir } // if
249cdf0e10cSrcweir
250cdf0e10cSrcweir return cmp;
251cdf0e10cSrcweir } // AStringToDoubleCompare
252cdf0e10cSrcweir
253cdf0e10cSrcweir //------------------------------------------------------------------------
254cdf0e10cSrcweir
255cdf0e10cSrcweir
256cdf0e10cSrcweir //------------------------------------------------------------------------
257cdf0e10cSrcweir
UStringLen(const sal_Unicode * pUStr)258cdf0e10cSrcweir sal_uInt32 UStringLen( const sal_Unicode *pUStr )
259cdf0e10cSrcweir {
260cdf0e10cSrcweir sal_uInt32 nUStrLen = 0;
261cdf0e10cSrcweir
262cdf0e10cSrcweir if ( pUStr != NULL )
263cdf0e10cSrcweir {
264cdf0e10cSrcweir const sal_Unicode *pTempUStr = pUStr;
265cdf0e10cSrcweir
266cdf0e10cSrcweir while( *pTempUStr )
267cdf0e10cSrcweir {
268cdf0e10cSrcweir pTempUStr++;
269cdf0e10cSrcweir } // while
270cdf0e10cSrcweir
271cdf0e10cSrcweir nUStrLen = (sal_uInt32)( pTempUStr - pUStr );
272cdf0e10cSrcweir } // if
273cdf0e10cSrcweir
274cdf0e10cSrcweir return nUStrLen;
275cdf0e10cSrcweir } // UStringLen
276cdf0e10cSrcweir
277cdf0e10cSrcweir //------------------------------------------------------------------------
278cdf0e10cSrcweir
AStringIsValid(const sal_Char * pAStr)279cdf0e10cSrcweir sal_Bool AStringIsValid( const sal_Char *pAStr )
280cdf0e10cSrcweir {
281cdf0e10cSrcweir if ( pAStr != NULL )
282cdf0e10cSrcweir {
283cdf0e10cSrcweir sal_uInt32 nLen = AStringLen( pAStr );
284cdf0e10cSrcweir sal_uChar uChar = 0;
285cdf0e10cSrcweir
286cdf0e10cSrcweir while ( ( nLen >= 0 ) && ( *pAStr ) )
287cdf0e10cSrcweir {
288cdf0e10cSrcweir uChar = (unsigned char)*pAStr;
289cdf0e10cSrcweir
290cdf0e10cSrcweir if ( uChar > 127 )
291cdf0e10cSrcweir {
292cdf0e10cSrcweir return sal_False;
293cdf0e10cSrcweir } // if
294cdf0e10cSrcweir
295cdf0e10cSrcweir pAStr++;
296cdf0e10cSrcweir
297cdf0e10cSrcweir // Since we are dealing with unsigned integers
298cdf0e10cSrcweir // we want to make sure that the last number is
299cdf0e10cSrcweir // indeed zero.
300cdf0e10cSrcweir
301cdf0e10cSrcweir if ( nLen > 0 )
302cdf0e10cSrcweir {
303cdf0e10cSrcweir nLen--;
304cdf0e10cSrcweir } // if
305cdf0e10cSrcweir else
306cdf0e10cSrcweir {
307cdf0e10cSrcweir break;
308cdf0e10cSrcweir } // else
309cdf0e10cSrcweir } // while
310cdf0e10cSrcweir } // if
311cdf0e10cSrcweir
312cdf0e10cSrcweir return sal_True;
313cdf0e10cSrcweir } // AStringIsValid
314cdf0e10cSrcweir
315cdf0e10cSrcweir //------------------------------------------------------------------------
316cdf0e10cSrcweir
AStringNIsValid(const sal_Char * pAStr,const sal_uInt32 nStrLen)317cdf0e10cSrcweir sal_Bool AStringNIsValid( const sal_Char *pAStr,
318cdf0e10cSrcweir const sal_uInt32 nStrLen
319cdf0e10cSrcweir )
320cdf0e10cSrcweir {
321cdf0e10cSrcweir sal_uInt32 nLen = nStrLen;
322cdf0e10cSrcweir sal_uChar uChar = 0;
323cdf0e10cSrcweir
324cdf0e10cSrcweir while ( ( nLen >= 0 ) && ( *pAStr ) )
325cdf0e10cSrcweir {
326cdf0e10cSrcweir uChar = (unsigned char)*pAStr;
327cdf0e10cSrcweir
328cdf0e10cSrcweir if ( uChar > 127 )
329cdf0e10cSrcweir {
330cdf0e10cSrcweir return sal_False;
331cdf0e10cSrcweir } // if
332cdf0e10cSrcweir
333cdf0e10cSrcweir pAStr++;
334cdf0e10cSrcweir
335cdf0e10cSrcweir // Since we are dealing with unsigned integers
336cdf0e10cSrcweir // we want to make sure that the last number is
337cdf0e10cSrcweir // indeed zero.
338cdf0e10cSrcweir
339cdf0e10cSrcweir if ( nLen > 0 )
340cdf0e10cSrcweir {
341cdf0e10cSrcweir nLen--;
342cdf0e10cSrcweir } // if
343cdf0e10cSrcweir else
344cdf0e10cSrcweir {
345cdf0e10cSrcweir break;
346cdf0e10cSrcweir } // else
347cdf0e10cSrcweir } // while
348cdf0e10cSrcweir
349cdf0e10cSrcweir return sal_True;
350cdf0e10cSrcweir } // AStringNIsValid
351cdf0e10cSrcweir
352cdf0e10cSrcweir //------------------------------------------------------------------------
353cdf0e10cSrcweir
ACharToUCharCompare(const sal_Unicode * pUStr,const sal_Char * pAStr)354cdf0e10cSrcweir static inline sal_Int32 ACharToUCharCompare( const sal_Unicode *pUStr,
355cdf0e10cSrcweir const sal_Char *pAStr
356cdf0e10cSrcweir )
357cdf0e10cSrcweir {
358cdf0e10cSrcweir sal_Int32 nCmp = 0;
359cdf0e10cSrcweir sal_Int32 nUChar = (sal_Int32)*pUStr;
360cdf0e10cSrcweir sal_Int32 nChar = (sal_Int32)((unsigned char)*pAStr);
361cdf0e10cSrcweir
362cdf0e10cSrcweir nCmp = nUChar - nChar;
363cdf0e10cSrcweir
364cdf0e10cSrcweir return nCmp;
365cdf0e10cSrcweir } // ACharToUCharCompare
366cdf0e10cSrcweir
367cdf0e10cSrcweir //------------------------------------------------------------------------
368cdf0e10cSrcweir
AStringToUStringCompare(const sal_Unicode * pUStr,const sal_Char * pAStr)369cdf0e10cSrcweir sal_Int32 AStringToUStringCompare( const sal_Unicode *pUStr,
370cdf0e10cSrcweir const sal_Char *pAStr
371cdf0e10cSrcweir )
372cdf0e10cSrcweir {
373cdf0e10cSrcweir sal_Int32 nCmp = kErrCompareAStringToUString;
374cdf0e10cSrcweir
375cdf0e10cSrcweir if ( ( pUStr != NULL ) && ( pAStr != NULL ) )
376cdf0e10cSrcweir {
377cdf0e10cSrcweir nCmp = ACharToUCharCompare( pUStr, pAStr );
378cdf0e10cSrcweir
379cdf0e10cSrcweir while ( ( nCmp == 0 ) && ( *pAStr ) )
380cdf0e10cSrcweir {
381cdf0e10cSrcweir pUStr++;
382cdf0e10cSrcweir pAStr++;
383cdf0e10cSrcweir
384cdf0e10cSrcweir nCmp = ACharToUCharCompare( pUStr, pAStr );
385cdf0e10cSrcweir } // while
386cdf0e10cSrcweir } // if
387cdf0e10cSrcweir
388cdf0e10cSrcweir return nCmp;
389cdf0e10cSrcweir } // AStringToUStringCompare
390cdf0e10cSrcweir
391cdf0e10cSrcweir //------------------------------------------------------------------------
392cdf0e10cSrcweir
AStringToUStringNCompare(const sal_Unicode * pUStr,const sal_Char * pAStr,const sal_uInt32 nAStrCount)393cdf0e10cSrcweir sal_Int32 AStringToUStringNCompare( const sal_Unicode *pUStr,
394cdf0e10cSrcweir const sal_Char *pAStr,
395cdf0e10cSrcweir const sal_uInt32 nAStrCount
396cdf0e10cSrcweir )
397cdf0e10cSrcweir {
398cdf0e10cSrcweir sal_Int32 nCmp = kErrCompareNAStringToUString;
399cdf0e10cSrcweir
400cdf0e10cSrcweir if ( ( pUStr != NULL ) && ( pAStr != NULL ) )
401cdf0e10cSrcweir {
402cdf0e10cSrcweir sal_uInt32 nCount = nAStrCount;
403cdf0e10cSrcweir
404cdf0e10cSrcweir nCmp = ACharToUCharCompare( pUStr, pAStr );
405cdf0e10cSrcweir
406cdf0e10cSrcweir while ( ( nCmp == 0 ) && ( *pAStr ) && ( nCount ) )
407cdf0e10cSrcweir {
408cdf0e10cSrcweir pUStr++;
409cdf0e10cSrcweir pAStr++;
410cdf0e10cSrcweir
411cdf0e10cSrcweir nCmp = ACharToUCharCompare( pUStr, pAStr );
412cdf0e10cSrcweir
413cdf0e10cSrcweir // Since we are dealing with unsigned integers
414cdf0e10cSrcweir // we want to make sure that the last number is
415cdf0e10cSrcweir // indeed zero.
416cdf0e10cSrcweir
417cdf0e10cSrcweir if ( nCount > 0 )
418cdf0e10cSrcweir {
419cdf0e10cSrcweir nCount--;
420cdf0e10cSrcweir } // if
421cdf0e10cSrcweir else
422cdf0e10cSrcweir {
423cdf0e10cSrcweir break;
424cdf0e10cSrcweir } // else
425cdf0e10cSrcweir } // while
426cdf0e10cSrcweir } // if
427cdf0e10cSrcweir
428cdf0e10cSrcweir return nCmp;
429cdf0e10cSrcweir } // AStringToUStringNCompare
430cdf0e10cSrcweir
431cdf0e10cSrcweir //------------------------------------------------------------------------
432cdf0e10cSrcweir
AStringToRTLUStringCompare(const rtl_uString * pRTLUStr,const sal_Char * pAStr)433cdf0e10cSrcweir sal_Int32 AStringToRTLUStringCompare( const rtl_uString *pRTLUStr,
434cdf0e10cSrcweir const sal_Char *pAStr
435cdf0e10cSrcweir )
436cdf0e10cSrcweir {
437cdf0e10cSrcweir sal_Int32 nCmp = kErrCompareAStringToRTLUString;
438cdf0e10cSrcweir
439cdf0e10cSrcweir if ( ( pRTLUStr != NULL ) && ( pAStr != NULL ) )
440cdf0e10cSrcweir {
441cdf0e10cSrcweir rtl_uString *pRTLUStrCopy = NULL;
442cdf0e10cSrcweir
443cdf0e10cSrcweir rtl_uString_newFromString( &pRTLUStrCopy, pRTLUStr );
444cdf0e10cSrcweir
445cdf0e10cSrcweir if ( pRTLUStrCopy != NULL )
446cdf0e10cSrcweir {
447cdf0e10cSrcweir const sal_Unicode *pUStr = rtl_uString_getStr( pRTLUStrCopy );
448cdf0e10cSrcweir
449cdf0e10cSrcweir if ( pUStr != NULL )
450cdf0e10cSrcweir {
451cdf0e10cSrcweir nCmp = AStringToUStringCompare( pUStr, pAStr );
452cdf0e10cSrcweir } // if
453cdf0e10cSrcweir
454cdf0e10cSrcweir rtl_uString_release( pRTLUStrCopy );
455cdf0e10cSrcweir
456cdf0e10cSrcweir pRTLUStrCopy = NULL;
457cdf0e10cSrcweir } // if
458cdf0e10cSrcweir } // if
459cdf0e10cSrcweir
460cdf0e10cSrcweir return nCmp;
461cdf0e10cSrcweir } // AStringToRTLUStringCompare
462cdf0e10cSrcweir
463cdf0e10cSrcweir //------------------------------------------------------------------------
464cdf0e10cSrcweir
AStringToRTLUStringNCompare(const rtl_uString * pRTLUStr,const sal_Char * pAStr,const sal_uInt32 nAStrCount)465cdf0e10cSrcweir sal_Int32 AStringToRTLUStringNCompare( const rtl_uString *pRTLUStr,
466cdf0e10cSrcweir const sal_Char *pAStr,
467cdf0e10cSrcweir const sal_uInt32 nAStrCount
468cdf0e10cSrcweir )
469cdf0e10cSrcweir {
470cdf0e10cSrcweir sal_Int32 nCmp = kErrCompareNAStringToRTLUString;
471cdf0e10cSrcweir
472cdf0e10cSrcweir if ( ( pRTLUStr != NULL ) && ( pAStr != NULL ) )
473cdf0e10cSrcweir {
474cdf0e10cSrcweir rtl_uString *pRTLUStrCopy = NULL;
475cdf0e10cSrcweir
476cdf0e10cSrcweir rtl_uString_newFromString( &pRTLUStrCopy, pRTLUStr );
477cdf0e10cSrcweir
478cdf0e10cSrcweir if ( pRTLUStrCopy != NULL )
479cdf0e10cSrcweir {
480cdf0e10cSrcweir const sal_Unicode *pUStr = rtl_uString_getStr( pRTLUStrCopy );
481cdf0e10cSrcweir
482cdf0e10cSrcweir if ( pUStr != NULL )
483cdf0e10cSrcweir {
484cdf0e10cSrcweir nCmp = AStringToUStringNCompare( pUStr, pAStr, nAStrCount );
485cdf0e10cSrcweir } // if
486cdf0e10cSrcweir
487cdf0e10cSrcweir rtl_uString_release( pRTLUStrCopy );
488cdf0e10cSrcweir
489cdf0e10cSrcweir pRTLUStrCopy = NULL;
490cdf0e10cSrcweir } // if
491cdf0e10cSrcweir } // if
492cdf0e10cSrcweir
493cdf0e10cSrcweir return nCmp;
494cdf0e10cSrcweir } // AStringToRTLUStringNCompare
495cdf0e10cSrcweir
496cdf0e10cSrcweir //------------------------------------------------------------------------
497cdf0e10cSrcweir
AStringToUStringCopy(sal_Unicode * pDest,const sal_Char * pSrc)498cdf0e10cSrcweir sal_Bool AStringToUStringCopy( sal_Unicode *pDest,
499cdf0e10cSrcweir const sal_Char *pSrc
500cdf0e10cSrcweir )
501cdf0e10cSrcweir {
502cdf0e10cSrcweir sal_Bool bCopied = sal_False;
503cdf0e10cSrcweir sal_uInt32 nCount = AStringLen( pSrc );
504cdf0e10cSrcweir sal_uInt32 nLen = nCount;
505cdf0e10cSrcweir
506cdf0e10cSrcweir if ( ( pDest != NULL )
507cdf0e10cSrcweir && ( pSrc != NULL )
508cdf0e10cSrcweir && ( AStringNIsValid( pSrc, nLen ) )
509cdf0e10cSrcweir )
510cdf0e10cSrcweir {
511cdf0e10cSrcweir while ( nCount >= 0 )
512cdf0e10cSrcweir {
513cdf0e10cSrcweir *pDest = (unsigned char)*pSrc;
514cdf0e10cSrcweir
515cdf0e10cSrcweir pDest++;
516cdf0e10cSrcweir pSrc++;
517cdf0e10cSrcweir
518cdf0e10cSrcweir // Since we are dealing with unsigned integers
519cdf0e10cSrcweir // we want to make sure that the last number is
520cdf0e10cSrcweir // indeed zero.
521cdf0e10cSrcweir
522cdf0e10cSrcweir if ( nCount > 0 )
523cdf0e10cSrcweir {
524cdf0e10cSrcweir nCount--;
525cdf0e10cSrcweir } // if
526cdf0e10cSrcweir else
527cdf0e10cSrcweir {
528cdf0e10cSrcweir break;
529cdf0e10cSrcweir } // else
530cdf0e10cSrcweir } // while
531cdf0e10cSrcweir
532cdf0e10cSrcweir if ( nCount == 0 )
533cdf0e10cSrcweir {
534cdf0e10cSrcweir bCopied = sal_True;
535cdf0e10cSrcweir } // if
536cdf0e10cSrcweir } // if
537cdf0e10cSrcweir
538cdf0e10cSrcweir return bCopied;
539cdf0e10cSrcweir } // AStringToUStringCopy
540cdf0e10cSrcweir
541cdf0e10cSrcweir //------------------------------------------------------------------------
542cdf0e10cSrcweir
AStringToUStringNCopy(sal_Unicode * pDest,const sal_Char * pSrc,const sal_uInt32 nSrcLen)543cdf0e10cSrcweir sal_Bool AStringToUStringNCopy( sal_Unicode *pDest,
544cdf0e10cSrcweir const sal_Char *pSrc,
545cdf0e10cSrcweir const sal_uInt32 nSrcLen
546cdf0e10cSrcweir )
547cdf0e10cSrcweir {
548cdf0e10cSrcweir sal_Bool bCopied = sal_False;
549cdf0e10cSrcweir sal_uInt32 nCount = nSrcLen;
550cdf0e10cSrcweir sal_uInt32 nLen = nSrcLen;
551cdf0e10cSrcweir
552cdf0e10cSrcweir if ( ( pDest != NULL )
553cdf0e10cSrcweir && ( pSrc != NULL )
554cdf0e10cSrcweir && ( AStringNIsValid( pSrc, nLen ) )
555cdf0e10cSrcweir )
556cdf0e10cSrcweir {
557cdf0e10cSrcweir while ( nCount >= 0 )
558cdf0e10cSrcweir {
559cdf0e10cSrcweir *pDest = (unsigned char)*pSrc;
560cdf0e10cSrcweir
561cdf0e10cSrcweir pDest++;
562cdf0e10cSrcweir pSrc++;
563cdf0e10cSrcweir
564cdf0e10cSrcweir // Since we are dealing with unsigned integers
565cdf0e10cSrcweir // we want to make sure that the last number is
566cdf0e10cSrcweir // indeed zero.
567cdf0e10cSrcweir
568cdf0e10cSrcweir if ( nCount > 0 )
569cdf0e10cSrcweir {
570cdf0e10cSrcweir nCount--;
571cdf0e10cSrcweir } // if
572cdf0e10cSrcweir else
573cdf0e10cSrcweir {
574cdf0e10cSrcweir break;
575cdf0e10cSrcweir } // else
576cdf0e10cSrcweir } // while
577cdf0e10cSrcweir
578cdf0e10cSrcweir if ( nCount == 0 )
579cdf0e10cSrcweir {
580cdf0e10cSrcweir bCopied = sal_True;
581cdf0e10cSrcweir } // if
582cdf0e10cSrcweir } // if
583cdf0e10cSrcweir
584cdf0e10cSrcweir return bCopied;
585cdf0e10cSrcweir } // AStringToUStringNCopy
586cdf0e10cSrcweir
587cdf0e10cSrcweir //------------------------------------------------------------------------
588cdf0e10cSrcweir //------------------------------------------------------------------------
589cdf0e10cSrcweir
590