add WFObj::getLine()

This commit is contained in:
Josh Holtrop 2011-04-18 12:35:09 -04:00
parent d59eb2ffe5
commit 28722f4c94
2 changed files with 28 additions and 4 deletions

View File

@ -123,11 +123,10 @@ bool WFObj::load(const char *fname)
bool WFObj::load(const WFObj::Buffer &buff)
{
string buildup;
while (istr.good())
for (size_t idx = 0; idx < buff.size;)
{
istr.getline(buf, size+1);
string input = trimString(buf);
string line = getLine(buff, idx, &idx)
string input = trimString(line);
int sz = input.size();
if (sz == 0 || input[0] == '#')
continue;
@ -145,6 +144,30 @@ bool WFObj::load(const WFObj::Buffer &buff)
return true;
}
string WFObj::getLine(const Buff & buff, size_t idx, size_t *update_idx)
{
size_t len = 0;
while (idx + len < buff.length)
{
uint8_t ch = buff.data[idx + len];
if (ch == 0)
{
*update_idx = idx + len + 1;
break;
}
if (ch == '\r' || ch == '\n')
{
*update_idx = idx + len + 1;
uint8_t nextch = buff.data[*update_idx];
if (ch == '\r' && nextch == '\n')
(*update_idx)++;
break;
}
len++;
}
return string((const char *) &buff.data[idx], len);
}
void WFObj::processInputLine(const std::string & input)
{
string line = input;

View File

@ -77,6 +77,7 @@ protected:
void parseVertexIndices(const std::string & vtxref, int * ret);
void updateAABB(const float * const vertex);
static Buffer loadfile(const char *path);
std::string getLine(const Buff & buff, size_t idx, size_t *update_idx);
/* variables */
std::vector< std::vector<std::string> > m_data;