libassa  3.5.0
/build/buildd/libassa-3.5.0/assa/CommonUtils.h
Go to the documentation of this file.
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 #include <unistd.h>
00019 
00020 #include <string> 
00021 #include <vector>
00022 using std::vector;
00023 using std::string;
00024 
00035 #if defined (WIN32)
00036 
00037 #include <Windows.h>
00038 
00039 #define ASSA_DIR_SEPARATOR          '\\'
00040 #define ASSA_DIR_SEPARATOR_S        "\\"
00041 #define ASSA_IS_DIR_SEPARATOR(c)    ((c) == ASSA_DIR_SEPARATOR || (c) == '/')
00042 #define ASSA_SEARCHPATH_SEPARATOR   ';'
00043 #define ASSA_SEARCHPATH_SEPARATOR_S ";"
00044 
00045 #else  /* POSIX */
00046 
00047 #define ASSA_DIR_SEPARATOR          '/'
00048 #define ASSA_DIR_SEPARATOR_S        "/"
00049 #define ASSA_IS_DIR_SEPARATOR(c)    ((c) == ASSA_DIR_SEPARATOR)
00050 #define ASSA_SEARCHPATH_SEPARATOR   ':'
00051 #define ASSA_SEARCHPATH_SEPARATOR_S ":"
00052 
00053 #endif 
00054 
00055 namespace ASSA {
00056 namespace Utils {
00057 
00066     void split (const char* text_, std::vector<std::string>& vec_);
00067 
00078     int split_pair (const string& text_, char sep_, string& lhs_, string& rhs_);
00079 
00088     int ltrim (std::string& text_, const std::string& delim_);
00089 
00099     int rtrim (std::string& text_, const std::string& delim_);
00100 
00107     void trim_sides (std::string& text_);
00108 
00117     void find_and_replace_char (std::string& text_, char src_, char dest_);
00118 
00127     std::string strenv (const char* in_);
00128 
00135     std::string get_cwd_name ();
00136 
00142     inline void sleep_for_seconds (long secs_to_sleep_) 
00143     {
00144 #if defined (WIN32)
00145         SleepEx (secs_to_sleep_ * 1000, FALSE);
00146 #else
00147         ::sleep (secs_to_sleep_);
00148 #endif
00149     }
00150 
00151 
00152 } // end namespace Utils
00153 } // end namespace ASSA
00154 
00155 #endif /* COMMON_UTILS_H */  
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines