GSetting 路径名有什么限制?
What are the restrictions on GSetting path names?
我在 GSettings 文档中读到:
Key names are restricted to lowercase characters, numbers and '-'. Furthermore, the names must begin with a lowercase character, must not end with a '-', and must not contain consecutive dashes
但是没有关于路径名的注释,其他不包括连续的斜杠 (/
)。我的用例是为基于设备的设置生成子目录(从可重定位模式),我想知道我是否应该清理任何字符的字符串。
路径名有条注释,且完整:
Paths must start with and end with a forward slash character ('/') and must not contain two sequential slash characters. Paths should be chosen based on a domain name associated with the program or library to which the settings belong. Examples of paths are "/org/gtk/settings/file-chooser/" and "/ca/desrt/dconf-editor/". Paths should not start with "/apps/", "/desktop/" or "/system/" as they often did in GConf.
(来自 the documentation)。
验证它们的代码如下:
static gboolean
path_is_valid (const gchar *path)
{
if (!path)
return FALSE;
if (path[0] != '/')
return FALSE;
if (!g_str_has_suffix (path, "/"))
return FALSE;
return strstr (path, "//") == NULL;
}
(来自 gsettings.c)。
所以文档是完整的——它提到了代码检查的所有内容。
根据您的设备的识别方式,您可能确实想要进行一些转义或清理以删除斜杠,以防万一您最终会遇到连续的斜杠。除此之外,如果需要,您只需要清理一些东西,使它们易于阅读和调试。
我在 GSettings 文档中读到:
Key names are restricted to lowercase characters, numbers and '-'. Furthermore, the names must begin with a lowercase character, must not end with a '-', and must not contain consecutive dashes
但是没有关于路径名的注释,其他不包括连续的斜杠 (/
)。我的用例是为基于设备的设置生成子目录(从可重定位模式),我想知道我是否应该清理任何字符的字符串。
路径名有条注释,且完整:
Paths must start with and end with a forward slash character ('/') and must not contain two sequential slash characters. Paths should be chosen based on a domain name associated with the program or library to which the settings belong. Examples of paths are "/org/gtk/settings/file-chooser/" and "/ca/desrt/dconf-editor/". Paths should not start with "/apps/", "/desktop/" or "/system/" as they often did in GConf.
(来自 the documentation)。
验证它们的代码如下:
static gboolean
path_is_valid (const gchar *path)
{
if (!path)
return FALSE;
if (path[0] != '/')
return FALSE;
if (!g_str_has_suffix (path, "/"))
return FALSE;
return strstr (path, "//") == NULL;
}
(来自 gsettings.c)。
所以文档是完整的——它提到了代码检查的所有内容。
根据您的设备的识别方式,您可能确实想要进行一些转义或清理以删除斜杠,以防万一您最终会遇到连续的斜杠。除此之外,如果需要,您只需要清理一些东西,使它们易于阅读和调试。