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