]> git.deb.at Git - pkg/abook.git/blobdiff - misc.c
multibyte update
[pkg/abook.git] / misc.c
diff --git a/misc.c b/misc.c
index df853bca38674d56851cf349769dfc50ba388a3e..a44c9d2f96a7bfafe721d95120c8c64acfb2cc76 100644 (file)
--- a/misc.c
+++ b/misc.c
 #ifdef HAVE_CONFIG_H
 #      include "config.h"
 #endif
+#ifdef HANDLE_MULTIBYTE
+#      include <wchar.h>
+#      include "mbswidth.h"
+#endif
 #include "misc.h"
 #ifdef ABOOK_SRC
 #      include "abook.h"
@@ -265,6 +269,28 @@ getaline(FILE *f)
        return buf;
 }
 
+int
+strwidth(const char *s)
+{
+       assert(s);
+#ifdef HANDLE_MULTIBYTE
+       return (int)mbswidth(s, 0);
+#else
+       return strlen(s);
+#endif
+}
+
+int
+bytes2width(const char *s, int width)
+{
+       assert(s);
+#ifdef HANDLE_MULTIBYTE
+       return mbsnbytes(s, strlen(s), width, 0);
+#else
+       return width;
+#endif
+}
+
 /**************************************************************
  * Original:
  * Patrick Powell Tue Apr 11 09:48:21 PDT 1995