StringUtil.h File Reference

String operation utility. More...

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

Go to the source code of this file.

Functions

int getlinePortable (std::istream &istr, std::string &line)
 Read a line from input stream.
bool isEscaped (const std::string &str, std::string::size_type pos)
 Check whether the character is escaped or not.
std::string escape (const std::string str)
 Escape string.
std::string unescape (const std::string str)
 Unescape string.
void eraseHeadBlank (std::string &str)
 Erase the head blank characters of string.
void eraseTailBlank (std::string &str)
 Erase the tail blank characters of string.
void replaceString (std::string &str, const std::string from, const std::string to)
 Replace string.
std::vector
< std::string > 
split (const std::string &input, const std::string &delimiter)
 Split string by delimiter.
bool toBool (std::string str, std::string yes, std::string no, bool default_value=true)
 Convert given string into bool value.
bool isAbsolutePath (const std::string &str)
 Investigate whether the given string is absolute path or not.
bool isURL (const std::string &str)
 Investigate whether the given string is URL or not.
template<class Printable>
std::string otos (Printable n)
 Convert the given object to std::string.
template<typename To>
bool stringTo (To &val, const char *str)
 Convert the given std::string to object.
std::vector
< std::string > 
unique_sv (std::vector< std::string > sv)
 Eliminate duplication from the given string list.
std::string flatten (std::vector< std::string > sv)
 Create CSV file from the given string list.
char ** toArgv (const std::vector< std::string > &args)
 Convert the given string list into the argument list.


Detailed Description

String operation utility.

Date:
Date
Author:
Noriaki Ando <n-ando@aist.go.jp>
Copyright (C) 2003-2008 Noriaki Ando Task-intelligence Research Group, Intelligent Systems Research Institute, National Institute of Advanced Industrial Science and Technology (AIST), Japan All rights reserved.

Id

Function Documentation

void eraseHeadBlank ( std::string &  str  ) 

Erase the head blank characters of string.

Erase the blank characters that exist at the head of the given string. Space ' 'and tab '\t' are supported as the blank character.

Parameters:
str The target head blank characters of string for the erase

void eraseTailBlank ( std::string &  str  ) 

Erase the tail blank characters of string.

Erase the blank characters that exist at the tail of the given string. Space ' 'and tab '\t' are supported as the blank character.

Parameters:
str The target tail blank characters of string for the erase

std::string escape ( const std::string  str  ) 

Escape string.

The following characters are converted.
HT -> "\t"
LF -> "\n"
CR -> "\r"
FF -> "\f"
Single quote and double quote are not processed.

Parameters:
str The target string for the escape
Returns:
Result string of the escape

std::string flatten ( std::vector< std::string >  sv  ) 

Create CSV file from the given string list.

Create CSV that arranged each element of the character string list given by the argument. If the string list is empty, the null will be returned.

Parameters:
sv The target string list for creating CSV
Returns:
String of CSV creating result

int getlinePortable ( std::istream &  istr,
std::string &  line 
)

Read a line from input stream.

This function reads a line from input stream. UNIX, Windows or mixed line feed code is acceptable.

Parameters:
istr The input stream.
line The output variable to store string to be read.
Returns:
The length of read string except line feed character.

bool isAbsolutePath ( const std::string &  str  ) 

Investigate whether the given string is absolute path or not.

Investigate whether the given string is absolute path or not. Investigate it as an absolute path, if the string is as follows:

Parameters:
str The target string for the investigation
Returns:
Investigation result of absolute path

bool isEscaped ( const std::string &  str,
std::string::size_type  pos 
)

Check whether the character is escaped or not.

Check whether the specified character is escaped or not

Parameters:
str The string that includes the character to be investigated.
pos The position of the character to be investigated.
Returns:
True if the specified character is escaped, else False.

bool isURL ( const std::string &  str  ) 

Investigate whether the given string is URL or not.

Investigate whether the given string is URL or not. When the string '://' is included in the given character string, make it of URL representation.

Parameters:
str The target string for investigation
Returns:
URL investigation result

template<class Printable>
std::string otos ( Printable  n  )  [inline]

Convert the given object to std::string.

Convert the object specified by the argument to string.

Parameters:
n The target object for conversion
Returns:
String conversion result

void replaceString ( std::string &  str,
const std::string  from,
const std::string  to 
)

Replace string.

Replace the given string with the specified characters.

Parameters:
str The target characters of string for replacement processing
from Characters of replacement source
to Characters of replacement destination

std::vector<std::string> split ( const std::string &  input,
const std::string &  delimiter 
)

Split string by delimiter.

Split the set string by the given delimiter

Parameters:
input The target characters of string for split
delimiter Split string (delimiter)
Returns:
Split string result list

template<typename To>
bool stringTo ( To &  val,
const char *  str 
) [inline]

Convert the given std::string to object.

Convert string given by the argument to specified object.

Parameters:
val The object of conversion destination
str String of conversion source
Returns:
Conversion processing result

char** toArgv ( const std::vector< std::string > &  args  ) 

Convert the given string list into the argument list.

Convert the string list into the argument list by adding '\0' to each element at the end of the string list given by the argument

Parameters:
args The target string list for conversion
Returns:
String of argument conversion result

bool toBool ( std::string  str,
std::string  yes,
std::string  no,
bool  default_value = true 
)

Convert given string into bool value.

Compare the specified string with the true representation string and the false representation string, and return the result as bool value. If it matches neither the true representation string nor the false representation string as a result of the comparison, the given default value will be return.

Parameters:
str The target string for investigation
yes The true representation string
no The false representation string
default_value The default value (The default value:true)

std::string unescape ( const std::string  str  ) 

Unescape string.

The following characters are converted.
"\t" -> HT
"\n" -> LF
"\r" -> CR
"\f" -> FF
"\"" -> "
"\'" -> '
Note: This is not complete inversion of the escape processing.

Parameters:
str The target string for the unescape
Returns:
Result string of the unescape

std::vector<std::string> unique_sv ( std::vector< std::string >  sv  ) 

Eliminate duplication from the given string list.

Create a list of eliminating duplication from the string list given by the argument.

Parameters:
sv The string list for confirmation source
Returns:
Eliminating duplication result list


Generated on Thu May 29 15:03:33 2008 for OpenRTM by  doxygen 1.5.3