Add hb_string_t
authorBehdad Esfahbod <behdad@behdad.org>
Mon, 30 Oct 2017 17:42:28 +0000 (11:42 -0600)
committerBehdad Esfahbod <behdad@behdad.org>
Mon, 30 Oct 2017 17:42:28 +0000 (11:42 -0600)
src/hb-ot-post-table.hh
src/hb-private.hh

index 275988e38a69468ea33db3ee7abf8f6faf438cee..090d3ccbe3fca7c9ee9ec5d505895c18a75f39d4 100644 (file)
@@ -110,48 +110,39 @@ struct post
       index_to_offset.finish ();
     }
 
-    struct str_t
-    {
-      inline str_t (void) : bytes (nullptr), len (0) {}
-      inline str_t (const char *bytes_, unsigned int len_) : bytes (bytes_), len (len_) {}
-
-      const char *bytes;
-      unsigned int len;
-    };
-
-    inline str_t _find_glyph_name (hb_codepoint_t glyph) const
+    inline hb_string_t _find_glyph_name (hb_codepoint_t glyph) const
     {
       if (version == 0x00010000)
       {
        if (glyph >= NUM_FORMAT1_NAMES)
-         return str_t ();
+         return hb_string_t ();
 
-       return str_t (format1_names (glyph), strlen (format1_names (glyph)));
+       return hb_string_t (format1_names (glyph), strlen (format1_names (glyph)));
       }
 
       if (version != 0x00020000 || glyph >= glyphNameIndex->len)
-       return str_t ();
+       return hb_string_t ();
 
       unsigned int index = glyphNameIndex->array[glyph];
       if (index < NUM_FORMAT1_NAMES)
-       return str_t (format1_names (index), strlen (format1_names (index)));
+       return hb_string_t (format1_names (index), strlen (format1_names (index)));
       index -= NUM_FORMAT1_NAMES;
 
       if (index >= index_to_offset.len)
-       return str_t ();
+       return hb_string_t ();
       unsigned int offset = index_to_offset.array[index];
 
       const uint8_t *data = pool + offset;
       unsigned int name_length = *data;
       data++;
 
-      return str_t ((const char *) data, name_length);
+      return hb_string_t ((const char *) data, name_length);
     }
 
     inline bool get_glyph_name (hb_codepoint_t glyph,
                                char *buf, unsigned int buf_len) const
     {
-      str_t s = _find_glyph_name (glyph);
+      hb_string_t s = _find_glyph_name (glyph);
       if (!s.len)
         return false;
       if (!buf_len)
index f6dbbe21f2a10f9ed4a9351cc5b1272e427bf1f5..b88de08d1d7e54f561373ef6653978ad1b1cdaa1 100644 (file)
@@ -1137,4 +1137,31 @@ hb_options (void)
 /* Size signifying variable-sized array */
 #define VAR 1
 
+
+/* String type. */
+
+struct hb_string_t
+{
+  inline hb_string_t (void) : bytes (nullptr), len (0) {}
+  inline hb_string_t (const char *bytes_, unsigned int len_) : bytes (bytes_), len (len_) {}
+
+  inline int cmp (const hb_string_t *a) const
+  {
+    if (len != a->len)
+      return (int) a->len - (int) len;
+
+    return memcmp (a->bytes, bytes, len);
+  }
+  static inline int cmp (const void *pa, const void *pb)
+  {
+    hb_string_t *a = (hb_string_t *) pa;
+    hb_string_t *b = (hb_string_t *) pb;
+    return b->cmp (a);
+  }
+
+  const char *bytes;
+  unsigned int len;
+};
+
+
 #endif /* HB_PRIVATE_HH */