Mercurial > repos > aaronquinlan > multi_intersect
diff BEDTools-Version-2.14.3/src/utils/lineFileUtilities/lineFileUtilities.h @ 0:dfcd8b6c1bda
Uploaded
author | aaronquinlan |
---|---|
date | Thu, 03 Nov 2011 10:25:04 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BEDTools-Version-2.14.3/src/utils/lineFileUtilities/lineFileUtilities.h Thu Nov 03 10:25:04 2011 -0400 @@ -0,0 +1,52 @@ +#ifndef LINEFILEUTILITIES_H +#define LINEFILEUTILITIES_H + +#include <vector> +#include <string> +#include <cstring> +#include <cstdlib> +#include <sstream> + +using namespace std; + +// templated function to convert objects to strings +template <typename T> +inline +std::string ToString(const T & value) { + std::stringstream ss; + ss << value; + return ss.str(); +} + +// tokenize into a list of strings. +inline +void Tokenize(const string &str, vector<string> &elems, const string &delimiter = "\t") +{ + char* tok; + char cchars [str.size()+1]; + char* cstr = &cchars[0]; + strcpy(cstr, str.c_str()); + tok = strtok(cstr, delimiter.c_str()); + while (tok != NULL) { + elems.push_back(tok); + tok = strtok(NULL, delimiter.c_str()); + } +} + +// tokenize into a list of integers +inline +void Tokenize(const string &str, vector<int> &elems, const string &delimiter = "\t") +{ + char* tok; + char cchars [str.size()+1]; + char* cstr = &cchars[0]; + strcpy(cstr, str.c_str()); + tok = strtok(cstr, delimiter.c_str()); + while (tok != NULL) { + elems.push_back(atoi(tok)); + tok = strtok(NULL, delimiter.c_str()); + } +} + +#endif /* LINEFILEUTILITIES_H */ +