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 #ifndef COSV_STRINGDATA_HXX
21 #define COSV_STRINGDATA_HXX
24 #include <cosv/str_types.hxx>
32 The expression CHAR(0) has to be valid.
38 typedef StringData self
;
40 typedef str::size size_type
;
41 typedef str::position position_type
;
45 /** @precond i_pData != 0
46 @precond i_nValidLength <= strlen(i_pData)
50 size_type i_nValidLength
);
57 const CHAR
* Data() const;
59 /** @returns the allocated number of CHAR.
60 This may be different from the number of bytes.
61 There is actually allocated one more CHAR,
62 which is guaranteed to be CHAR(0) in all circumstances.
64 size_type
Size() const;
67 /* Because this is used only within a refcounted structure,
68 these functions are forbidden - at least yet.
70 StringData(const self
&);
71 self
& operator=(const self
&);
75 size_type nSize
; /// The allocated size - 1 (for the finishing 0).
83 StringData
<CHAR
>::StringData()
84 : dpData( new CHAR
[1] ),
91 StringData
<CHAR
>::StringData( const CHAR
* i_pData
,
92 size_type i_nValidLength
)
93 : dpData( new CHAR
[i_nValidLength
+ 1] ),
96 memcpy( dpData
, i_pData
, i_nValidLength
* sizeof(CHAR
) );
97 dpData
[nSize
] = CHAR(0);
100 template <class CHAR
>
101 StringData
<CHAR
>::~StringData()
106 template <class CHAR
>
108 StringData
<CHAR
>::Data() const
113 template <class CHAR
>
114 typename StringData
<CHAR
>::size_type
115 StringData
<CHAR
>::Size() const
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */