Skip to content

Move the implementation of get_and_strip_column to CSVColumn #7

@zweaver-chwy

Description

@zweaver-chwy

Add this method in CSVColumn:

std::string CSVColumn::get_stripped_value(const char quote) const
{
    const std::string& str = this->get_value();

    if (str.empty())
        return std::string{};

    // if the quote is not present on both sides, return the string as is
    // (although, this is almost surely a cause of another problem)
    if (str[0] != quote && str[str.length() - 1] != quote)
        return str;

    std::string stripped_str;
    for (std::size_t i = 1; i < str.length() - 1; ++i)
        stripped_str.push_back(str[i]);

    return stripped_str;
}

Replace CSVReader::get_and_strip_column with:

std::string CSVReader::get_and_strip_column(const std::size_t idx) const
{
    if (idx >= this->m_columns.size())
        return std::string{};

    return this->m_columns[idx].get_stripped_value(this->m_quote);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions