glib_compat.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Discord plugin for libpurple
  3. * Copyright (C) 2016-2017 Eion Robb
  4. * Copyright (C) 2017 Alyssa Rosenzweig
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #include <glib.h>
  20. #if !GLIB_CHECK_VERSION(2, 32, 0)
  21. #define g_hash_table_contains(hash_table, key) g_hash_table_lookup_extended(hash_table, key, NULL, NULL)
  22. #endif /* 2.32.0 */
  23. static gboolean
  24. g_str_insensitive_equal(gconstpointer v1, gconstpointer v2)
  25. {
  26. return (g_ascii_strcasecmp(v1, v2) == 0);
  27. }
  28. static guint
  29. g_str_insensitive_hash(gconstpointer v)
  30. {
  31. guint hash;
  32. gchar *lower_str = g_ascii_strdown(v, -1);
  33. hash = g_str_hash(lower_str);
  34. g_free(lower_str);
  35. return hash;
  36. }