Move setting of LD_LIBRARY_PATH closer to invocation of cppunittester
[LibreOffice.git] / xmloff / source / core / SvXMLAttrCollection.cxx
blob466008b9f80ee488b841e84f7642873308af8720
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/.
8 */
10 #include "SvXMLAttrCollection.hxx"
11 #include <limits.h>
12 #include <osl/diagnose.h>
14 bool SvXMLAttrCollection::operator ==( const SvXMLAttrCollection& rCmp ) const
16 return (rCmp.aNamespaceMap == aNamespaceMap) &&
17 (rCmp.aAttrs == aAttrs);
20 bool SvXMLAttrCollection::AddAttr( const OUString& rLName,
21 const OUString& rValue )
23 assert(!rLName.isEmpty());
24 aAttrs.emplace_back(rLName, rValue );
25 return true;
28 bool SvXMLAttrCollection::AddAttr( const OUString& rPrefix,
29 const OUString& rNamespace,
30 const OUString& rLName,
31 const OUString& rValue )
33 assert(!rPrefix.isEmpty());
34 assert(!rNamespace.isEmpty());
35 assert(!rLName.isEmpty());
36 sal_uInt16 nPos = aNamespaceMap.Add( rPrefix, rNamespace );
37 aAttrs.emplace_back(nPos, rLName, rValue );
38 return true;
41 bool SvXMLAttrCollection::AddAttr( const OUString& rPrefix,
42 const OUString& rLName,
43 const OUString& rValue )
45 assert(!rPrefix.isEmpty());
46 assert(!rLName.isEmpty());
47 sal_uInt16 nPos = aNamespaceMap.GetIndexByPrefix( rPrefix );
48 if( USHRT_MAX == nPos )
49 return false;
50 aAttrs.emplace_back(nPos, rLName, rValue );
51 return true;
54 bool SvXMLAttrCollection::SetAt( size_t i,
55 const OUString& rLName,
56 const OUString& rValue )
58 assert(!rLName.isEmpty());
59 if( i >= GetAttrCount() )
60 return false;
61 aAttrs[i] = SvXMLAttr(rLName, rValue);
62 return true;
65 bool SvXMLAttrCollection::SetAt( size_t i,
66 const OUString& rPrefix,
67 const OUString& rNamespace,
68 const OUString& rLName,
69 const OUString& rValue )
71 assert(!rPrefix.isEmpty());
72 assert(!rNamespace.isEmpty());
73 assert(!rLName.isEmpty());
74 if( i >= GetAttrCount() )
75 return false;
77 sal_uInt16 nPos = aNamespaceMap.Add( rPrefix, rNamespace );
78 if( USHRT_MAX == nPos )
79 return false;
81 aAttrs[i] = SvXMLAttr(nPos, rLName, rValue);
82 return true;
85 bool SvXMLAttrCollection::SetAt( size_t i,
86 const OUString& rPrefix,
87 const OUString& rLName,
88 const OUString& rValue )
90 assert(!rPrefix.isEmpty());
91 assert(!rLName.isEmpty());
92 if( i >= GetAttrCount() )
93 return false;
95 sal_uInt16 nPos = aNamespaceMap.GetIndexByPrefix( rPrefix );
96 if( USHRT_MAX == nPos )
97 return false;
99 aAttrs[i] = SvXMLAttr(nPos, rLName, rValue);
100 return true;
103 void SvXMLAttrCollection::Remove( size_t i )
105 if( i < GetAttrCount() )
107 aAttrs.erase( aAttrs.begin() + i );
109 else
111 OSL_FAIL( "illegal index" );
115 size_t SvXMLAttrCollection::GetAttrCount() const
117 return aAttrs.size();
120 const OUString& SvXMLAttrCollection::GetAttrLName(size_t i) const
122 OSL_ENSURE( i < aAttrs.size(), "SvXMLAttrContainerData::GetLName: illegal index" );
123 return aAttrs[i].getLName();
126 const OUString& SvXMLAttrCollection::GetAttrValue(size_t i) const
128 OSL_ENSURE( i < aAttrs.size(), "SvXMLAttrContainerData::GetValue: illegal index" );
129 return aAttrs[i].getValue();
132 OUString SvXMLAttrCollection::GetAttrNamespace( size_t i ) const
134 OUString sRet;
135 sal_uInt16 nPos = GetPrefixPos( i );
136 //Does this point to a valid namespace entry?
137 if( USHRT_MAX != nPos )
138 sRet = aNamespaceMap.GetNameByIndex( nPos );
139 return sRet;
142 OUString SvXMLAttrCollection::GetAttrPrefix( size_t i ) const
144 OUString sRet;
145 sal_uInt16 nPos = GetPrefixPos( i );
146 //Does this point to a valid namespace entry?
147 if( USHRT_MAX != nPos )
148 sRet = aNamespaceMap.GetPrefixByIndex( nPos );
149 return sRet;
152 const OUString& SvXMLAttrCollection::GetNamespace( sal_uInt16 i ) const
154 return aNamespaceMap.GetNameByIndex( i );
157 const OUString& SvXMLAttrCollection::GetPrefix( sal_uInt16 i ) const
159 return aNamespaceMap.GetPrefixByIndex( i );
162 sal_uInt16 SvXMLAttrCollection::GetFirstNamespaceIndex() const
164 return aNamespaceMap.GetFirstIndex();
167 sal_uInt16 SvXMLAttrCollection::GetNextNamespaceIndex( sal_uInt16 nIdx ) const
169 return aNamespaceMap.GetNextIndex( nIdx );
172 sal_uInt16 SvXMLAttrCollection::GetPrefixPos( size_t i ) const
174 // SAL_WARN_IF( i < 0 || i >= aAttrs.size()), "xmloff",
175 // "SvXMLAttrCollection::GetPrefixPos: illegal index" );
176 return aAttrs[i].getPrefixPos();
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */