Back to index

supertuxkart  0.5+dfsg1
Functions
StringUtils Namespace Reference

Functions

bool has_suffix (const std::string &lhs, const std::string rhs)
std::string path (const std::string &filename)
 Return the path (i.e.
std::string basename (const std::string &filename)
 Return the filename part of a path.
std::string without_extension (const std::string &filename)
std::string extension (const std::string &filename)
std::string upcase (const std::string &str)
std::string downcase (const std::string &str)
std::vector< std::string > split (const std::string &s, char c)
template<class T >
std::string to_string (const T &any)
template<class T >
bool from_string (const std::string &rep, T &x)
 Convert the contents in string rep to type T, if conversion fails false is returned and the value of x is unchanged, if true is returned the conversation was successfull.

Function Documentation

std::string StringUtils::basename ( const std::string &  filename)

Return the filename part of a path.

Definition at line 52 of file string_utils.cpp.

    {
        for(int i = int(filename.size()) - 1; i >= 0; --i)
        {
            if (filename[i]=='/' || filename[i]=='\\')
            {
                return filename.substr(i+1);
            }
        }
        return filename;
    }

Here is the caller graph for this function:

std::string StringUtils::downcase ( const std::string &  str)

Definition at line 99 of file string_utils.cpp.

    {
        std::string name = str;
        std::transform(name.begin(), name.end(), name.begin(), ::tolower);
        return name;
    }
std::string StringUtils::extension ( const std::string &  filename)

Definition at line 78 of file string_utils.cpp.

    {
        for(int i = int(filename.size()) - 1; i >= 0; --i)
        {
            if (filename[i] == '.')
            {
                return filename.substr(i+1);
            }
        }
        return filename;
    }

Here is the caller graph for this function:

template<class T >
bool StringUtils::from_string ( const std::string &  rep,
T &  x 
)

Convert the contents in string rep to type T, if conversion fails false is returned and the value of x is unchanged, if true is returned the conversation was successfull.

Definition at line 54 of file string_utils.hpp.

    {
        // this is necessary so that if "x" is not modified if the conversion fails
        T temp;
        std::istringstream iss(rep);
        iss >> temp;

        if (iss.fail())
        {
            return false;
        }
        else
        {
            x = temp;
            return true;
        }
    }
bool StringUtils::has_suffix ( const std::string &  lhs,
const std::string  rhs 
)

Definition at line 27 of file string_utils.cpp.

    {
        if (lhs.length() < rhs.length())
            return false;
        else
            // While this is basically correct, it fails with older
            // g++ versions (at least 2.95.3), which have a wrong template. To
            // avoid this issue, a more C-traditional way is used.
            return strcmp(lhs.c_str()+(lhs.length()-rhs.length()), rhs.c_str())==0;
    }

Here is the caller graph for this function:

std::string StringUtils::path ( const std::string &  filename)

Return the path (i.e.

up to the last /

Definition at line 39 of file string_utils.cpp.

    {
        for(int i = int(filename.size()) - 1; i >= 0; --i)
        {
            if (filename[i]=='/' || filename[i]=='\\')
            {
                return filename.substr(0,i);
            }
        }
        return "";
    }

Here is the caller graph for this function:

std::vector< std::string > StringUtils::split ( const std::string &  s,
char  c 
)

Definition at line 109 of file string_utils.cpp.

    {
        std::vector<std::string> result;
    
        std::string::size_type start=0;
        while(start!=std::string::npos)
        {
            std::string::size_type i=s.find(c, start);
            if(i!=std::string::npos)
            {
                result.push_back(std::string(s,start, i-start));
                start=i+1;
            } 
            else
            {
                result.push_back(std::string(s,start));
                start = i;
            }
        }
        return result;
    }

Here is the caller graph for this function:

template<class T >
std::string StringUtils::to_string ( const T &  any)

Definition at line 43 of file string_utils.hpp.

    {
        std::ostringstream oss;
        oss << any ;
        return oss.str();
    }
std::string StringUtils::upcase ( const std::string &  str)

Definition at line 91 of file string_utils.cpp.

    {
        std::string name = str;
        std::transform(name.begin(), name.end(), name.begin(), ::toupper);
        return name;
    }
std::string StringUtils::without_extension ( const std::string &  filename)

Definition at line 65 of file string_utils.cpp.

    {
        for(int i = int(filename.size()) - 1; i >= 0; --i)
        {
            if (filename[i] == '.')
            {
                return filename.substr(0, i);
            }
        }
        return filename;
    }

Here is the caller graph for this function: