update credits
[LibreOffice.git] / sal / qa / OStringBuffer / rtl_String_Utils.cxx
blob56f362e118422ddf86f781df014f9f400700152a
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>
23 #include <sal/types.h>
25 #include <rtl/ustring.h>
26 #include <rtl/string.hxx>
27 #include <rtl_String_Utils_Const.h>
29 using ::rtl::OString;
30 sal_uInt32 AStringLen( const sal_Char *pAStr )
32 sal_uInt32 nStrLen = 0;
34 if ( pAStr != NULL )
36 const sal_Char *pTempStr = pAStr;
38 while( *pTempStr )
40 pTempStr++;
41 } // while
43 nStrLen = (sal_uInt32)( pTempStr - pAStr );
44 } // if
46 return nStrLen;
47 } // AStringLen
48 /* disable assignment within condition expression */
49 #if defined WNT && defined _MSC_VER
50 #pragma warning( disable : 4706 )
51 #endif
52 sal_Char* cpystr( sal_Char* dst, const sal_Char* src )
54 const sal_Char* psrc = src;
55 sal_Char* pdst = dst;
57 while( (*pdst++ = *psrc++) ) {}
59 return dst;
62 sal_Char* cpynstr( sal_Char* dst, const sal_Char* src, sal_uInt32 cnt )
65 const sal_Char* psrc = src;
66 sal_Char* pdst = dst;
67 sal_uInt32 len = cnt;
68 sal_uInt32 i;
70 if ( len >= AStringLen(src) )
72 return( cpystr( dst, src ) );
75 // copy string by char
76 for( i = 0; i < len; i++ )
77 *pdst++ = *psrc++;
78 *pdst = '\0';
80 return ( dst );
83 //------------------------------------------------------------------------
84 sal_Bool cmpstr( const sal_Char* str1, const sal_Char* str2, sal_uInt32 len )
86 const sal_Char* pBuf1 = str1;
87 const sal_Char* pBuf2 = str2;
88 sal_uInt32 i = 0;
90 while ( (*pBuf1 == *pBuf2) && i < len )
92 (pBuf1)++;
93 (pBuf2)++;
94 i++;
96 return( i == len );
98 //-----------------------------------------------------------------------
99 sal_Bool cmpstr( const sal_Char* str1, const sal_Char* str2 )
101 const sal_Char* pBuf1 = str1;
102 const sal_Char* pBuf2 = str2;
103 sal_Bool res = sal_True;
105 while ( (*pBuf1 == *pBuf2) && *pBuf1 !='\0' && *pBuf2 != '\0')
107 (pBuf1)++;
108 (pBuf2)++;
110 if (*pBuf1 == '\0' && *pBuf2 == '\0')
111 res = sal_True;
112 else
113 res = sal_False;
114 return (res);
116 //------------------------------------------------------------------------
117 sal_Bool cmpustr( const sal_Unicode* str1, const sal_Unicode* str2, sal_uInt32 len )
119 const sal_Unicode* pBuf1 = str1;
120 const sal_Unicode* pBuf2 = str2;
121 sal_uInt32 i = 0;
123 while ( (*pBuf1 == *pBuf2) && i < len )
125 (pBuf1)++;
126 (pBuf2)++;
127 i++;
129 return( i == len );
132 //-----------------------------------------------------------------------
133 sal_Bool cmpustr( const sal_Unicode* str1, const sal_Unicode* str2 )
135 const sal_Unicode* pBuf1 = str1;
136 const sal_Unicode* pBuf2 = str2;
137 sal_Bool res = sal_True;
139 while ( (*pBuf1 == *pBuf2) && *pBuf1 !='\0' && *pBuf2 != '\0')
141 (pBuf1)++;
142 (pBuf2)++;
144 if (*pBuf1 == '\0' && *pBuf2 == '\0')
145 res = sal_True;
146 else
147 res = sal_False;
148 return (res);
151 sal_Char* createName( sal_Char* dst, const sal_Char* meth, sal_uInt32 cnt )
153 sal_Char* pdst = dst;
154 sal_Char nstr[16];
155 sal_Char* pstr = nstr;
156 rtl_str_valueOfInt32( pstr, cnt, 10 );
158 cpystr( pdst, meth );
159 cpystr( pdst+ AStringLen(meth), "_" );
161 if ( cnt < 100 )
163 cpystr(pdst + AStringLen(pdst), "0" );
165 if ( cnt < 10 )
167 cpystr(pdst + AStringLen(pdst), "0" );
170 cpystr( pdst + AStringLen(pdst), nstr );
171 return( pdst );
174 //------------------------------------------------------------------------
176 static inline sal_Int32 ACharToUCharCompare( const sal_Unicode *pUStr,
177 const sal_Char *pAStr
180 sal_Int32 nCmp = 0;
181 sal_Int32 nUChar = (sal_Int32)*pUStr;
182 sal_Int32 nChar = (sal_Int32)((unsigned char)*pAStr);
184 nCmp = nUChar - nChar;
186 return nCmp;
187 } // ACharToUCharCompare
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */