merged tag ooo/OOO330_m14
[LibreOffice.git] / cosv / source / storage / dirchain.cxx
blobb183c0f990f7332b5e76e25cddaecfc9b11c36ad
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #include <precomp.h>
29 #include <cosv/dirchain.hxx>
31 // NOT FULLY DECLARED SERVICES
32 #include <cosv/bstream.hxx>
37 namespace csv
39 namespace ploc
43 DirectoryChain::DirectoryChain()
47 DirectoryChain::DirectoryChain( const char * i_sSubPath,
48 bool i_bPathIsAlwaysDir,
49 const char * i_sDelimiter )
51 Set( i_sSubPath, i_bPathIsAlwaysDir, i_sDelimiter );
54 DirectoryChain::~DirectoryChain()
58 void
59 DirectoryChain::Set( const char * i_sSubPath,
60 bool i_bPathIsAlwaysDir,
61 const char * i_sDelimiter )
63 csv_assert(i_sDelimiter != 0);
64 if (i_sSubPath == 0)
65 return;
67 const char * pRestPath = i_sSubPath;
68 if (*pRestPath == *i_sDelimiter)
69 ++pRestPath;
71 for ( const char * pDirEnd = strchr(pRestPath,*i_sDelimiter);
72 pDirEnd != 0;
73 pDirEnd = strchr(pRestPath,*i_sDelimiter) )
75 aPath.push_back( String(pRestPath, pDirEnd) );
76 pRestPath = pDirEnd + 1;
78 if (*pRestPath != 0 AND i_bPathIsAlwaysDir)
79 aPath.push_back( String(pRestPath) );
82 void
83 DirectoryChain::PushFront( const String & i_sName )
85 aPath.insert( aPath.begin(), i_sName );
88 void
89 DirectoryChain::PushFront( const DirectoryChain & i_sPath )
91 aPath.insert( aPath.begin(), i_sPath.Begin(), i_sPath.End() );
94 void
95 DirectoryChain::PushBack( const String & i_sName )
97 aPath.push_back(i_sName);
100 void
101 DirectoryChain::PushBack( const DirectoryChain & i_sPath )
103 aPath.insert( aPath.end(), i_sPath.Begin(), i_sPath.End() );
106 void
107 DirectoryChain::PopFront( uintt i_nCount )
109 if (i_nCount <= aPath.size())
110 aPath.erase( aPath.begin(), aPath.begin() + i_nCount );
111 else
112 aPath.erase( aPath.begin(), aPath.end() );
115 void
116 DirectoryChain::PopBack( uintt i_nCount )
118 if (i_nCount <= aPath.size())
119 aPath.erase( aPath.end() - i_nCount, aPath.end() );
120 else
121 aPath.erase( aPath.begin(), aPath.end() );
124 void
125 DirectoryChain::Get( ostream & o_rPath,
126 const char * i_sDelimiter ) const
128 for ( std::vector<String>::const_iterator it = aPath.begin();
129 it != aPath.end();
130 ++it )
132 o_rPath << (*it).c_str() << i_sDelimiter;
136 void
137 DirectoryChain::Get( bostream & o_rPath,
138 const char * i_sDelimiter ) const
140 uintt deliLen = strlen(i_sDelimiter);
142 for ( std::vector<String>::const_iterator it = aPath.begin();
143 it != aPath.end();
144 ++it )
146 o_rPath.write( (*it).c_str() );
147 o_rPath.write( i_sDelimiter, deliLen);
154 } // namespace ploc
155 } // namespace csv