Browse Source

Update csv.cpp

blueloveTH 2 years ago
parent
commit
657062d25a
1 changed files with 6 additions and 0 deletions
  1. 6 0
      src/csv.cpp

+ 6 - 0
src/csv.cpp

@@ -11,6 +11,10 @@ void add_module_csv(VM *vm){
         List ret;
         List ret;
         for(int i=0; i<csvfile.size(); i++){
         for(int i=0; i<csvfile.size(); i++){
             std::string_view line = CAST(Str&, csvfile[i]).sv();
             std::string_view line = CAST(Str&, csvfile[i]).sv();
+            if(i == 0){
+                // Skip utf8 BOM if there is any.
+                if (strncmp(line.data(), "\xEF\xBB\xBF", 3) == 0) line = line.substr(3);
+            }
             List row;
             List row;
             int j = 0;
             int j = 0;
             bool in_quote = false;
             bool in_quote = false;
@@ -37,6 +41,8 @@ void add_module_csv(VM *vm){
                             buffer.clear();
                             buffer.clear();
                         }
                         }
                         break;
                         break;
+                    case '\r':
+                        break;  // ignore
                     default:
                     default:
                         buffer += line[j];
                         buffer += line[j];
                         break;
                         break;