From d76e279492d6d8f8213279cdb56d3910a42b4355 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Wed, 28 Apr 2021 07:16:32 +0100 Subject: [PATCH] Windows: term prefixes: work around the fact that we forgot to lowercase the drive names --- src/rcldb/rcldb.h | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/rcldb/rcldb.h b/src/rcldb/rcldb.h index 88a92cae..b382d594 100644 --- a/src/rcldb/rcldb.h +++ b/src/rcldb/rcldb.h @@ -134,19 +134,24 @@ inline bool has_prefix(const string& trm) inline string strip_prefix(const string& trm) { - if (trm.empty()) + if (!has_prefix(trm)) return trm; string::size_type st = 0; if (o_index_stripchars) { st = trm.find_first_not_of("ABCDEFIJKLMNOPQRSTUVWXYZ"); - if (st == string::npos) - return string(); - } else { - if (has_prefix(trm)) { - st = trm.find_last_of(":") + 1; - } else { - return trm; +#ifdef _WIN32 + // We have a problem there because we forgot to lowercase the drive + // name. So if the found character is a colon consider the drive name as + // the first non capital even if it is uppercase + if (st != string::npos && st >= 2 && trm[st] == ':') { + st -= 1; } +#endif + } else { + st = trm.find_first_of(":", 1) + 1; + } + if (st == string::npos) { + return string(); // ?? } return trm.substr(st); } @@ -154,13 +159,27 @@ inline string strip_prefix(const string& trm) inline string get_prefix(const string& trm) { if (!has_prefix(trm)) - return trm; + return string(); string::size_type st = 0; if (o_index_stripchars) { st = trm.find_first_not_of("ABCDEFIJKLMNOPQRSTUVWXYZ"); + if (st == string::npos) { + return string(); // ?? + } +#ifdef _WIN32 + // We have a problem there because we forgot to lowercase the drive + // name. So if the found character is a colon consider the drive name as + // the first non capital even if it is uppercase + if (st >= 2 && trm[st] == ':') { + st -= 1; + } +#endif return trm.substr(0, st); } else { - st = trm.find_last_of(":") + 1; + st = trm.find_first_of(":", 1) + 1; + if (st == string::npos) { + return string(); // ?? + } return trm.substr(1, st-2); } }