summaryrefslogtreecommitdiff
path: root/project2/fileRows.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/fileRows.cpp')
-rw-r--r--project2/fileRows.cpp138
1 files changed, 5 insertions, 133 deletions
diff --git a/project2/fileRows.cpp b/project2/fileRows.cpp
index e990f56..11a71ef 100644
--- a/project2/fileRows.cpp
+++ b/project2/fileRows.cpp
@@ -8,21 +8,9 @@ DECLARE_LOADER("filerows", FileRows);
FileRows::FileRows(const xmlpp::Element * p) :
SourceObject(p),
- RowSet(p),
- path(p, "path"),
- fieldSep(p->get_attribute_value("fieldSep")[0]),
- quoteChar(p->get_attribute_value("quoteChar")[0]),
- keepBlankRows(p->get_attribute_value("keepBlankRows") == "true"),
- countBlankRows(p->get_attribute_value("keepBlankRows") == "count"),
- newline(p->get_attribute_value("newline")),
- encoding(p->get_attribute_value("encoding"))
+ StreamRows(p),
+ path(p, "path")
{
- BOOST_FOREACH(const xmlpp::Node * node, p->find("columns/column")) {
- const xmlpp::Element * elem = dynamic_cast<const xmlpp::Element *>(node);
- if (elem) {
- columns.push_back(boost::shared_ptr<Glib::ustring>(new Glib::ustring(elem->get_child_text()->get_content())));
- }
- }
}
FileRows::~FileRows()
@@ -40,131 +28,15 @@ FileRows::setFilter(const Glib::ustring &)
throw NotSupported(__PRETTY_FUNCTION__);
}
-unsigned int
-FileRows::columnCount() const
-{
- return columns.size();
-}
-
-const Glib::ustring &
-FileRows::getColumnName(unsigned int col) const
-{
- return *columns[col];
-}
-
void
FileRows::execute(const RowProcessor * rp) const
{
rowNum = 1;
FileStarChannel c(doOpen());
c.set_encoding(encoding);
- c.set_line_term(newline);
- Glib::ustring line;
- while (c.read_line(line) == Glib::IO_STATUS_NORMAL) {
- if (boost::algorithm::ends_with(line, newline)) {
- line.erase(line.length() - newline.length());
- }
- Columns::const_iterator curCol = columns.begin();
- bool mkCols = columns.empty();
- bool inQuotes = false;
- bool prevWasQuote = false;
- typedef boost::shared_ptr<Glib::ustring> StringPtr;
- StringPtr tok(new Glib::ustring());
- BOOST_FOREACH(gunichar c, line) {
- if (c == quoteChar) {
- if (prevWasQuote) {
- *tok += c;
- prevWasQuote = false;
- inQuotes = !inQuotes;
- }
- else {
- prevWasQuote = inQuotes;
- inQuotes = !inQuotes;
- }
- }
- else if ((!inQuotes) && (c == fieldSep)) {
- prevWasQuote = false;
- if (mkCols) {
- addColumn(tok);
- }
- else {
- values.push_back(tok);
- curCol++;
- }
- tok = StringPtr(new Glib::ustring());
- }
- else {
- prevWasQuote = false;
- *tok += c;
- }
- }
- if (tok->length()) {
- if (mkCols) {
- addColumn(tok);
- }
- else {
- values.push_back(tok);
- curCol++;
- }
- }
- if (!mkCols) {
- if (keepBlankRows || !values.empty()) {
- while (values.size() < columns.size()) {
- values.push_back(VariableType());
- curCol++;
- }
- rp->rowReady();
- rowNum += 1;
- }
- else if (countBlankRows) {
- rowNum +=1;
- }
- }
- values.clear();
- }
-}
-
-VariableType
-FileRows::getCurrentValue(unsigned int col) const
-{
- return values[col];
-}
-
-bool
-FileRows::isNull(unsigned int) const
-{
- return false;
-}
-
-bool
-FileRows::isNull(const Glib::ustring &) const
-{
- return false;
-}
-
-VariableType
-FileRows::getCurrentValue(const Glib::ustring & id) const
-{
- Values::const_iterator v = values.begin();
- for (Columns::const_iterator i = columns.begin(); i != columns.end(); i++, v++) {
- if (**i == id) {
- return *v;
- }
- }
- throw RowSet::FieldDoesNotExist();
-}
-
-void
-FileRows::addColumn(boost::shared_ptr<Glib::ustring> tok) const
-{
- columns.push_back(tok);
- for (Glib::ustring::iterator i = tok->begin(); i != tok->end(); ) {
- if (!isalnum(*i)) {
- tok->erase(i);
- }
- else {
- i++;
- }
+ gunichar ch;
+ while (c.read(ch) == Glib::IO_STATUS_NORMAL) {
+ this->pushChar(ch, rp);
}
}