summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 40f162b)
raw | patch | inline | side by side (parent: 40f162b)
author | Junio C Hamano <gitster@pobox.com> | |
Mon, 7 Jan 2008 03:02:22 +0000 (19:02 -0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 7 Jan 2008 04:27:35 +0000 (20:27 -0800) |
utf8_width() function was doing two different things. To pick a
valid character from UTF-8 stream, and compute the display width of
that character. This splits the former to a separate function
pick_one_utf8_char().
Signed-off-by: Junio C Hamano <gitster@pobox.com>
valid character from UTF-8 stream, and compute the display width of
that character. This splits the former to a separate function
pick_one_utf8_char().
Signed-off-by: Junio C Hamano <gitster@pobox.com>
utf8.c | patch | blob | history | |
utf8.h | patch | blob | history |
index 9efcdb9c09970127ebe37923879274b95efd526c..24d2ec696afac26c2b5e31c0994025005837470d 100644 (file)
--- a/utf8.c
+++ b/utf8.c
/* This code is originally from http://www.cl.cam.ac.uk/~mgk25/ucs/ */
-typedef unsigned int ucs_char_t; /* assuming 32bit int */
-
struct interval {
int first;
int last;
}
/*
- * This function returns the number of columns occupied by the character
- * pointed to by the variable start. The pointer is updated to point at
- * the next character. If it was not valid UTF-8, the pointer is set to NULL.
+ * Pick one ucs character starting from the location *start points at,
+ * and return it, while updating the *start pointer to point at the
+ * end of that character.
+ *
+ * If the string was not a valid UTF-8, *start pointer is set to NULL
+ * and the return value is undefined.
*/
-int utf8_width(const char **start)
+ucs_char_t pick_one_utf8_char(const char **start)
{
unsigned char *s = (unsigned char *)*start;
ucs_char_t ch;
return 0;
}
+ return ch;
+}
+
+/*
+ * This function returns the number of columns occupied by the character
+ * pointed to by the variable start. The pointer is updated to point at
+ * the next character. If it was not valid UTF-8, the pointer is set to
+ * NULL.
+ */
+int utf8_width(const char **start)
+{
+ ucs_char_t ch = pick_one_utf8_char(start);
+ if (!*start)
+ return 0;
return git_wcwidth(ch);
}
index 15db6f1f27ef7a1f056d5b6adca901f092036f82..4a7f0464c4321864f96eb9ce96eaccfead3ad935 100644 (file)
--- a/utf8.h
+++ b/utf8.h
#ifndef GIT_UTF8_H
#define GIT_UTF8_H
+typedef unsigned int ucs_char_t; /* assuming 32bit int */
+
+ucs_char_t pick_one_utf8_char(const char **start);
int utf8_width(const char **start);
int is_utf8(const char *text);
int is_encoding_utf8(const char *name);