fs/StandardDirectory: pass std::string_view to ParseConfigLine()
This commit is contained in:
parent
f6f3c4c25b
commit
ea5bcfed8b
|
@ -60,6 +60,8 @@
|
||||||
static constexpr Path app_filename = Path::FromFS(APP_FILENAME);
|
static constexpr Path app_filename = Path::FromFS(APP_FILENAME);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using std::string_view_literals::operator""sv;
|
||||||
|
|
||||||
#if !defined(_WIN32) && !defined(ANDROID)
|
#if !defined(_WIN32) && !defined(ANDROID)
|
||||||
class PasswdEntry
|
class PasswdEntry
|
||||||
{
|
{
|
||||||
|
@ -134,49 +136,42 @@ static AllocatedPath GetStandardDir(int folder_id)
|
||||||
|
|
||||||
#ifdef USE_XDG
|
#ifdef USE_XDG
|
||||||
|
|
||||||
static const char home_prefix[] = "$HOME/";
|
static constexpr std::string_view home_prefix = "$HOME/"sv;
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
ParseConfigLine(const char *line, const char *dir_name,
|
ParseConfigLine(std::string_view line, std::string_view dir_name,
|
||||||
AllocatedPath &result_dir)
|
AllocatedPath &result_dir)
|
||||||
{
|
{
|
||||||
// strip leading white space
|
// strip leading white space
|
||||||
line = StripLeft(line);
|
line = StripLeft(line);
|
||||||
|
|
||||||
// check for end-of-line or comment
|
// check for end-of-line or comment
|
||||||
if (*line == '\0' || *line == '#')
|
if (line.empty() || line.front() == '#')
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// check if current setting is for requested dir
|
// check if current setting is for requested dir
|
||||||
if (!StringStartsWith(line, dir_name))
|
if (!SkipPrefix(line, dir_name))
|
||||||
return false;
|
return false;
|
||||||
line += strlen(dir_name);
|
|
||||||
|
|
||||||
// strip equals sign and spaces around it
|
// strip equals sign and spaces around it
|
||||||
line = StripLeft(line);
|
line = StripLeft(line);
|
||||||
if (*line != '=')
|
if (!SkipPrefix(line, "="sv))
|
||||||
return false;
|
return false;
|
||||||
++line;
|
|
||||||
line = StripLeft(line);
|
line = StripLeft(line);
|
||||||
|
|
||||||
|
if (line.empty())
|
||||||
|
return true;
|
||||||
|
|
||||||
// check if path is quoted
|
// check if path is quoted
|
||||||
bool quoted = false;
|
const bool quoted = SkipPrefix(line, "\""sv);
|
||||||
if (*line == '"') {
|
|
||||||
++line;
|
|
||||||
quoted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if path is relative to $HOME
|
// check if path is relative to $HOME
|
||||||
bool home_relative = false;
|
const bool home_relative = SkipPrefix(line, home_prefix);
|
||||||
if (StringStartsWith(line, home_prefix)) {
|
|
||||||
line += strlen(home_prefix);
|
|
||||||
home_relative = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// find end of the string
|
// find end of the string
|
||||||
std::string_view path_view;
|
std::string_view path_view;
|
||||||
if (quoted) {
|
if (quoted) {
|
||||||
const auto [pv, rest] = SplitLast(std::string_view{line}, '"');
|
const auto [pv, rest] = SplitLast(line, '"');
|
||||||
if (rest.data() == nullptr)
|
if (rest.data() == nullptr)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue