update credits
[LibreOffice.git] / sal / qa / rtl_strings / rtl_String_Utils.cxx
blobaf324fd333243a78614ec4e11d03b3d0121b191f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <math.h>
21 #include <stdlib.h>
22 #include <sal/types.h>
23 #include <rtl/ustring.h>
24 #include <rtl/string.hxx>
25 #include <rtl_String_Utils_Const.h>
27 using ::rtl::OString;
28 sal_uInt32 AStringLen( const sal_Char *pAStr )
30 sal_uInt32 nStrLen = 0;
32 if ( pAStr != NULL )
34 const sal_Char *pTempStr = pAStr;
36 while( *pTempStr )
38 pTempStr++;
39 } // while
41 nStrLen = (sal_uInt32)( pTempStr - pAStr );
42 } // if
44 return nStrLen;
45 } // AStringLen
46 sal_Char* cpystr( sal_Char* dst, const sal_Char* src )
48 const sal_Char* psrc = src;
49 sal_Char* pdst = dst;
51 while( *pdst++ = *psrc++ );
52 return ( dst );
55 sal_Char* cpynstr( sal_Char* dst, const sal_Char* src, sal_uInt32 cnt )
58 const sal_Char* psrc = src;
59 sal_Char* pdst = dst;
60 sal_uInt32 len = cnt;
61 sal_uInt32 i;
63 if ( len >= AStringLen(src) )
65 return( cpystr( dst, src ) );
68 // copy string by char
69 for( i = 0; i < len; i++ )
70 *pdst++ = *psrc++;
71 *pdst = '\0';
73 return ( dst );
76 //------------------------------------------------------------------------
77 sal_Bool cmpstr( const sal_Char* str1, const sal_Char* str2, sal_uInt32 len )
79 const sal_Char* pBuf1 = str1;
80 const sal_Char* pBuf2 = str2;
81 sal_uInt32 i = 0;
83 while ( (*pBuf1 == *pBuf2) && i < len )
85 (pBuf1)++;
86 (pBuf2)++;
87 i++;
89 return( i == len );
91 //------------------------------------------------------------------------
92 sal_Bool cmpustr( const sal_Unicode* str1, const sal_Unicode* str2, sal_uInt32 len )
94 const sal_Unicode* pBuf1 = str1;
95 const sal_Unicode* pBuf2 = str2;
96 sal_uInt32 i = 0;
98 while ( (*pBuf1 == *pBuf2) && i < len )
100 (pBuf1)++;
101 (pBuf2)++;
102 i++;
104 return( i == len );
107 //-----------------------------------------------------------------------
108 sal_Bool cmpustr( const sal_Unicode* str1, const sal_Unicode* str2 )
110 const sal_Unicode* pBuf1 = str1;
111 const sal_Unicode* pBuf2 = str2;
112 sal_Bool res = sal_True;
114 while ( (*pBuf1 == *pBuf2) && *pBuf1 !='\0' && *pBuf2 != '\0')
116 (pBuf1)++;
117 (pBuf2)++;
119 if (*pBuf1 == '\0' && *pBuf2 == '\0')
120 res = sal_True;
121 else
122 res = sal_False;
123 return (res);
126 sal_Char* createName( sal_Char* dst, const sal_Char* meth, sal_uInt32 cnt )
128 sal_Char* pdst = dst;
129 sal_Char nstr[16];
130 sal_Char* pstr = nstr;
131 rtl_str_valueOfInt32( pstr, cnt, 10 );
133 cpystr( pdst, meth );
134 cpystr( pdst+ AStringLen(meth), "_" );
136 if ( cnt < 100 )
138 cpystr(pdst + AStringLen(pdst), "0" );
140 if ( cnt < 10 )
142 cpystr(pdst + AStringLen(pdst), "0" );
145 cpystr( pdst + AStringLen(pdst), nstr );
146 return( pdst );
149 //------------------------------------------------------------------------
151 static inline sal_Int32 ACharToUCharCompare( const sal_Unicode *pUStr,
152 const sal_Char *pAStr
155 sal_Int32 nCmp = 0;
156 sal_Int32 nUChar = (sal_Int32)*pUStr;
157 sal_Int32 nChar = (sal_Int32)((unsigned char)*pAStr);
159 nCmp = nUChar - nChar;
161 return nCmp;
162 } // ACharToUCharCompare
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */