From 5a8f9f11c08f4c41d68fca44dc24b655fd94bceb Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Wed, 18 Jan 2017 14:26:17 -0800 Subject: [PATCH] Only warn once about non-numeric/non-integer/negative feature IDs --- geojson.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/geojson.cpp b/geojson.cpp index 79c1887..b81797f 100644 --- a/geojson.cpp +++ b/geojson.cpp @@ -241,17 +241,32 @@ int serialize_geometry(json_object *geometry, json_object *properties, json_obje id_value = strtoull(id->string, &err, 10); if (err != NULL && *err != '\0') { - fprintf(stderr, "Warning: Can't represent non-integer feature ID %s\n", id->string); + static bool warned_frac = false; + + if (!warned_frac) { + fprintf(stderr, "Warning: Can't represent non-integer feature ID %s\n", id->string); + warned_frac = true; + } } else { has_id = true; } } else { - fprintf(stderr, "Warning: Can't represent negative feature ID %s\n", id->string); + static bool warned_neg = false; + + if (!warned_neg) { + fprintf(stderr, "Warning: Can't represent negative feature ID %s\n", id->string); + warned_neg = true; + } } } else { - char *s = json_stringify(id); - fprintf(stderr, "Warning: Can't represent non-numeric feature ID %s\n", s); - free(s); // stringify + static bool warned_nan = false; + + if (!warned_nan) { + char *s = json_stringify(id); + fprintf(stderr, "Warning: Can't represent non-numeric feature ID %s\n", s); + free(s); // stringify + warned_nan = true; + } } }