#include <string>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <list>
#include "linebreaker.h"
LineBreaker::LineBreaker(const string &s)
{
// Copy the string as a character array.
m_data = new char[s.length()+1];
strcpy(m_data, s.c_str());
// Find all the words.
char last = ' ';
list<char *> parts;
for(char *scan = m_data; *scan; ++scan) {
char curr = *scan;
if(isspace(last) && !isspace(curr))
parts.push_back(scan);
else if(!isspace(last) && isspace(curr))
*scan = '\0';
last = curr;
}
// Allocate the array of pointers for exec, and copy the
// pointer into it. Then add the NULL terminator.
m_parmlist = new char * [parts.size()+1];
copy(parts.begin(), parts.end(), m_parmlist);
m_parmlist[parts.size()] = NULL;
m_count = parts.size();
}
// Pop and return the last item from the list.
SorC LineBreaker::pop()
{
if(m_count <= 0) return SorC("");
SorC ret(m_parmlist[--m_count]);
m_parmlist[m_count] = NULL;
return ret;
}