From a3d6648fa6c0138e1d02408a117f87cbd3407e80 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 2 Feb 2015 03:33:43 +0100 Subject: Workaround for old libraries without regex support --- src/MinedMap.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/MinedMap.cpp b/src/MinedMap.cpp index 7e7d249..6207306 100644 --- a/src/MinedMap.cpp +++ b/src/MinedMap.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include @@ -134,8 +133,6 @@ static void doRegion(const std::string &input, const std::string &output) { } int main(int argc, char *argv[]) { - static const std::regex re("r\\.(-?\\d+)\\.(-?\\d+)\\.mca"); - if (argc < 3) { std::fprintf(stderr, "Usage: %s \n", argv[0]); return 1; @@ -156,15 +153,19 @@ int main(int argc, char *argv[]) { struct dirent *entry; while ((entry = readdir(dir)) != nullptr) { - std::cmatch m; - if (std::regex_match(entry->d_name, m, re)) { - int x = std::atoi(m[1].str().c_str()); + int x, z; + if (std::sscanf(entry->d_name, "r.%i.%i.mca", &x, &z) == 2) { + size_t l = strlen(entry->d_name) + 1; + char buf[l]; + std::snprintf(buf, l, "r.%i.%i.mca", x, z); + if (std::memcmp(entry->d_name, buf, l)) + continue; + if (x < minX) minX = x; if (x > maxX) maxX = x; - int z = std::atoi(m[2].str().c_str()); if (z < minZ) minZ = z; if (z > maxZ) -- cgit v1.2.3