Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

StringTool Class Reference


Detailed Description

String utils.

Definition at line 10 of file StringTool.h.

Public Types

typedef std::vector< std::string > t_args

Static Public Member Functions

static long readInt (const char *text, bool *ok)
 Convert string to number.
static std::string toString (long value)
 Convert long to string.
static bool startsWith (const std::string &str, const std::string &prefix)
static void replace (std::string &buffer, const std::string &pattern, const std::string &newstring)
 Replace one substring with another.
static t_args split (const std::string &str, char separator)
 Split string.


Member Typedef Documentation

typedef std::vector<std::string> StringTool::t_args
 

Definition at line 12 of file StringTool.h.


Member Function Documentation

long StringTool::readInt const char *  strNum,
bool *  ok
[static]
 

Convert string to number.

Parameters:
strNum string
ok true on sucess
Returns:
number or zero

Definition at line 21 of file StringTool.cpp.

00022 {
00023     long result = 0;
00024     *ok = false;
00025 
00026     if (strNum != NULL) {
00027         char *endptr;
00028         result = strtol(strNum, &endptr, 0);
00029         if (strNum[0] != '\0' && endptr[0] == '\0') {
00030             *ok = true;
00031         }
00032     }
00033 
00034     if (!ok) {
00035         result = 0;
00036     }
00037 
00038     return result;
00039 }

void StringTool::replace std::string &  buffer,
const std::string &  pattern,
const std::string &  newstring
[static]
 

Replace one substring with another.

Parameters:
buffer string to change
pattern what replace
newstring what to place

Definition at line 67 of file StringTool.cpp.

00069 {
00070     std::string::size_type pos = buffer.find(pattern);
00071     while (pos != std::string::npos) {
00072         buffer.replace(pos, pattern.size(), newstring);
00073         pos = buffer.find(pattern, pos + newstring.size());
00074     }
00075 }

StringTool::t_args StringTool::split const std::string &  str,
char  separator
[static]
 

Split string.

Returns:
splited segments without separator

Definition at line 82 of file StringTool.cpp.

00083 {
00084     std::string remain = str;
00085     t_args args;
00086 
00087     std::string::size_type pos = remain.find(separator);
00088     while (pos != std::string::npos) {
00089         args.push_back(remain.substr(0, pos));
00090         remain.erase(0, pos + 1);
00091 
00092         pos = remain.find(separator);
00093     }
00094     if (remain.size() > 0) {
00095         args.push_back(remain);
00096     }
00097 
00098     return args;
00099 }

bool StringTool::startsWith const std::string &  str,
const std::string &  prefix
[static]
 

Definition at line 54 of file StringTool.cpp.

00056 {
00057     return prefix == str.substr(0, prefix.size());
00058 }

std::string StringTool::toString long  value  )  [static]
 

Convert long to string.

Returns:
string value

Definition at line 46 of file StringTool.cpp.

00047 {
00048     std::ostringstream buffer;
00049     buffer << value;
00050     return buffer.str();
00051 }


The documentation for this class was generated from the following files:
Generated on Wed Jun 1 09:57:00 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2