static strm_value csv_value(const char* p, strm_int len, enum csv_type ftype) { const char *s = p; const char *send = s+len; long i=0; double f, pow = 1; enum csv_type type = TYPE_STR; switch (ftype) { case TYPE_UNSPC: case TYPE_NUM: /* skip preceding white spaces */ while (isspace((int)*s)) s++; /* check if numbers */ while (s<send) { switch (*s) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (type == TYPE_STR) type = TYPE_INT; i = i*10 + (*s - '0'); pow *= 10; break; case '.': if (type == TYPE_FLT) { /* second dot */ type = TYPE_TIME; break; } type = TYPE_FLT; f = i; i = 0; pow = 1; break; default: type = TYPE_UNSPC; break; } s++; } default: break; } switch (type) { case TYPE_INT: return strm_int_value(i); case TYPE_FLT: f += i / pow; return strm_flt_value(f); default: return csv_string(p, len, ftype); } /* not reached */ }
//does not set size for vector<string> buf, cause it`s unknown at this point csv_buffer::csv_buffer(istream& stream) { cursor = 0; string s; while( getline(stream, s) && s.compare("END") != 0 ) { cursor++; if (s.length() > 0) buf.push_back(csv_string(s)); } cursor = 0; }
//sends 1 string from buf csv_string csv_buffer::send() { cursor++; if(cursor-1 < this->size()) return(buf[cursor-1]); else return(csv_string("")); }