aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/charset.c6
-rw-r--r--src/charset.h3
-rw-r--r--src/list_window.c2
-rw-r--r--src/screen.c14
-rw-r--r--src/support.c2
-rw-r--r--src/wreadln.c6
6 files changed, 17 insertions, 16 deletions
diff --git a/src/charset.c b/src/charset.c
index 41269f38b..aaec39c72 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -34,14 +34,14 @@ charset_init(bool disable)
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 119937710..24f7ef632 100644
--- a/src/charset.h
+++ b/src/charset.h
@@ -28,7 +28,8 @@ void charset_init(bool disable);
/**
* 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 001b606fc..93bed8666 100644
--- a/src/list_window.c
+++ b/src/list_window.c
@@ -185,7 +185,7 @@ list_window_paint(struct list_window *lw,
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 8e6ddefde..87d738825 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -165,7 +165,7 @@ paint_top_window2(const char *header, mpdclient_t *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) {
@@ -196,11 +196,11 @@ static void
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;
}
@@ -277,7 +277,7 @@ paint_status_window(mpdclient_t *c)
if (str) {
waddstr(w, str);
- x += my_strlen(str)+1;
+ x += utf8_width(str) + 1;
}
/* create time string */
@@ -329,7 +329,7 @@ paint_status_window(mpdclient_t *c)
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,
@@ -339,7 +339,7 @@ paint_status_window(mpdclient_t *c)
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 ebbff7348..3f30671f9 100644
--- a/src/support.c
+++ b/src/support.c
@@ -115,7 +115,7 @@ strscroll(char *str, char *separator, int width, scroll_state_t *st)
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 840b73ba0..d01cfcb87 100644
--- a/src/wreadln.c
+++ b/src/wreadln.c
@@ -116,7 +116,7 @@ static inline void drawline(gint cursor,
/* 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);
@@ -274,7 +274,7 @@ _wreadln(WINDOW *w,
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;
@@ -290,7 +290,7 @@ _wreadln(WINDOW *w,
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];
}