Bump for 3.6-28
[LibreOffice.git] / sal / qa / rtl_strings / rtl_String_Utils.cxx
blob972124f03e24f58677a8e7c131260aad7e87c541
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 #*************************************************************************/
30 #include <math.h>
31 #include <stdlib.h>
33 #ifndef _SAL_TYPES_H_
34 #include <sal/types.h>
35 #endif
37 #ifndef _RTL_USTRING_H_
38 #include <rtl/ustring.h>
39 #endif
41 #ifndef _RTL_STRING_HXX_
42 #include <rtl/string.hxx>
43 #endif
45 #ifndef _RTL_STRING_UTILS_CONST_H_
46 #include <rtl_String_Utils_Const.h>
47 #endif
49 using ::rtl::OString;
50 sal_uInt32 AStringLen( const sal_Char *pAStr )
52 sal_uInt32 nStrLen = 0;
54 if ( pAStr != NULL )
56 const sal_Char *pTempStr = pAStr;
58 while( *pTempStr )
60 pTempStr++;
61 } // while
63 nStrLen = (sal_uInt32)( pTempStr - pAStr );
64 } // if
66 return nStrLen;
67 } // AStringLen
68 sal_Char* cpystr( sal_Char* dst, const sal_Char* src )
70 const sal_Char* psrc = src;
71 sal_Char* pdst = dst;
73 while( *pdst++ = *psrc++ );
74 return ( dst );
77 sal_Char* cpynstr( sal_Char* dst, const sal_Char* src, sal_uInt32 cnt )
80 const sal_Char* psrc = src;
81 sal_Char* pdst = dst;
82 sal_uInt32 len = cnt;
83 sal_uInt32 i;
85 if ( len >= AStringLen(src) )
87 return( cpystr( dst, src ) );
90 // copy string by char
91 for( i = 0; i < len; i++ )
92 *pdst++ = *psrc++;
93 *pdst = '\0';
95 return ( dst );
98 //------------------------------------------------------------------------
99 sal_Bool cmpstr( const sal_Char* str1, const sal_Char* str2, sal_uInt32 len )
101 const sal_Char* pBuf1 = str1;
102 const sal_Char* pBuf2 = str2;
103 sal_uInt32 i = 0;
105 while ( (*pBuf1 == *pBuf2) && i < len )
107 (pBuf1)++;
108 (pBuf2)++;
109 i++;
111 return( i == len );
113 //------------------------------------------------------------------------
114 sal_Bool cmpustr( const sal_Unicode* str1, const sal_Unicode* str2, sal_uInt32 len )
116 const sal_Unicode* pBuf1 = str1;
117 const sal_Unicode* pBuf2 = str2;
118 sal_uInt32 i = 0;
120 while ( (*pBuf1 == *pBuf2) && i < len )
122 (pBuf1)++;
123 (pBuf2)++;
124 i++;
126 return( i == len );
129 //-----------------------------------------------------------------------
130 sal_Bool cmpustr( const sal_Unicode* str1, const sal_Unicode* str2 )
132 const sal_Unicode* pBuf1 = str1;
133 const sal_Unicode* pBuf2 = str2;
134 sal_Bool res = sal_True;
136 while ( (*pBuf1 == *pBuf2) && *pBuf1 !='\0' && *pBuf2 != '\0')
138 (pBuf1)++;
139 (pBuf2)++;
141 if (*pBuf1 == '\0' && *pBuf2 == '\0')
142 res = sal_True;
143 else
144 res = sal_False;
145 return (res);
148 sal_Char* createName( sal_Char* dst, const sal_Char* meth, sal_uInt32 cnt )
150 sal_Char* pdst = dst;
151 sal_Char nstr[16];
152 sal_Char* pstr = nstr;
153 rtl_str_valueOfInt32( pstr, cnt, 10 );
155 cpystr( pdst, meth );
156 cpystr( pdst+ AStringLen(meth), "_" );
158 if ( cnt < 100 )
160 cpystr(pdst + AStringLen(pdst), "0" );
162 if ( cnt < 10 )
164 cpystr(pdst + AStringLen(pdst), "0" );
167 cpystr( pdst + AStringLen(pdst), nstr );
168 return( pdst );
171 //------------------------------------------------------------------------
173 static inline sal_Int32 ACharToUCharCompare( const sal_Unicode *pUStr,
174 const sal_Char *pAStr
177 sal_Int32 nCmp = 0;
178 sal_Int32 nUChar = (sal_Int32)*pUStr;
179 sal_Int32 nChar = (sal_Int32)((unsigned char)*pAStr);
181 nCmp = nUChar - nChar;
183 return nCmp;
184 } // ACharToUCharCompare
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */