Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

CommonUtils.h File Reference

#include <sstream>
#include <string>
#include <vector>

Go to the source code of this file.

Namespaces

namespace  ASSA
namespace  ASSA::Utils

Defines

#define ASSA_DIR_SEPARATOR   '/'
 Windows has its own wicked way of delimiting path.
#define ASSA_DIR_SEPARATOR_S   "/"
#define ASSA_IS_DIR_SEPARATOR(c)   ((c) == ASSA_DIR_SEPARATOR)
#define ASSA_SEARCHPATH_SEPARATOR   ':'
#define ASSA_SEARCHPATH_SEPARATOR_S   ":"

Functions

void split (const char *text_, std::vector< std::string > &vec_)
 Split character string into tokens separated by the whitespace character (blank, tab, newline, formfeed, and carriage return).
int split_pair (const string &text_, char sep_, string &lhs_, string &rhs_)
 Split input string into two parts separated by the separator character.
int ltrim (std::string &text_, const std::string &delim_)
 Trim string from the beginning to the left of the delimiter.
int rtrim (std::string &text_, const std::string &delim_)
 Trim string from the delimiter to the end of the string.
void trim_sides (std::string &text_)
 Trim white spaces and tabs from the beginning and the end of the text string.
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_.
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.
void sleep_for_seconds (long secs_to_sleep_)
 Portable sleep.


Define Documentation

#define ASSA_DIR_SEPARATOR   '/'
 

Windows has its own wicked way of delimiting path.

This is *borrowed* fro glib.

Definition at line 46 of file CommonUtils.h.

Referenced by ASSA::GenServer::init().

#define ASSA_DIR_SEPARATOR_S   "/"
 

Definition at line 47 of file CommonUtils.h.

#define ASSA_IS_DIR_SEPARATOR  )     ((c) == ASSA_DIR_SEPARATOR)
 

Definition at line 48 of file CommonUtils.h.

#define ASSA_SEARCHPATH_SEPARATOR   ':'
 

Definition at line 49 of file CommonUtils.h.

#define ASSA_SEARCHPATH_SEPARATOR_S   ":"
 

Definition at line 50 of file CommonUtils.h.


Function Documentation

void ASSA::Utils::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_.

Parameters:
text_ String to modify
src_ Find the character
dest_ Character to replace with

Referenced by ASSA::CmdLineOpts::parse_config_file().

std::string ASSA::Utils::get_cwd_name  ) 
 

Get current working directory.

Returns:
the current working directory on success, and an empty string on failure with errno set to indicate the error occured.

int ASSA::Utils::ltrim std::string &  text_,
const std::string &  delim_
 

Trim string from the beginning to the left of the delimiter.

Delimiter is removed as well.

Parameters:
text_ String to modify
delim_ Delimiter character
Returns:
0 on success; -1 on error

Referenced by ASSA::IniFile::trim_section_name().

int ASSA::Utils::rtrim std::string &  text_,
const std::string &  delim_
 

Trim string from the delimiter to the end of the string.

Delimiter is removed as well.

Parameters:
text_ String to modify
delim_ Delimiter character
Returns:
0 on success; -1 on error

Referenced by ASSA::IniFile::trim_section_name().

void ASSA::Utils::sleep_for_seconds long  secs_to_sleep_  )  [inline]
 

Portable sleep.

Parameters:
secs_to_sleep_ Number of seconds to sleep

Definition at line 141 of file CommonUtils.h.

00142     {
00143 #if defined (WIN32)
00144         SleepEx (secs_to_sleep_ * 1000, FALSE);
00145 #else
00146         ::sleep (secs_to_sleep_);
00147 #endif
00148     }

void ASSA::Utils::split const char *  text_,
std::vector< std::string > &  vec_
 

Split character string into tokens separated by the whitespace character (blank, tab, newline, formfeed, and carriage return).

The vec_ vector is emptied out prior parsing string text_.

Parameters:
text_ string of tokens to split
vec_ vector with tokens extracted from the string str_

int ASSA::Utils::split_pair const string &  text_,
char  sep_,
string &  lhs_,
string &  rhs_
 

Split input string into two parts separated by the separator character.

Parameters:
text_ Input string to split
sep_ Separator character
lhs_ Return left-hand side of the input string
rhs_ Return right-hand side of the input string
Returns:
0 on success; -1 if separator character was not found.

Referenced by ASSA::IniFile::load().

std::string ASSA::Utils::strenv const char *  in_  ) 
 

Expand the passed string in_ by substituting environment variable names for their values.

Environment variables must be preceeded by dollar sign and optionally enclosed in parentheses: $ENV_NAME, or , or ${ENV_NAME}. $HOME is equivalent to '~' or '~username'. If later is used, "username" is looked up in the password file.

Referenced by ASSA::GenServer::init_internals(), and ASSA::PidFileLock::lock().

void ASSA::Utils::trim_sides std::string &  text_  ) 
 

Trim white spaces and tabs from the beginning and the end of the text string.

Parameters:
text_ String to trim

Referenced by ASSA::IniFile::load().


Generated on Mon Mar 26 22:47:35 2007 for libassa by  doxygen 1.4.2