merge the formfield patch from ooo-build
[ooovba.git] / cosv / source / storage / dirchain.cxx
blob7f083bfc459d8978b55e175c5b5920b936384cc8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dirchain.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <precomp.h>
32 #include <cosv/dirchain.hxx>
34 // NOT FULLY DECLARED SERVICES
35 #include <cosv/bstream.hxx>
40 namespace csv
42 namespace ploc
46 DirectoryChain::DirectoryChain()
50 DirectoryChain::DirectoryChain( const char * i_sSubPath,
51 bool i_bPathIsAlwaysDir,
52 const char * i_sDelimiter )
54 Set( i_sSubPath, i_bPathIsAlwaysDir, i_sDelimiter );
57 DirectoryChain::~DirectoryChain()
61 void
62 DirectoryChain::Set( const char * i_sSubPath,
63 bool i_bPathIsAlwaysDir,
64 const char * i_sDelimiter )
66 csv_assert(i_sDelimiter != 0);
67 if (i_sSubPath == 0)
68 return;
70 const char * pRestPath = i_sSubPath;
71 if (*pRestPath == *i_sDelimiter)
72 ++pRestPath;
74 for ( const char * pDirEnd = strchr(pRestPath,*i_sDelimiter);
75 pDirEnd != 0;
76 pDirEnd = strchr(pRestPath,*i_sDelimiter) )
78 aPath.push_back( String(pRestPath, pDirEnd) );
79 pRestPath = pDirEnd + 1;
81 if (*pRestPath != 0 AND i_bPathIsAlwaysDir)
82 aPath.push_back( String(pRestPath) );
85 void
86 DirectoryChain::PushFront( const String & i_sName )
88 aPath.insert( aPath.begin(), i_sName );
91 void
92 DirectoryChain::PushFront( const DirectoryChain & i_sPath )
94 aPath.insert( aPath.begin(), i_sPath.Begin(), i_sPath.End() );
97 void
98 DirectoryChain::PushBack( const String & i_sName )
100 aPath.push_back(i_sName);
103 void
104 DirectoryChain::PushBack( const DirectoryChain & i_sPath )
106 aPath.insert( aPath.end(), i_sPath.Begin(), i_sPath.End() );
109 void
110 DirectoryChain::PopFront( uintt i_nCount )
112 if (i_nCount <= aPath.size())
113 aPath.erase( aPath.begin(), aPath.begin() + i_nCount );
114 else
115 aPath.erase( aPath.begin(), aPath.end() );
118 void
119 DirectoryChain::PopBack( uintt i_nCount )
121 if (i_nCount <= aPath.size())
122 aPath.erase( aPath.end() - i_nCount, aPath.end() );
123 else
124 aPath.erase( aPath.begin(), aPath.end() );
127 void
128 DirectoryChain::Get( ostream & o_rPath,
129 const char * i_sDelimiter ) const
131 for ( std::vector<String>::const_iterator it = aPath.begin();
132 it != aPath.end();
133 ++it )
135 o_rPath << (*it).c_str() << i_sDelimiter;
139 void
140 DirectoryChain::Get( bostream & o_rPath,
141 const char * i_sDelimiter ) const
143 uintt deliLen = strlen(i_sDelimiter);
145 for ( std::vector<String>::const_iterator it = aPath.begin();
146 it != aPath.end();
147 ++it )
149 o_rPath.write( (*it).c_str() );
150 o_rPath.write( i_sDelimiter, deliLen);
157 } // namespace ploc
158 } // namespace csv