#include #include #include #include "linebreaker2.h" using namespace std; /* * Fill the vector with pointers to each word in the string. */ void LineBreaker2::fill() { // Find all the words. char last = ' '; for(char *scan = m_data.get(); *scan; ++scan) { // Current character. char curr = *scan; // If the last was a space and this is not, word start. if(isspace(last) && !isspace(curr)) m_ptrs.push_back(scan); // If last was not space, and this is, word end else if(!isspace(last) && isspace(curr)) *scan = '\0'; // The current is last for the next time 'round. last = curr; } // Add the null. m_ptrs.push_back(nullptr); } char *LineBreaker2::pop_back() { // If it's too small, bail. if(size() < 1) return nullptr; // Get the last string for later return, then remove the null and the // returned item, then put the null back. char *ret = back(); m_ptrs.pop_back(); m_ptrs.pop_back(); m_ptrs.push_back(nullptr); return ret; }