unsigned int
utf8_hash_case_string (const char *s, unsigned int basis)
{
- return utf8_hash_case_bytes (s, strlen (s), basis);
+ return utf8_hash_case_substring (ss_cstr (s), basis);
+}
+
+/* Returns a hash value for UTF-8 string S, with lowercase and uppercase
+ letters treated as equal, starting from BASIS. */
+unsigned int
+utf8_hash_case_substring (struct substring s, unsigned int basis)
+{
+ return utf8_hash_case_bytes (s.string, s.length, basis);
}
/* Compares UTF-8 strings A and B case-insensitively.
int
utf8_strcasecmp (const char *a, const char *b)
{
- return utf8_strncasecmp (a, strlen (a), b, strlen (b));
+ return utf8_sscasecmp (ss_cstr (a), ss_cstr (b));
+}
+
+int
+utf8_sscasecmp (struct substring a, struct substring b)
+{
+ return utf8_strncasecmp (a.string, a.length, b.string, b.length);
}
/* Compares UTF-8 strings A (with length AN) and B (with length BN)
#define I18N_H
#include "libpspp/compiler.h"
+#include "libpspp/str.h"
#include <stdbool.h>
#include <unistr.h>
unsigned int utf8_hash_case_bytes (const char *, size_t n, unsigned int basis) WARN_UNUSED_RESULT;
unsigned int utf8_hash_case_string (const char *, unsigned int basis) WARN_UNUSED_RESULT;
+unsigned int utf8_hash_case_substring (struct substring, unsigned int basis)
+ WARN_UNUSED_RESULT;
int utf8_strcasecmp (const char *, const char *);
+int utf8_sscasecmp (struct substring, struct substring);
int utf8_strncasecmp (const char *, size_t, const char *, size_t);
int utf8_strverscasecmp (const char *, const char *);
char *utf8_to_upper (const char *);
#include <string.h>
#include "libpspp/array.h"
+#include "libpspp/i18n.h"
#include "libpspp/str.h"
#include "gl/xalloc.h"
sa->n = n;
}
+/* Returns true if A and B contain the same strings in the same order,
+ false otherwise. */
+bool
+string_array_equal (const struct string_array *a,
+ const struct string_array *b)
+{
+ if (a->n != b->n)
+ return false;
+
+ for (size_t i = 0; i < a->n; i++)
+ if (strcmp (a->strings[i], b->strings[i]))
+ return false;
+ return true;
+}
+
+/* Returns true if A and B contain the same strings in the same order,
+ false otherwise. */
+bool
+string_array_equal_case (const struct string_array *a,
+ const struct string_array *b)
+{
+ if (a->n != b->n)
+ return false;
+
+ for (size_t i = 0; i < a->n; i++)
+ if (utf8_strcasecmp (a->strings[i], b->strings[i]))
+ return false;
+ return true;
+}
+
/* Divides STRING into tokens at DELIMITERS and adds each token to SA. */
void
string_array_parse (struct string_array *sa, struct substring string,
void string_array_sort (struct string_array *);
void string_array_uniq (struct string_array *);
+bool string_array_equal (const struct string_array *,
+ const struct string_array *);
+bool string_array_equal_case (const struct string_array *,
+ const struct string_array *);
+
void string_array_parse (struct string_array *, struct substring string,
struct substring delimiters);
char *string_array_join (const struct string_array *, const char *separator);