From 17bd48d23c1765a2baf958653bc7497cd7b39aae Mon Sep 17 00:00:00 2001 From: Ville Voutilainen Date: Thu, 30 Jul 2015 01:00:49 +0300 Subject: [PATCH] An attempt to tidy up current_timezone() --- tz.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tz.cpp b/tz.cpp index 5588f19..cd289f4 100644 --- a/tz.cpp +++ b/tz.cpp @@ -1670,10 +1670,11 @@ current_timezone() if (sz <= tmp) break; } - if (result.compare(0, 20, "/usr/share/zoneinfo/")==0) - result.erase(0, 20); - else if (result.compare(0, 22, "../usr/share/zoneinfo/")==0) - result.erase(0, 22); + const char zonepath[] = "/usr/share/zoneinfo/"; + const size_t zonepath_len = sizeof(zonepath)/sizeof(zonepath[0])-1; + const size_t pos = result.find(zonepath); + if (pos != result.npos) + result.erase(0, zonepath_len+pos); return locate_zone(result); }