20ase_gettext (
const String &untranslated)
22 CString translated = untranslated;
23 return translated.c_str();
28now_strftime (
const String &format)
31 char buffer[4096] = { 0, };
49 if (word.
empty())
return true;
52 warning (
"%s: invalid icon keyword: '%s'", __func__, word);
59 if (!is.empty() && is.find (
',') == is.npos)
66operator""_icon (
const char *key,
size_t)
80 warning (
"%s: invalid icon unicode: '%s'", __func__, unicode);
88operator""_uc (
const char *key,
size_t)
99 warning (
"%s: invalid svg icon: %s…", __func__, svgdata.
substr (0, 40));
117 ASE_UNUSED
long nflags;
118#ifdef HAVE_SYS_EVENTFD_H
120 fds[0] = eventfd (0 , EFD_CLOEXEC | EFD_NONBLOCK);
125 err = pipe2 (fds, O_CLOEXEC | O_NONBLOCK);
129 nflags =
fcntl (fds[1], F_GETFL, 0);
131 nflags =
fcntl (fds[1], F_GETFD, 0);
137 nflags =
fcntl (fds[0], F_GETFL, 0);
139 nflags =
fcntl (fds[0], F_GETFD, 0);
161 struct pollfd pfd = {
inputfd(), POLLIN, 0 };
164 presult =
poll (&pfd, 1, -1);
166 return pfd.revents != 0;
173#ifdef HAVE_SYS_EVENTFD_H
175 err = eventfd_write (fds[0], 1);
180 err =
write (fds[1], &w, 1);
190#ifdef HAVE_SYS_EVENTFD_H
193 err = eventfd_read (fds[0], &bytes8);
198 err =
read (fds[0], buffer,
sizeof (buffer));
199 while (err == 512 || (err < 0 &&
errno ==
EINTR));
206#ifdef HAVE_SYS_EVENTFD_H
217CustomDataContainer::CustomDataEntry&
218CustomDataContainer::custom_data_entry (VirtualBase *key)
223 for (
auto &e : *custom_data_)
226 custom_data_->push_back ({ .key = key, });
227 return custom_data_->back();
231CustomDataContainer::custom_data_get (VirtualBase *key)
const
234 for (
auto &e : *custom_data_)
242CustomDataContainer::custom_data_del (VirtualBase *key)
245 return Aux::erase_first (*custom_data_, [key] (
auto &e) {
return key == e.key; });
247 static_assert (
sizeof (CustomDataContainer) ==
sizeof (
void*));
251CustomDataContainer::custom_data_destroy()
254 while (!custom_data_->empty())
258 custom_data_->pop_back();
263CustomDataContainer::~CustomDataContainer()
265 custom_data_destroy();
279 TASSERT (uint16_swap_le_be (0x1234) == 0x3412);
280 TASSERT (uint32_swap_le_be (0xe23456f8) == 0xf85634e2);
281 TASSERT (uint64_swap_le_be (0xf2345678a1b2c3d4) == 0xd4c3b2a1785634f2);
284 b = Aux::contains (fv, [] (
auto v) {
return v == 9; });
TASSERT (b ==
false);
285 b = Aux::contains (fv, [] (
auto v) {
return v == 2; });
TASSERT (b ==
true);
287 j = Aux::erase_all (fv, [] (
auto v) {
return fabs (v) == 2; });
289 j = Aux::erase_first (fv, [] (
auto v) {
return fabs (v) == 1; });
bool opened()
Indicates whether eventfd has been opened.
void flush()
Clear pending wakeups.
int inputfd()
Returns the file descriptor for POLLIN.
bool pollin()
Checks whether events are pending.
int open()
Opens the eventfd and returns -errno.
void wakeup()
Wakeup polling end.
#define assert_return(expr,...)
Return from the current function if expr is unmet and issue an assertion warning.
#define return_unless(cond,...)
Return silently if cond does not evaluate to true with return value ...
#define TEST_INTEGRITY(FUNC)
Register func as an integrity test.
size_t erase_all(C &container, const std::function< bool(typename C::value_type const &value)> &pred)
Erase all elements for which pred() is true in vector or list.
size_t erase_first(C &container, const std::function< bool(typename C::value_type const &value)> &pred)
Erase first element for which pred() is true in vector or list.
The Anklang C++ API namespace.
String string_join(const String &junctor, const StringS &strvec)
Join a number of strings.
bool string_is_canonified(const String &string, const String &valid_chars)
Check if string_canonify() would modify string.
size_t utf8_to_unicode(const char *str, uint32_t *codepoints)
Convert valid UTF-8 sequences to Unicode codepoints, invalid sequences are treated as Latin-1 charact...
constexpr bool unicode_is_character(uint32_t u)
Return whether u is not one of the 66 Unicode noncharacters.
const String & string_set_ascii_alnum()
Returns a string containing all of 0-9, A-Z and a-z.
StringS string_split_any(const String &string, const String &splitchars, size_t maxn)
Split a string, using any of the splitchars as delimiter.
std::string String
Convenience alias for std::string.
bool string_startswith(const String &string, const String &fragment)
Returns whether string starts with fragment.
#define TASSERT(cond)
Unconditional test assertion, enters breakpoint if not fullfilled.
IconString SvgIcon(const String &svgdata)
Create an IconString consisting of an SVG string.
IconString UcIcon(const String &unicode)
Create an IconString consisting of a single/double unicode character.
IconString KwIcon(const String &keywords)
Create an IconString consisting of keywords.