00001
00002
00003 #ifndef GAUDIALG_HBOOKNAME_H
00004 #define GAUDIALG_HBOOKNAME_H 1
00005
00006 #include <string>
00007 #include <algorithm>
00008
00018 namespace
00019 {
00036 inline std::string dirHbookName
00037 ( const std::string& addr ,
00038 const int maxLen = 16 )
00039 {
00040
00041 if( addr.empty() ) { return std::string(); }
00042
00043 std::string old( addr );
00044
00045 if( 0 < maxLen && maxLen < (int) old.size() )
00046 {
00047 std::string::iterator p1,p2;
00048 p1 = old.begin();
00049 const char sep('/');
00050 while( old.end() != p1 )
00051 {
00052 p1 =
00053 std::find_if( p1 ,
00054 old.end() ,
00055 std::bind2nd(std::not_equal_to<char>(),sep));
00056 p2 = std::find( p1 , old.end() , sep ) ;
00057 if( ( p2 - p1 ) <= (int) maxLen ) { p1 = p2 ; continue ; }
00058 old.insert( p1 + maxLen , sep ) ;
00059 p1 = old.begin() ;
00060 }
00061 }
00063 return old;
00064 }
00065
00085 inline std::string histoHbookName
00086 ( const std::string& addr ,
00087 const int maxLen = 8 )
00088 {
00089
00090 if( addr.empty() ) { return std::string(); }
00091
00092 std::string old( addr );
00093 {
00094 std::string::size_type pos
00095 = old.find_last_of( '/' );
00096 if ( std::string::npos == pos ) { old += "/1" ; }
00097 else if ( old.size() - 1 == pos ) { old += '1' ; }
00098 else
00099 {
00100 const int id =
00101 atoi( std::string( old , pos + 1 , std::string::npos ).c_str() );
00102 if( 0 == id ) { old+="/1"; }
00103 }
00104 }
00105
00106 if( 0 < maxLen && maxLen < (int) old.size() )
00107 {
00108 std::string::iterator p1,p2;
00109 p1 = old.begin();
00110 const char sep('/');
00111 while( old.end() != p1 )
00112 {
00113 p1 =
00114 std::find_if( p1 ,
00115 old.end() ,
00116 std::bind2nd(std::not_equal_to<char>(),sep));
00117 p2 = std::find( p1 , old.end() , sep ) ;
00118 if( ( p2 - p1 ) <= (int) maxLen ) { p1 = p2 ; continue ; }
00119 old.insert( p1 + maxLen , sep ) ;
00120 p1 = old.begin() ;
00121 }
00122 }
00123
00124 return old;
00125 }
00126
00127 }
00128
00129
00130
00131
00132 #endif // GAUDIALG_HBOOKNAME_H
00133