b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher Stephen Gallagher <sgallagh@redhat.com>
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher Copyright (C) 2011 Red Hat
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher This program is free software; you can redistribute it and/or modify
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher it under the terms of the GNU General Public License as published by
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher the Free Software Foundation; either version 3 of the License, or
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher (at your option) any later version.
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher This program is distributed in the hope that it will be useful,
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher but WITHOUT ANY WARRANTY; without even the implied warranty of
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher GNU General Public License for more details.
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher You should have received a copy of the GNU General Public License
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher along with this program. If not, see <http://www.gnu.org/licenses/>.
dbea04f585a30d001b574317c068cd03a4fa332bJakub Hrozekuint8_t *sss_utf8_tolower(const uint8_t *s, size_t len, size_t *_nlen)
dbea04f585a30d001b574317c068cd03a4fa332bJakub Hrozek lower = u8_tolower(s, len, NULL, NULL, NULL, &llen);
dbea04f585a30d001b574317c068cd03a4fa332bJakub Hrozekuint8_t *sss_utf8_tolower(const uint8_t *s, size_t len, size_t *_nlen)
dbea04f585a30d001b574317c068cd03a4fa332bJakub Hrozek glower = g_utf8_strdown((const gchar *) s, len);
dbea04f585a30d001b574317c068cd03a4fa332bJakub Hrozek /* strlen() is safe here because g_utf8_strdown() always null-terminates */
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagherbool sss_utf8_check(const uint8_t *s, size_t n)
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagherbool sss_utf8_check(const uint8_t *s, size_t n)
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher return g_utf8_validate((const gchar *)s, n, NULL);
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher/* Returns EOK on match, ENOTUNIQ if comparison succeeds but
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher * does not match.
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher * May return other errno error codes on failure
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallaghererrno_t sss_utf8_case_eq(const uint8_t *s1, const uint8_t *s2)
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher /* Do a case-insensitive comparison.
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher * The input must be encoded in UTF8.
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher * We have no way of knowing the language,
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher * so we'll pass NULL for the language and
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher * hope for the best.
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher /* An error occurred */
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallaghererrno_t sss_utf8_case_eq(const uint8_t *s1, const uint8_t *s2)
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher n1 = g_utf8_strlen((const gchar *)s1, -1);
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher n2 = g_utf8_strlen((const gchar *)s2, -1);
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher gs1 = g_utf8_casefold((const gchar *)s1, n1);
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher gs2 = g_utf8_casefold((const gchar *)s2, n2);
2b4332767d299263a288e0a74bbfbc9de674de95Jakub Hrozekbool sss_string_equal(bool cs, const char *s1, const char *s2)
2b4332767d299263a288e0a74bbfbc9de674de95Jakub Hrozek return sss_utf8_case_eq((const uint8_t *)s1, (const uint8_t *)s2) == EOK;