comparison BEDTools-Version-2.14.3/src/utils/Fasta/split.cpp @ 0:dfcd8b6c1bda

Uploaded
author aaronquinlan
date Thu, 03 Nov 2011 10:25:04 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:dfcd8b6c1bda
1 #include "split.h"
2
3 std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
4 std::stringstream ss(s);
5 std::string item;
6 while(std::getline(ss, item, delim)) {
7 elems.push_back(item);
8 }
9 return elems;
10 }
11
12 std::vector<std::string> split(const std::string &s, char delim) {
13 std::vector<std::string> elems;
14 return split(s, delim, elems);
15 }
16
17 std::vector<std::string> &split(const std::string &s, const std::string& delims, std::vector<std::string> &elems) {
18 char* tok;
19 char cchars [s.size()+1];
20 char* cstr = &cchars[0];
21 strcpy(cstr, s.c_str());
22 tok = strtok(cstr, delims.c_str());
23 while (tok != NULL) {
24 elems.push_back(tok);
25 tok = strtok(NULL, delims.c_str());
26 }
27 return elems;
28 }
29
30 std::vector<std::string> split(const std::string &s, const std::string& delims) {
31 std::vector<std::string> elems;
32 return split(s, delims, elems);
33 }