// // Copyright 2009 Illumina, Inc. // // This software is covered by the "Illumina Genome Analyzer Software // License Agreement" and the "Illumina Source Code License Agreement", // and certain third party copyright/licenses, and any user of this // source file is bound by the terms therein (see accompanying files // Illumina_Genome_Analyzer_Software_License_Agreement.pdf and // Illumina_Source_Code_License_Agreement.pdf and third party // copyright/license notices). // // /// \file /// \author Ivan Mikoulitch /// #include "stringSplitter.h" ////////////////////////////////////////////////////////////////////// StringSplitter::StringSplitter(const string& str) : str_(str) { ProcessString(); } ////////////////////////////////////////////////////////////////////// StringSplitter::~StringSplitter(void) { } ////////////////////////////////////////////////////////////////////// void StringSplitter::ProcessString() { indexes_.push_back(-1); string::const_iterator s_it = str_.begin(); int index=0; while(s_it!=str_.end()) { if (*s_it=='\t') indexes_.push_back(index); ++s_it; ++index; } indexes_.push_back(index); return; } ////////////////////////////////////////////////////////////////////// // index is one based; first element = 1. string StringSplitter::GetString(int start_index, int end_index/*=0*/) { int start = indexes_[start_index-1]+1; int length = indexes_[end_index==0?start_index:end_index] - start; string str = str_.substr(start, length); return str; } ////////////////////////////////////////////////////////////////////// // index is one based; first element = 1. string StringSplitter::GetStringEnd(unsigned int start_index) { // ivan to test if(start_index>=indexes_.size()) return ""; int start = indexes_[start_index-1]+1; int length = str_.size() - start; string str = str_.substr(start, length); return str; }