Anonymous avatar Anonymous committed 8561e0a

CPP: Fix geocoding data parser.

Patch contributed by pmezard.

The "end" iterator must stay on the trailing LF, for it is not included in the
line characters sequence. Also fix the test which should have failed.

Comments (0)

Files changed (2)

cpp/test/phonenumbers/geocoding/geocoding_data_test.cc

   ASSERT_EQ(2, desc_1_de->prefixes_size);
   const int32 expected_prefixes[] = {1201, 1650};
   const char* expected_descriptions[] = {
-    "New Jerse",
-    "Kalifornie",
+    "New Jersey",
+    "Kalifornien",
   };
   for (int i = 0; i < desc_1_de->prefixes_size; ++i) {
     EXPECT_EQ(expected_prefixes[i], desc_1_de->prefixes[i]);

tools/cpp/src/cpp-build/generate_geocoding_data.cc

       continue;
     }
     --end;
-    if (*end != '\n') {
-      if (!feof(input)) {
-        // A line without LF can only happen at the end of file.
-        return false;
-      }
-    } else {
-      // Consume the LF.
-      --end;
+    if (*end != '\n' && !feof(input)) {
+      // A line without LF can only happen at the end of file.
+      return false;
     }
 
     // Trim and check for comments.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.