libassa  3.5.1
CommonUtils.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //------------------------------------------------------------------------------
3 // $Id: CommonUtils.h,v 1.8 2006/07/20 02:30:53 vlg Exp $
4 //------------------------------------------------------------------------------
5 // CommonUtils.h
6 //------------------------------------------------------------------------------
7 // Copyright (C) 1997-2003,2005 Vladislav Grinchenko
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Library General Public
11 // License as published by the Free Software Foundation; either
12 // version 2 of the License, or (at your option) any later version.
13 //------------------------------------------------------------------------------
14 #ifndef COMMON_UTILS_H
15 #define COMMON_UTILS_H
16 
17 #include <sstream>
18 #include <unistd.h>
19 
20 #include <string>
21 #include <vector>
22 using std::vector;
23 using std::string;
24 
35 #if defined (WIN32)
36 
37 #include <Windows.h>
38 
39 #define ASSA_DIR_SEPARATOR '\\'
40 #define ASSA_DIR_SEPARATOR_S "\\"
41 #define ASSA_IS_DIR_SEPARATOR(c) ((c) == ASSA_DIR_SEPARATOR || (c) == '/')
42 #define ASSA_SEARCHPATH_SEPARATOR ';'
43 #define ASSA_SEARCHPATH_SEPARATOR_S ";"
44 
45 #else /* POSIX */
46 
47 #define ASSA_DIR_SEPARATOR '/'
48 #define ASSA_DIR_SEPARATOR_S "/"
49 #define ASSA_IS_DIR_SEPARATOR(c) ((c) == ASSA_DIR_SEPARATOR)
50 #define ASSA_SEARCHPATH_SEPARATOR ':'
51 #define ASSA_SEARCHPATH_SEPARATOR_S ":"
52 
53 #endif
54 
55 namespace ASSA {
56 namespace Utils {
57 
66  void split (const char* text_, std::vector<std::string>& vec_);
67 
78  int split_pair (const string& text_, char sep_, string& lhs_, string& rhs_);
79 
88  int ltrim (std::string& text_, const std::string& delim_);
89 
99  int rtrim (std::string& text_, const std::string& delim_);
100 
107  void trim_sides (std::string& text_);
108 
117  void find_and_replace_char (std::string& text_, char src_, char dest_);
118 
127  std::string strenv (const char* in_);
128 
135  std::string get_cwd_name ();
136 
142  inline void sleep_for_seconds (long secs_to_sleep_)
143  {
144 #if defined (WIN32)
145  SleepEx (secs_to_sleep_ * 1000, FALSE);
146 #else
147  ::sleep (secs_to_sleep_);
148 #endif
149  }
150 
151 
152 } // end namespace Utils
153 } // end namespace ASSA
154 
155 #endif /* COMMON_UTILS_H */
int split_pair(const string &text_, char sep_, string &lhs_, string &rhs_)
Split input string into two parts separated by the separator character.
Definition: CommonUtils.cpp:47
void sleep_for_seconds(long secs_to_sleep_)
Portable sleep.
Definition: CommonUtils.h:142
void find_and_replace_char(std::string &text_, char src_, char dest_)
Find and relpace all instances of src_ character with dest_ character in a string text_.
void trim_sides(std::string &text_)
Trim white spaces and tabs from the beginning and the end of the text string.
Definition: CommonUtils.cpp:93
void split(const char *text_, std::vector< std::string > &vec_)
Split character string into tokens separated by the whitespace character (blank, tab,...
Definition: CommonUtils.cpp:34
std::string strenv(const char *in_)
Expand the passed string in_ by substituting environment variable names for their values.
std::string get_cwd_name()
Get current working directory.
int ltrim(std::string &text_, const std::string &delim_)
Trim string from the beginning to the left of the delimiter.
Definition: CommonUtils.cpp:67
int rtrim(std::string &text_, const std::string &delim_)
Trim string from the delimiter to the end of the string.
Definition: CommonUtils.cpp:80
Definition: Acceptor.h:40