2 * Copyright © 2017 Google, Inc.
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 * Google Author(s): Behdad Esfahbod
27 #ifndef HB_STRING_ARRAY_HH
28 #if 0 /* Make checks happy. */
29 #define HB_STRING_ARRAY_HH
32 #include "hb-private.hh"
34 /* Based on Bruno Haible's code in Appendix B of Ulrich Drepper's dsohowto.pdf:
35 * https://software.intel.com/sites/default/files/m/a/1/e/dsohowto.pdf */
37 #define HB_STRING_ARRAY_TYPE_NAME HB_PASTE(HB_STRING_ARRAY_NAME, _msgstr_t)
38 #define HB_STRING_ARRAY_POOL_NAME HB_PASTE(HB_STRING_ARRAY_NAME, _msgstr)
39 #define HB_STRING_ARRAY_OFFS_NAME HB_PASTE(HB_STRING_ARRAY_NAME, _msgidx)
41 static const union HB_STRING_ARRAY_TYPE_NAME {
43 /* I like to avoid storing the nul-termination byte since we don't need it,
44 * but C++ does not allow that.
45 * https://stackoverflow.com/questions/28433862/why-initializer-string-for-array-of-chars-is-too-long-compiles-fine-in-c-not
47 #define _S(s) char HB_PASTE (str, __LINE__)[sizeof (s)];
48 #include HB_STRING_ARRAY_LIST
53 HB_STRING_ARRAY_POOL_NAME =
57 #include HB_STRING_ARRAY_LIST
61 static const unsigned int HB_STRING_ARRAY_OFFS_NAME[] =
63 #define _S(s) offsetof (union HB_STRING_ARRAY_TYPE_NAME, st.HB_PASTE(str, __LINE__)),
64 #include HB_STRING_ARRAY_LIST
66 sizeof (HB_STRING_ARRAY_TYPE_NAME)
69 static inline hb_string_t
70 HB_STRING_ARRAY_NAME (unsigned int i)
72 assert (i < ARRAY_LENGTH (HB_STRING_ARRAY_OFFS_NAME) - 1);
73 return hb_string_t (HB_STRING_ARRAY_POOL_NAME.str + HB_STRING_ARRAY_OFFS_NAME[i],
74 HB_STRING_ARRAY_OFFS_NAME[i + 1] - HB_STRING_ARRAY_OFFS_NAME[i] - 1);
77 #undef HB_STRING_ARRAY_TYPE_NAME
78 #undef HB_STRING_ARRAY_POOL_NAME
79 #undef HB_STRING_ARRAY_OFFS_NAME
81 #endif /* HB_STRING_ARRAY_HH */