mirror of
https://github.com/HowardHinnant/date.git
synced 2024-12-27 00:14:07 +08:00
Search for '/' after "zoneinfo" in current_zone()
This commit is contained in:
parent
23fa1bb86d
commit
3f0f9b3cbe
18
src/tz.cpp
18
src/tz.cpp
@ -3697,20 +3697,22 @@ tzdb::current_zone() const
|
|||||||
throw system_error(errno, system_category(), "realpath() failed");
|
throw system_error(errno, system_category(), "realpath() failed");
|
||||||
#if HAS_STRING_VIEW
|
#if HAS_STRING_VIEW
|
||||||
string_view result = rp;
|
string_view result = rp;
|
||||||
CONSTDATA string_view zoneinfo = "/zoneinfo/";
|
CONSTDATA string_view zoneinfo = "zoneinfo";
|
||||||
const size_t pos = result.rfind(zoneinfo);
|
size_t pos = result.rfind(zoneinfo);
|
||||||
if (pos == result.npos)
|
if (pos == result.npos)
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
"current_zone() failed to find \"/zoneinfo/\" in " + string(result));
|
"current_zone() failed to find \"zoneinfo\" in " + string(result));
|
||||||
result.remove_prefix(pos + zoneinfo.size());
|
pos = result.find('/', pos);
|
||||||
|
result.remove_prefix(pos + 1);
|
||||||
#else
|
#else
|
||||||
string result = rp;
|
string result = rp;
|
||||||
CONSTDATA char zoneinfo[] = "/zoneinfo/";
|
CONSTDATA char zoneinfo[] = "zoneinfo";
|
||||||
const size_t pos = result.rfind(zoneinfo);
|
size_t pos = result.rfind(zoneinfo);
|
||||||
if (pos == result.npos)
|
if (pos == result.npos)
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
"current_zone() failed to find \"/zoneinfo/\" in " + result);
|
"current_zone() failed to find \"zoneinfo\" in " + result);
|
||||||
result.erase(0, pos + sizeof(zoneinfo) - 1);
|
pos = result.find('/', pos);
|
||||||
|
result.erase(0, pos + 1);
|
||||||
#endif
|
#endif
|
||||||
return locate_zone(result);
|
return locate_zone(result);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user