update20140630
This commit is contained in:
83
uni/masterarbeit/source/moversight/common/util/StringUtil.cc
Normal file
83
uni/masterarbeit/source/moversight/common/util/StringUtil.cc
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* File: StringUtil.cc
|
||||
* Author: jgaebler
|
||||
*
|
||||
* Created on July 10, 2012, 8:13 PM
|
||||
*/
|
||||
|
||||
#include "StringUtil.h"
|
||||
|
||||
namespace ubeeme {
|
||||
namespace moversight {
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
StringUtil::StringUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Copy constructor
|
||||
* @param orig The instance to copy
|
||||
*/
|
||||
StringUtil::StringUtil(const StringUtil & /* orig */) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
StringUtil::~StringUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Splits a string into a set of substrings
|
||||
* @param s The string to split
|
||||
* @param delim The delimeter character
|
||||
* @param elems The substring set
|
||||
* @return The resulting set of substrings.
|
||||
*/
|
||||
StringList &
|
||||
StringUtil::split(const std::string &s, char delim, StringList &elems) {
|
||||
|
||||
std::stringstream ss(s);
|
||||
std::string item;
|
||||
|
||||
while (std::getline(ss, item, delim)) {
|
||||
elems.add(item);
|
||||
}
|
||||
return elems;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Splits a string into a set of substrings. The substrings are determined by the delimiter
|
||||
* Usage: std::vector<std::string> x = split("one:two::three", ':')
|
||||
* @see http://stackoverflow.com/questions/236129/how-to-split-a-string-in-c
|
||||
*
|
||||
* @param s The string to split
|
||||
* @param delimiter The delimiter charackter
|
||||
* @return The resulting set of sub strings.
|
||||
*/
|
||||
StringList
|
||||
StringUtil::split(const std::string &s, char delimiter) {
|
||||
|
||||
StringList elems;
|
||||
return split(s, delimiter, elems);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief Converts the given int to std:string.
|
||||
* @param i The int to convert.
|
||||
* @return The resulting string.
|
||||
*/
|
||||
std::string
|
||||
StringUtil::int2String(int i) {
|
||||
std::stringstream out;
|
||||
out << i;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user