Struct

IpuzCharsetBuilder

Description [src]

struct IpuzCharsetBuilder {
  /* No available fields */
}

An opaque data structure used to dynamically build an IpuzCharset.

This structure keeps track of the number of times a given unicode character is added or removed from it. Once that process is done, it can be converted to a IpuzCharset.

The main reason for the split between the builder and the charset is for performance: certain operations involving charsets are performance critical, and having them immutable helps with that.

Example:

IpuzCharsetBuilder *builder;
g_autoptr (IpuzCharset) charset = NULL;

builder = ipuz_charset_builder_new ();
ipuz_charset_builder_add_text (builder, "STAR");
ipuz_charset_builder_add_text (builder, "CARET");
ipuz_charset_builder_add_text (builder, "HASH");
ipuz_charset_builder_add_text (builder, "BRACE");

// builder is consumed by this, and thus doesn't need freeing
charset = ipuz_charset_builder_build (builder);
g_assert_cmpint (ipuz_charset_get_count (charset, g_utf8_get_char ("A")),
                 ==,
                 4);

Note

Calling ipuz_charset_builder_build() will free the builder while returning a new IpuzCharset. As a result, there is almost never a need to explicitly free a builder unless it’s unused.

Constructors

ipuz_charset_builder_new

Returns an empty builder for a character set. Use ipuz_charset_builder_add_text() to populate it. Once it’s populated, use ipuz_charset_builder_build() to create a charset.

ipuz_charset_builder_new_for_language

Creates a charset builder with a list of all characters in common use in crosswords for langs alphabet. lang should be a country code, but can be a fully-qualified locale (such as from the $LANG environment variable). In that instance the remainder of the string is ignored, as we don’t consider regional distinctions when determining a default alphabet.

ipuz_charset_builder_new_from_text

Returns an IpuzCharsetBuilder prepopulated with the characters from text.

Instance methods

ipuz_charset_builder_add_text

Adds each unicode code point from text into self.

ipuz_charset_builder_build

Consumes self and frees it, returning an immutable IpuzCharset in the process.

ipuz_charset_builder_copy

Makes a copy of self.

ipuz_charset_builder_remove_character

Tries to remove one instance of c from self, i.e., decrease its character count by one. If c is not present in the self, this function returns FALSE and leaves self unchanged.

ipuz_charset_builder_remove_text

Tries to remove all the characters in text from self, i.e. decrease their character counts by as many instances of each character there are in text. If text contains characters that are not already in the self, or if text contains more of a certain character than self already has, this function returns FALSE and leaves self unchanged.

ipuz_charset_builder_set_char_count

Explicitly sets the count of c to be count in self.