summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b693269)
raw | patch | inline | side by side (parent: b693269)
author | Max Kellermann <max@duempel.org> | |
Thu, 2 Oct 2008 17:01:02 +0000 (19:01 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Thu, 2 Oct 2008 17:01:02 +0000 (19:01 +0200) |
my_strlen() is a bad name for the function, since the return value is
not a length, but a visible width on the screen. Rename it to
utf8_width() and change its return type to "unsigned".
not a length, but a visible width on the screen. Rename it to
utf8_width() and change its return type to "unsigned".
src/charset.c | patch | blob | history | |
src/charset.h | patch | blob | history | |
src/list_window.c | patch | blob | history | |
src/screen.c | patch | blob | history | |
src/support.c | patch | blob | history | |
src/wreadln.c | patch | blob | history |
diff --git a/src/charset.c b/src/charset.c
index 41269f38bbac685fae237b47f9debb9ac5c9bbbd..aaec39c72c8a16e6772df16e3a41eef81a93a0e6 100644 (file)
--- a/src/charset.c
+++ b/src/charset.c
noconvert = disable;
}
-size_t
-my_strlen(const char *str)
+unsigned
+utf8_width(const char *str)
{
assert(str != NULL);
if (g_utf8_validate(str, -1, NULL)) {
size_t len = g_utf8_strlen(str, -1);
- size_t width = 0;
+ unsigned width = 0;
gunichar c;
while (len--) {
diff --git a/src/charset.h b/src/charset.h
index 11993771024b60177f6a9dc3773585c9a0355c57..24f7ef6322e019adc0b737679a57507db91196f3 100644 (file)
--- a/src/charset.h
+++ b/src/charset.h
/**
* Returns the number of terminal cells occupied by this string.
*/
-size_t my_strlen(const char *str);
+unsigned
+utf8_width(const char *str);
char *utf8_to_locale(const char *str);
char *locale_to_utf8(const char *str);
diff --git a/src/list_window.c b/src/list_window.c
index 001b606fc814fe7aac68316662dd1c3749d0e4f0..93bed86667db070332e3da3bb344dca1b28fa57e 100644 (file)
--- a/src/list_window.c
+++ b/src/list_window.c
if (label) {
int selected = lw->start + i == lw->selected;
- size_t len = my_strlen(label);
+ unsigned len = utf8_width(label);
if (highlight)
colors_use(lw->w, COLOR_LIST_BOLD);
diff --git a/src/screen.c b/src/screen.c
index 8e6ddefde4d89914588942cb48f90463914fd5b5..87d7388254c8ddb8daa1463002749e325aee3e8f 100644 (file)
--- a/src/screen.c
+++ b/src/screen.c
g_snprintf(buf, 32, _(" Volume %d%%"), c->status->volume);
}
colors_use(w, COLOR_TITLE);
- mvwaddstr(w, 0, screen.top_window.cols-my_strlen(buf), buf);
+ mvwaddstr(w, 0, screen.top_window.cols - utf8_width(buf), buf);
flags[0] = 0;
if (c->status != NULL) {
paint_top_window(const char *header, mpdclient_t *c, int full_repaint)
{
static int prev_volume = -1;
- static size_t prev_header_len = -1;
+ static unsigned prev_header_len = -1;
WINDOW *w = screen.top_window.w;
- if (prev_header_len!=my_strlen(header)) {
- prev_header_len = my_strlen(header);
+ if (prev_header_len != utf8_width(header)) {
+ prev_header_len = utf8_width(header);
full_repaint = 1;
}
if (str) {
waddstr(w, str);
- x += my_strlen(str)+1;
+ x += utf8_width(str) + 1;
}
/* create time string */
if (status != NULL && (IS_PLAYING(status->state) ||
IS_PAUSED(status->state))) {
char songname[MAX_SONGNAME_LENGTH];
- int width = COLS-x-my_strlen(screen.buf);
+ int width = COLS - x - utf8_width(screen.buf);
if (song)
strfsong(songname, MAX_SONGNAME_LENGTH,
colors_use(w, COLOR_STATUS);
/* scroll if the song name is to long */
- if (options.scroll && my_strlen(songname) > (size_t)width) {
+ if (options.scroll && utf8_width(songname) > (unsigned)width) {
static scroll_state_t st = { 0, 0 };
char *tmp = strscroll(songname, options.scroll_sep, width, &st);
diff --git a/src/support.c b/src/support.c
index ebbff7348d10c409af5b2ba51d8b7aab5f7359c6..3f30671f9758d25d52c1bb91a09b39c4300fdc82 100644 (file)
--- a/src/support.c
+++ b/src/support.c
tmp = g_malloc(size);
g_strlcpy(tmp, str, size);
g_strlcat(tmp, separator, size);
- len = my_strlen(tmp);
+ len = utf8_width(tmp);
if (st->offset >= len)
st->offset = 0;
diff --git a/src/wreadln.c b/src/wreadln.c
index 840b73ba004e3f72074fca35dfad8b45e5988e00..d01cfcb87c8517544c930cc5a86b9b8ba1440af2 100644 (file)
--- a/src/wreadln.c
+++ b/src/wreadln.c
/* clear input area */
whline(w, ' ', width);
/* print visible part of the line buffer */
- if(masked == TRUE) whline(w, '*', my_strlen(line)-start);
+ if(masked == TRUE) whline(w, '*', utf8_width(line) - start);
else waddnstr(w, line+start, width);
/* move the cursor to the correct position */
wmove(w, y, x0 + cursor-start);
line[cursor] = 0;
break;
case KEY_CTRL_U:
- cursor = my_strlen(line);
+ cursor = utf8_width(line);
for (i = 0;i < cursor; i++)
line[i] = '\0';
cursor = 0;
break;
case KEY_DC: /* handle delete key. As above */
case KEY_CTRL_D:
- if (cursor <= (gint)my_strlen(line) - 1) {
+ if (cursor <= (gint)utf8_width(line) - 1) {
for (i = cursor; line[i] != 0; i++)
line[i] = line[i + 1];
}