PLearn 0.1
Namespaces | Functions
stringutils.cc File Reference
#include "stringutils.h"
#include "general.h"
Include dependency graph for stringutils.cc:

Go to the source code of this file.

Namespaces

namespace  PLearn
 

< for swap


Functions

string PLearn::left (const string &s, size_t width, char padding=' ')
 aligns the given string in a cell having the given width
string PLearn::right (const string &s, size_t width, char padding)
string PLearn::center (const string &s, size_t width, char padding)
string PLearn::extract_filename (const string &filepath)
 ** File path manipulation functions **
string PLearn::extract_directory (const string &filepath)
 Returns everything before the last '/' including the '/' (if there's no '/' it returns "./")
string PLearn::extract_extension (const string &filepath)
 Returns everything after the last '.
string PLearn::extract_filename_without_extension (const string &filepath)
 Returns everything before the last '.' of the filename, excluding the '.' (if there's no '.' in the filename it returns the whole filename)
string PLearn::remove_extension (const string &filename)
 Return the filename withoug the extension (i.e. removing the last.
string * PLearn::data_filename_2_filenames (const string &filename, int &nb_files)
 take a filename containing the name of a file per line, and return theses names as a string* of length nb_files
string PLearn::removeblanks (const string &s)
 removes starting and ending blanks '\n','\r',' ','\t'
string PLearn::removeallblanks (const string &s)
 removes all blanks '\n','\r',' ','\t'
string PLearn::removenewline (const string &s)
 removes any trailing '\n' and/or '\r'
string PLearn::removequotes (const string &s)
 remove exactly one pair of matching leading and trailing '\'' and '"'; if there is none, return the string unmodified
string PLearn::quote_string (const string &s)
 Quote the provided string 's'.
string PLearn::remove_trailing_slash (const string &path)
 removes any trailing '/' from the path
string PLearn::append_slash (const string &path)
 appends a trailing slash to path if there isn't already one
string PLearn::lowerstring (const string &s)
 convert a string to all lowercase
string PLearn::upperstring (const string &s)
 convert a string to all uppercase
string PLearn::pgetline (istream &in=cin)
 returns the next line read from the stream, after removing any trailing '\r' and/or '\n'
bool PLearn::isBlank (const string &s)
 returns true if s is a blank line (containing only space, tab, until end of line or a # comment-character is reached
bool PLearn::isParagraphBlank (const string &s)
 returns true if s is a blank paragraph (containing only space, tab, until end of **string**)
string PLearn::space_to_underscore (string str)
 replaces all characters <= ' ' (i.e. newline, tab, space, etc...) by '_'
string PLearn::underscore_to_space (string str)
 replaces all underscores by a single space character
string PLearn::backslash_to_slash (string str)
 replaces all backslashes with slash
int PLearn::search_replace (string &text, const string &searchstr, const string &replacestr)
 replaces all occurences of searchstr in the text by replacestr returns the number of matches that got replaced
vector< string > PLearn::split (const string &s, char delimiter)
 splits a string along occurences of the delimiters.
vector< string > PLearn::split_quoted_delimiter (const string &s, char delimiter, const string &double_quote)
vector< string > PLearn::split_quoted_delimiter (const string &s, char delimiter, char double_quote)
vector< string > PLearn::split_quoted_delimiter (const string &s, const string &delimiters, const string &double_quote)
vector< string > PLearn::split_all (const string &s, const string &delimiters)
vector< string > PLearn::split (const string &s, const string &delimiters, bool keep_delimiters)
void PLearn::split_on_first (const string &s, const string &delimiters, string &left, string &right)
pair< string, string > PLearn::split_on_first (const string &s, const string &delimiters)
void PLearn::remove_comments (string &text, const string &commentstart="#")
 In a multiline text, removes everything starting at commentstart pattern until the end of line.
string PLearn::join (const vector< string > &s, const string &separator=" ")
 makes a single string from a vector of strings
vector< string > PLearn::remove (const vector< string > &v, string element)
 return vector with all instances of element removed
int PLearn::findpos (const vector< string > &v, string element)
 return index of element in v, or -1 if not found
int PLearn::universal_compare (const string &x, const string &y)
 "Universal compare".
vector< string > PLearn::addprepostfix (const string &prefix, const vector< string > &names, const string &postfix)
 returns the list of names, but with a prepended prefix and an appended postfix
string PLearn::addprepostfix (const string &prefix, const string &text, const string &postfix)
 Returns a string with the prefix prepended and the postfix appended to each *line* of the text string.
vector< string > PLearn::stringvector (int argc, char **argv)
 makes a C++ style vector of strings from a C style vectr of strings Note: this may be useful in conjunction with get_option.
string PLearn::get_option (const vector< string > &command_line, const string &option, const string &default_value)
bool PLearn::find (const vector< string > &command_line, const string &option)
vector< string > PLearn::getNonBlankLines (const string &in)
 Returns a vector of string containing only non-empty lines, as you guessed it.
ostream & PLearn::operator<< (ostream &out, const vector< string > &vs)
 formatted printing of vector<string> prints strings separated by a ", "
vector< string > PLearn::split_from_string (const string &s, const string &delimiter)
 Split a string along occurences of the substring 'delimiter'.
void PLearn::parseBaseAndParameters (const string &s, string &base, map< string, string > &params, map< string, string > *added=0, map< string, string > *backup=0, const string &delimiter="::")
 From a string s = "base_string::arg1=val1::arg2=val2::arg3=val3", fill 'base' with 'base_string', and add to 'params' mappings argX -> valX.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines