1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #define CSV_USE_CSV_ASSERTIONS
21 #include <cosv/csv_env.hxx>
23 #include <cosv/comfunc.hxx>
24 #include <cosv/string.hxx>
25 #include <cosv/streamstr.hxx>
26 #include <cosv/std_outp.hxx>
27 #include <cosv/tpl/dyn.hxx>
29 // NOT FULLY DECLARED SERVICES
40 str_from_StringOffset( const String
& i_rStr
,
43 return i_nOffset
< i_rStr
.size()
44 ? i_rStr
.c_str() + i_nOffset
49 str_from_ptr( const char * i_str
)
52 return valid_str(i_str
);
56 //********************* String::S_Data **********************//
65 S_Data::S_Data( const char * i_sData
,
66 size_type i_nValidLength
)
67 : aStr( str_from_ptr(i_sData
),
68 (i_nValidLength
!= str::maxsize
78 csv_assert( nCount
== 0 );
81 const String::S_Data
*
83 S_Data::Acquire() const
86 ++ (const_cast< uintt
& >(nCount
));
95 S_Data::Release() const
98 -- (const_cast< uintt
& >(nCount
));
103 delete (const_cast< S_Data
* >(this));
107 //************************** String **************************//
111 : pd( String::Null_().pd
->Acquire() )
115 String::String( const char * i_str
)
116 : pd( new S_Data(i_str
) )
120 String::String( const char * i_str
,
121 size_type i_nLength
)
122 : pd( new S_Data(i_str
, i_nLength
) )
126 String::String( const_iterator i_itBegin
,
127 const_iterator i_itEnd
)
128 : pd( new S_Data(i_itBegin
, size_type(i_itEnd
- i_itBegin
)) )
132 String::String( const self
& i_rStr
)
133 : pd( i_rStr
.pd
->Acquire() )
144 String::operator=( const self
& i_rStr
)
146 i_rStr
.pd
->Acquire();
154 String::operator=( const char * i_str
)
157 pTemp
= new S_Data(i_str
);
165 String::assign( const char * i_str
,
166 size_type i_nLength
)
169 pTemp
= new S_Data( i_str
, i_nLength
);
175 String::compare( const self
& i_rStr
) const
177 return strcmp( c_str(), i_rStr
.c_str() );
181 String::compare( const CharOrder_Table
& i_rOrder
,
182 const self
& i_rStr
) const
184 return csv::compare( i_rOrder
, c_str(), i_rStr
.c_str() );
190 // Must not use the default constructor! Because that one calls
191 // this function, which would create a circular dependency.
192 static const String
aNull_("");
199 static const char cNull_
= '\0';
205 compare( const String
& i_s1
,
206 csv::str::position i_nStartPosition1
,
208 csv::str::size i_nLength
)
210 const char * pS1
= str_from_StringOffset( i_s1
, i_nStartPosition1
);
212 if ( i_nLength
!= csv::str::maxsize
)
222 compare( const CharOrder_Table
& i_rOrder
,
226 const char * it1
= i_s1
;
227 const char * it2
= i_s2
;
228 for ( ; i_rOrder(*it1
) == i_rOrder(*it2
) AND
*it1
!= '\0'; ++it1
, ++it2
)
230 return int( i_rOrder(*it1
) - i_rOrder(*it2
) );
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */