]> Creatis software - bbtk.git/blob - kernel/src/bbtkUtilities.h
Recreated the complete cvs tree because the project architecture deeply changed
[bbtk.git] / kernel / src / bbtkUtilities.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkUtilities.h,v $
5   Language:  C++
6   Date:      $Date: 2008/01/22 15:02:00 $
7   Version:   $Revision: 1.1.1.1 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See doc/license.txt or
11   http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18
19
20 /**
21  *  \file 
22  *  \brief struct bbtk::Utilities : various usefull methods 
23  */
24
25 /**
26  * \class bbtk::Utilities
27  * \brief various usefull methods 
28  */
29  
30 #ifndef __bbtkUtilities_h_INCLUDED__
31 #define __bbtkUtilities_h_INCLUDED__
32
33 #include "bbtkSystem.h"
34 #include <string>
35
36 namespace bbtk
37 {
38   /// Holds various usefull methods 
39   struct BBTK_EXPORT Utilities
40   {    
41     static inline std::string get_file_name(const std::string& s) 
42     { 
43       std::string::size_type slash_position = s.find_last_of("/\\");
44       if (slash_position != std::string::npos) 
45       {
46         return  s.substr(slash_position+1,std::string::npos);   
47       }
48       else 
49       {
50         return s;
51       }      
52     }
53
54
55   //========================================================================
56     // Usefull functions for html generation
57    
58     //========================================================================
59     static inline void replace( std::string& str,
60                                 const std::string& from, 
61                                 const std::string& to )
62     {
63       using std::string;
64       string::size_type pos = str.find( from );
65       while ( pos != string::npos )
66       {
67         str.replace( pos, from.size(), to );
68         pos = str.find( from, pos+from.size()-1 );
69       } 
70     }
71     //========================================================================
72
73     //========================================================================
74     static inline void html_format(std::string& str)
75     {
76       replace( str, "&", "&amp;" );
77       replace( str, "<", "&lt;" );
78       replace( str, ">", "&gt;" );
79     }
80     //========================================================================
81
82   };
83
84 } // namespace bbtk
85  
86 #endif //#ifndef __bbtkUtilities_h_INCLUDED__
87 //EOF