diff options
author | Olga Khlopkova <o.khlopkova@corp.mail.ru> | 2020-06-19 11:05:01 +0300 |
---|---|---|
committer | Olga Khlopkova <o.khlopkova@corp.mail.ru> | 2020-06-19 11:05:01 +0300 |
commit | e851019d3a2ad11c2f33ebd56ed9ee6a4d0a98a6 (patch) | |
tree | 8c958896461d4406d8a437a10a9b6698b06eaa4b | |
parent | 07d343eed8fc6e4753cf016a2cef2ae7b172fdb8 (diff) |
fix for quotes
-rw-r--r-- | include/just_gtfs/just_gtfs.h | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/include/just_gtfs/just_gtfs.h b/include/just_gtfs/just_gtfs.h index c69d9ad..bbfcd66 100644 --- a/include/just_gtfs/just_gtfs.h +++ b/include/just_gtfs/just_gtfs.h @@ -116,7 +116,18 @@ inline std::string unquote_text(const std::string & text) size_t quotes_count = 0; - for (size_t i = 0; i < text.size(); ++i) + size_t start_index = 0; + size_t end_index = text.size(); + + // Field values that contain quotation marks or commas must be enclosed within quotation marks. + if (text.size() > 1 && text.front() == quote && text.back() == quote) + { + ++start_index; + --end_index; + } + + // In addition, each quotation mark in the field value must be preceded with a quotation mark. + for (size_t i = start_index; i < end_index; ++i) { if (text[i] != quote) { @@ -142,12 +153,6 @@ inline std::string unquote_text(const std::string & text) } } - if (res.size() > 2 && res.front() == quote && res.back() == quote && (quotes_count - 2) % 2 == 0) - return res.substr(1, res.size() - 2); - - if (res == "\"") - return {}; - return res; } |