1/*
2 * Copyright © 2017 Google, Inc.
3 *
4 * This is part of HarfBuzz, a text shaping library.
5 *
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.
11 *
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
16 * DAMAGE.
17 *
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.
23 *
24 * Google Author(s): Behdad Esfahbod
25 */
26
27#ifndef HB_STRING_ARRAY_HH
28#if 0 /* Make checks happy. */
29#define HB_STRING_ARRAY_HH
30#endif
31
32#include "hb.hh"
33
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 */
36
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)
40
41static const union HB_STRING_ARRAY_TYPE_NAME {
42 struct {
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/q/28433862
46 */
47#define _S(s) char HB_PASTE (str, __LINE__)[sizeof (s)];
48#include HB_STRING_ARRAY_LIST
49#undef _S
50 } st;
51 char str[VAR];
52}
53HB_STRING_ARRAY_POOL_NAME =
54{
55 {
56#define _S(s) s,
57#include HB_STRING_ARRAY_LIST
58#undef _S
59 }
60};
61static const unsigned int HB_STRING_ARRAY_OFFS_NAME[] =
62{
63#define _S(s) offsetof (union HB_STRING_ARRAY_TYPE_NAME, st.HB_PASTE(str, __LINE__)),
64#include HB_STRING_ARRAY_LIST
65#undef _S
66 sizeof (HB_STRING_ARRAY_TYPE_NAME)
67};
68
69static inline hb_bytes_t
70HB_STRING_ARRAY_NAME (unsigned int i)
71{
72 assert (i < ARRAY_LENGTH (HB_STRING_ARRAY_OFFS_NAME) - 1);
73 return hb_bytes_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);
75}
76
77#undef HB_STRING_ARRAY_TYPE_NAME
78#undef HB_STRING_ARRAY_POOL_NAME
79#undef HB_STRING_ARRAY_OFFS_NAME
80
81#endif /* HB_STRING_ARRAY_HH */
82