CB100

Notas, resueltos y tps de la materia Algoritmos y Estructuras de Datos
Index Commits Files Refs README
commit d1204bff746da9aa26678c68149e90b4629ae8ce
parent c5876968c34d4a9be3ce244072abb014281e49a7
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date:   Thu, 20 Jun 2024 17:27:09 -0300

if `token` is a string and is surrounded by `"` remove them

Diffstat:
Mmain.cpp | 13++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/main.cpp b/main.cpp
@@ -31,6 +31,11 @@ enum {
     LINEA_6_SENTIDO
 };
 
+void delSurroundingChar(std::string &str, char c) {
+    str.erase(0, 1);
+    str[str.size() - 1] = '\0';
+}
+
 size_t getTokens(std::string line, std::vector<std::string> &tokens) {
     std::string token;
     std::stringstream lineStream;
@@ -46,17 +51,15 @@ size_t getTokens(std::string line, std::vector<std::string> &tokens) {
             std::getline(lineStream, nextToken, CSV_DELIM);
             token += CSV_DELIM + nextToken;
         }
+        if(token[0] == '"' && token[token.size() - 1] == '"') {
+            delSurroundingChar(token, '"');
+        }
         tokens.push_back(token);
     }
 
     return field;
 }
 
-void delSurroundingChar(std::string &str, char c) {
-    str.erase(0, 1);
-    str[str.size() - 1] = '\0';
-}
-
 // busca el barrio en la lista de barrios, si no lo encuentra devuelve NULL
 Barrio *getBarrioPorNombre(std::string nombre, List<Barrio*> *barrios) {
     if(barrios == NULL) {