Permission: use std::find instead of g_strsplit()
This commit is contained in:
parent
daa47546c7
commit
9acc1e1e97
@ -24,16 +24,15 @@
|
|||||||
#include "ConfigOption.hxx"
|
#include "ConfigOption.hxx"
|
||||||
#include "system/FatalError.hxx"
|
#include "system/FatalError.hxx"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <glib.h>
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static constexpr char PERMISSION_PASSWORD_CHAR = '@';
|
static constexpr char PERMISSION_PASSWORD_CHAR = '@';
|
||||||
#define PERMISSION_SEPERATOR ","
|
static constexpr char PERMISSION_SEPARATOR = ',';
|
||||||
|
|
||||||
static constexpr struct {
|
static constexpr struct {
|
||||||
const char *name;
|
const char *name;
|
||||||
@ -65,16 +64,22 @@ static unsigned parsePermissions(const char *string)
|
|||||||
{
|
{
|
||||||
assert(string != nullptr);
|
assert(string != nullptr);
|
||||||
|
|
||||||
unsigned permission = 0;
|
const char *const end = string + strlen(string);
|
||||||
gchar **tokens;
|
|
||||||
|
|
||||||
tokens = g_strsplit(string, PERMISSION_SEPERATOR, 0);
|
unsigned permission = 0;
|
||||||
for (unsigned i = 0; tokens[i] != NULL; ++i) {
|
while (true) {
|
||||||
char *temp = tokens[i];
|
const char *comma = std::find(string, end,
|
||||||
permission |= ParsePermission(temp);
|
PERMISSION_SEPARATOR);
|
||||||
|
if (comma > string) {
|
||||||
|
const std::string name(string, comma);
|
||||||
|
permission |= ParsePermission(name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
g_strfreev(tokens);
|
if (comma == end)
|
||||||
|
break;
|
||||||
|
|
||||||
|
string = comma + 1;
|
||||||
|
}
|
||||||
|
|
||||||
return permission;
|
return permission;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user