xrootd
PathProcessor.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
3 // Author: Lukasz Janyst <ljanyst@cern.ch>
4 //------------------------------------------------------------------------------
5 // XRootD is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // XRootD is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
17 //------------------------------------------------------------------------------
18 
19 #ifndef EOS_NS_PATH_PROCESSOR_HH
20 #define EOS_NS_PATH_PROCESSOR_HH
21 
22 #include <cstring>
23 #include <vector>
24 #include <string>
25 
26 namespace eos
27 {
28  //----------------------------------------------------------------------------
30  //----------------------------------------------------------------------------
32  {
33  public:
34  //------------------------------------------------------------------------
37  //------------------------------------------------------------------------
38  static void splitPath( std::vector<std::string> &elements,
39  const std::string &path )
40  {
41  elements.clear();
42  std::vector<char*> elems;
43  char buffer[path.length()+1];
44  strcpy( buffer, path.c_str() );
45  splitPath( elems, buffer );
46  for( size_t i = 0; i < elems.size(); ++i )
47  elements.push_back( elems[i] );
48  }
49 
50  //------------------------------------------------------------------------
53  //------------------------------------------------------------------------
54  static void splitPath( std::vector<char*> &elements, char *buffer )
55  {
56  elements.clear();
57  elements.reserve( 10 );
58 
59  char *cursor = buffer;
60  char *beg = buffer;
61 
62  //----------------------------------------------------------------------
63  // Go by the characters one by one
64  //----------------------------------------------------------------------
65  while( *cursor )
66  {
67  if( *cursor == '/' )
68  {
69  *cursor = 0;
70  if( beg != cursor )
71  elements.push_back( beg );
72  beg = cursor+1;
73  }
74  ++cursor;
75  }
76 
77  if( beg != cursor )
78  elements.push_back( beg );
79  }
80  };
81 }
82 
83 #endif // EOS_NS_PATH_PROCESSOR_HH