1
/* ipuz-enumeration.h
2
 *
3
 * Copyright 2022 Jonathan Blandford <jrb@gnome.org>
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18
 *
19
 * SPDX-License-Identifier: (LGPL-2.1-or-later OR MIT)
20
 */
21

            
22
#pragma once
23

            
24
#include <glib-object.h>
25

            
26
G_BEGIN_DECLS
27

            
28

            
29
#define DELIM_IS_MODIFIER(d)  (d==IPUZ_DELIMINATOR_ALLCAPS||d==IPUZ_DELIMINATOR_CAPITALIZED||d ==IPUZ_DELIMINATOR_FOREIGN)
30
#define DELIM_IS_SEPARATOR(d) ((guint)d<=IPUZ_DELIMINATOR_APOSTROPHE)
31

            
32
typedef enum _IPuzDeliminator
33
{
34
  IPUZ_DELIMINATOR_WORD_BREAK,
35
  IPUZ_DELIMINATOR_PERIOD,
36
  IPUZ_DELIMINATOR_DASH,
37
  IPUZ_DELIMINATOR_APOSTROPHE,
38

            
39
  /* Word Modifiers */
40
  IPUZ_DELIMINATOR_ALLCAPS,
41
  IPUZ_DELIMINATOR_CAPITALIZED,
42
  IPUZ_DELIMINATOR_FOREIGN,
43
} IPuzDeliminator;
44

            
45
typedef enum _IPuzVerbosity
46
{
47
  IPUZ_VERBOSITY_STANDARD, /* "4,4" */
48
  IPUZ_VERBOSITY_SPARSE,   /* "Two words" */
49
} IPuzVerbosity;
50

            
51

            
52
/* grid_offset indicates what position within the clue the deliminator
53
 * can be found. It includes the borders within its count, as well as
54
 * the cells. For example, consider the enumeration "^4-4 3":
55
 *
56
 * |^| | | - | | | ǁ | | |
57
 *
58
 * We'll call this function with CAPITALIZED at position 1, DASH at
59
 * position 8, and WORD_BREAK at 16 and 22. final_word will be TRUE
60
 * when we get the WORD_BREAK at 22.
61
 *
62
 * Note, this last WORD_BREAK is implicit, and shouldn't be
63
 * rendered. It does help you know how long the final word is, though.
64
 */
65

            
66
typedef void (*IPuzDelimFunc) (IPuzDeliminator delim,
67
                               guint           grid_offset,
68
                               gboolean        final_word,
69
                               gpointer        user_data);
70

            
71
typedef struct _IPuzEnumeration IPuzEnumeration;
72

            
73
#define IPUZ_TYPE_ENUMERATION (ipuz_enumeration_get_type ())
74

            
75

            
76
GType            ipuz_enumeration_get_type      (void);
77
IPuzEnumeration *ipuz_enumeration_new           (const gchar           *src,
78
                                                 IPuzVerbosity          verbosity);
79
IPuzEnumeration *ipuz_enumeration_ref           (IPuzEnumeration       *enumeration);
80
void             ipuz_enumeration_unref         (IPuzEnumeration       *enumeration);
81
gboolean         ipuz_enumeration_equal         (const IPuzEnumeration *enumeration1,
82
                                                 const IPuzEnumeration *enumeration2);
83
gchar           *ipuz_enumeration_get_src       (const IPuzEnumeration *enumeration);
84
gchar           *ipuz_enumeration_get_display   (const IPuzEnumeration *enumeration);
85
gboolean         ipuz_enumeration_get_has_delim (const IPuzEnumeration *enumeration);
86
gint             ipuz_enumeration_delim_length  (const IPuzEnumeration *enumeration);
87
void             ipuz_enumeration_delim_foreach (const IPuzEnumeration *enumeration,
88
                                                 IPuzDelimFunc          func,
89
                                                 gpointer               user_data);
90
gboolean         ipuz_enumeration_valid_char    (gchar                  c);
91

            
92
118
G_DEFINE_AUTOPTR_CLEANUP_FUNC(IPuzEnumeration, ipuz_enumeration_unref)
93

            
94

            
95
G_END_DECLS