Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1790)

Unified Diff: third_party/harfbuzz-ng/src/hb-language.c

Issue 6052008: harfbuzz: check in harfbuzz-ng, add gyp define to use it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 9 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/harfbuzz-ng/src/hb-language.h ('k') | third_party/harfbuzz-ng/src/hb-object-private.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/harfbuzz-ng/src/hb-language.c
diff --git a/third_party/harfbuzz-ng/src/hb-language.c b/third_party/harfbuzz-ng/src/hb-language.c
new file mode 100644
index 0000000000000000000000000000000000000000..2aabada8fb5ba1d61fd8cf1b00120f64fc8cbed0
--- /dev/null
+++ b/third_party/harfbuzz-ng/src/hb-language.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2009 Red Hat, Inc.
+ *
+ * This is part of HarfBuzz, a text shaping library.
+ *
+ * Permission is hereby granted, without written agreement and without
+ * license or royalty fees, to use, copy, modify, and distribute this
+ * software and its documentation for any purpose, provided that the
+ * above copyright notice and the following two paragraphs appear in
+ * all copies of this software.
+ *
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
+ * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
+ * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * Red Hat Author(s): Behdad Esfahbod
+ */
+
+#include "hb-private.h"
+
+#include "hb-language.h"
+
+HB_BEGIN_DECLS
+
+
+static const char canon_map[256] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', 0, 0,
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 0, 0, 0, 0, 0, 0,
+ '-', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
+ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0, 0, 0, 0, '-',
+ 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
+ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0, 0, 0, 0, 0
+};
+
+static hb_bool_t
+lang_equal (const void *v1,
+ const void *v2)
+{
+ const unsigned char *p1 = v1;
+ const unsigned char *p2 = v2;
+
+ while (canon_map[*p1] && canon_map[*p1] == canon_map[*p2])
+ {
+ p1++, p2++;
+ }
+
+ return (canon_map[*p1] == canon_map[*p2]);
+}
+
+#if 0
+static unsigned int
+lang_hash (const void *key)
+{
+ const unsigned char *p = key;
+ unsigned int h = 0;
+ while (canon_map[*p])
+ {
+ h = (h << 5) - h + canon_map[*p];
+ p++;
+ }
+
+ return h;
+}
+#endif
+
+
+hb_language_t
+hb_language_from_string (const char *str)
+{
+ static unsigned int num_langs;
+ static unsigned int num_alloced;
+ static const char **langs;
+ unsigned int i;
+ unsigned char *p;
+
+ /* TODO Use a hash table or something */
+
+ if (!str)
+ return NULL;
+
+ for (i = 0; i < num_langs; i++)
+ if (lang_equal (str, langs[i]))
+ return langs[i];
+
+ if (unlikely (num_langs == num_alloced)) {
+ unsigned int new_alloced = 2 * (8 + num_alloced);
+ const char **new_langs = realloc (langs, new_alloced * sizeof (langs[0]));
+ if (!new_langs)
+ return NULL;
+ num_alloced = new_alloced;
+ langs = new_langs;
+ }
+
+ langs[i] = strdup (str);
+ for (p = (unsigned char *) langs[i]; *p; p++)
+ *p = canon_map[*p];
+
+ num_langs++;
+
+ return (hb_language_t) langs[i];
+}
+
+const char *
+hb_language_to_string (hb_language_t language)
+{
+ return (const char *) language;
+}
+
+
+HB_END_DECLS
« no previous file with comments | « third_party/harfbuzz-ng/src/hb-language.h ('k') | third_party/harfbuzz-ng/src/hb-object-private.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698