Commit 9acc1e1e authored by Max Kellermann's avatar Max Kellermann

Permission: use std::find instead of g_strsplit()

parent daa47546
......@@ -24,16 +24,15 @@
#include "ConfigOption.hxx"
#include "system/FatalError.hxx"
#include <algorithm>
#include <map>
#include <string>
#include <glib.h>
#include <assert.h>
#include <string.h>
static constexpr char PERMISSION_PASSWORD_CHAR = '@';
#define PERMISSION_SEPERATOR ","
static constexpr char PERMISSION_SEPARATOR = ',';
static constexpr struct {
const char *name;
......@@ -65,17 +64,23 @@ static unsigned parsePermissions(const char *string)
{
assert(string != nullptr);
unsigned permission = 0;
gchar **tokens;
const char *const end = string + strlen(string);
tokens = g_strsplit(string, PERMISSION_SEPERATOR, 0);
for (unsigned i = 0; tokens[i] != NULL; ++i) {
char *temp = tokens[i];
permission |= ParsePermission(temp);
unsigned permission = 0;
while (true) {
const char *comma = std::find(string, end,
PERMISSION_SEPARATOR);
if (comma > string) {
const std::string name(string, comma);
permission |= ParsePermission(name.c_str());
}
if (comma == end)
break;
string = comma + 1;
}
g_strfreev(tokens);
return permission;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment