libassa 3.5.0
|
00001 // -*- c++ -*- 00002 //------------------------------------------------------------------------------ 00003 // $Id: CommonUtils.h,v 1.8 2006/07/20 02:30:53 vlg Exp $ 00004 //------------------------------------------------------------------------------ 00005 // CommonUtils.h 00006 //------------------------------------------------------------------------------ 00007 // Copyright (C) 1997-2003,2005 Vladislav Grinchenko 00008 // 00009 // This library is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU Library General Public 00011 // License as published by the Free Software Foundation; either 00012 // version 2 of the License, or (at your option) any later version. 00013 //------------------------------------------------------------------------------ 00014 #ifndef COMMON_UTILS_H 00015 #define COMMON_UTILS_H 00016 00017 #include <sstream> 00018 00019 #include <string> 00020 #include <vector> 00021 using std::vector; 00022 using std::string; 00023 00034 #if defined (WIN32) 00035 00036 #include <Windows.h> 00037 00038 #define ASSA_DIR_SEPARATOR '\\' 00039 #define ASSA_DIR_SEPARATOR_S "\\" 00040 #define ASSA_IS_DIR_SEPARATOR(c) ((c) == ASSA_DIR_SEPARATOR || (c) == '/') 00041 #define ASSA_SEARCHPATH_SEPARATOR ';' 00042 #define ASSA_SEARCHPATH_SEPARATOR_S ";" 00043 00044 #else /* POSIX */ 00045 00046 #define ASSA_DIR_SEPARATOR '/' 00047 #define ASSA_DIR_SEPARATOR_S "/" 00048 #define ASSA_IS_DIR_SEPARATOR(c) ((c) == ASSA_DIR_SEPARATOR) 00049 #define ASSA_SEARCHPATH_SEPARATOR ':' 00050 #define ASSA_SEARCHPATH_SEPARATOR_S ":" 00051 00052 #endif 00053 00054 namespace ASSA { 00055 namespace Utils { 00056 00065 void split (const char* text_, std::vector<std::string>& vec_); 00066 00077 int split_pair (const string& text_, char sep_, string& lhs_, string& rhs_); 00078 00087 int ltrim (std::string& text_, const std::string& delim_); 00088 00098 int rtrim (std::string& text_, const std::string& delim_); 00099 00106 void trim_sides (std::string& text_); 00107 00116 void find_and_replace_char (std::string& text_, char src_, char dest_); 00117 00126 std::string strenv (const char* in_); 00127 00134 std::string get_cwd_name (); 00135 00141 inline void sleep_for_seconds (long secs_to_sleep_) 00142 { 00143 #if defined (WIN32) 00144 SleepEx (secs_to_sleep_ * 1000, FALSE); 00145 #else 00146 ::sleep (secs_to_sleep_); 00147 #endif 00148 } 00149 00150 00151 } // end namespace Utils 00152 } // end namespace ASSA 00153 00154 #endif /* COMMON_UTILS_H */