#include <string.h>
+bool
+IsIncompleteCharMB(const char *s, size_t n)
+{
+ auto mb = std::mbstate_t();
+ const std::size_t length = std::mbrlen(s, n, &mb);
+ return length == std::size_t(-2);
+}
+
std::size_t
CharSizeMB(const char *s, size_t n)
{
#include <cstddef>
+/**
+ * Is the given character incomplete?
+ */
+gcc_pure
+bool
+IsIncompleteCharMB(const char *s, size_t n);
+
/**
* Wrapper for std::mbrlen() which attempts to recover with a best
* effort from invalid or incomplete sequences.
#include <assert.h>
#include <stdlib.h>
#include <string.h>
-#include <glib.h>
#if (defined(HAVE_CURSES_ENHANCED) || defined(ENABLE_MULTIBYTE)) && !defined(_WIN32)
#include <sys/poll.h>
doupdate();
}
-#if (defined(HAVE_CURSES_ENHANCED) || defined(ENABLE_MULTIBYTE)) && !defined(_WIN32)
-static bool
-multibyte_is_complete(const char *p, size_t length)
-{
- char *q = g_locale_to_utf8(p, length,
- nullptr, nullptr, nullptr);
- if (q != nullptr) {
- g_free(q);
- return true;
- } else {
- return false;
- }
-}
-#endif
-
static void
wreadln_insert_byte(struct wreadln *wr, int key)
{
/* wide version: try to complete the multibyte sequence */
while (length < sizeof(buffer)) {
- if (multibyte_is_complete(buffer, length))
+ if (!IsIncompleteCharMB(buffer, length))
/* sequence is complete */
break;