summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9a0647e)
raw | patch | inline | side by side (parent: 9a0647e)
author | Max Kellermann <max@duempel.org> | |
Mon, 19 Oct 2009 06:18:43 +0000 (08:18 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Mon, 19 Oct 2009 06:18:43 +0000 (08:18 +0200) |
These functions are a shortcut for a common use case: convert an
allocated string in-place.
allocated string in-place.
src/charset.c | patch | blob | history | |
src/charset.h | patch | blob | history | |
src/wreadln.c | patch | blob | history |
diff --git a/src/charset.c b/src/charset.c
index 85cb89141a1ceb05447859fcee417281c6ca796e..59d1a26df3173acbc466024855c88b75c72cfe03 100644 (file)
--- a/src/charset.c
+++ b/src/charset.c
return g_strdup(localestr);
#endif
}
+
+char *
+replace_utf8_to_locale(char *src)
+{
+#ifdef ENABLE_LOCALE
+ assert(src != NULL);
+
+ if (noconvert)
+ return src;
+
+ return utf8_to_locale(src);
+#else
+ return src;
+#endif
+}
+
+
+char *
+replace_locale_to_utf8(char *src)
+{
+#ifdef ENABLE_LOCALE
+ assert(src != NULL);
+
+ if (noconvert)
+ return src;
+
+ return locale_to_utf8(src);
+#else
+ return src;
+#endif
+}
diff --git a/src/charset.h b/src/charset.h
index d1b3f75e3676e9d87ae87e15942bf35ffd78b3e0..a08054b70be361c8c0b5cdbb2613320f7b53c72b 100644 (file)
--- a/src/charset.h
+++ b/src/charset.h
char *utf8_to_locale(const char *str);
char *locale_to_utf8(const char *str);
+/**
+ * Converts the UTF-8 string to the locale, and frees the source
+ * pointer. Returns the source pointer as-is if no conversion is
+ * required.
+ */
+char *
+replace_utf8_to_locale(char *src);
+
+/**
+ * Converts the locale string to UTF-8, and frees the source pointer.
+ * Returns the source pointer as-is if no conversion is required.
+ */
+char *
+replace_locale_to_utf8(char *src);
+
#endif
diff --git a/src/wreadln.c b/src/wreadln.c
index ad1047fd5cc001365a886264958710190b390379..66a1f1c2f5f72464fe7c48c5de84aae83c9c2bbb 100644 (file)
--- a/src/wreadln.c
+++ b/src/wreadln.c
dup = g_strdup(data);
dup[x] = 0;
- p = locale_to_utf8(dup);
- g_free(dup);
+ p = replace_locale_to_utf8(dup);
width = utf8_width(p);
g_free(p);