Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / sal / qa / OStringBuffer / rtl_String_Utils.cxx
blob53a1f18a575f78632e43996edb7470577d886ff1
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
49 sal_Char* cpystr( sal_Char* dst, const sal_Char* src )
51 const sal_Char* psrc = src;
52 sal_Char* pdst = dst;
54 while( (*pdst++ = *psrc++) ) {}
56 return dst;
59 sal_Char* cpynstr( sal_Char* dst, const sal_Char* src, sal_uInt32 cnt )
62 const sal_Char* psrc = src;
63 sal_Char* pdst = dst;
64 sal_uInt32 len = cnt;
65 sal_uInt32 i;
67 if ( len >= AStringLen(src) )
69 return( cpystr( dst, src ) );
72 // copy string by char
73 for( i = 0; i < len; i++ )
74 *pdst++ = *psrc++;
75 *pdst = '\0';
77 return ( dst );
80 //------------------------------------------------------------------------
81 sal_Bool cmpstr( const sal_Char* str1, const sal_Char* str2, sal_uInt32 len )
83 const sal_Char* pBuf1 = str1;
84 const sal_Char* pBuf2 = str2;
85 sal_uInt32 i = 0;
87 while ( (*pBuf1 == *pBuf2) && i < len )
89 (pBuf1)++;
90 (pBuf2)++;
91 i++;
93 return( i == len );
95 //-----------------------------------------------------------------------
96 sal_Bool cmpstr( const sal_Char* str1, const sal_Char* str2 )
98 const sal_Char* pBuf1 = str1;
99 const sal_Char* pBuf2 = str2;
100 sal_Bool res = sal_True;
102 while ( (*pBuf1 == *pBuf2) && *pBuf1 !='\0' && *pBuf2 != '\0')
104 (pBuf1)++;
105 (pBuf2)++;
107 if (*pBuf1 == '\0' && *pBuf2 == '\0')
108 res = sal_True;
109 else
110 res = sal_False;
111 return (res);
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 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */