Skip to content

Comments

Fix display non-ascii character.#1299

Merged
koutcher merged 1 commit intojonas:masterfrom
nonakap:fix-display-non-ascii-character
Oct 28, 2023
Merged

Fix display non-ascii character.#1299
koutcher merged 1 commit intojonas:masterfrom
nonakap:fix-display-non-ascii-character

Conversation

@nonakap
Copy link
Contributor

@nonakap nonakap commented Oct 24, 2023

Should cast the argument passed to is*() function in ctype.h to unsigned char.

See https://wiki.sei.cmu.edu/confluence/display/c/STR37-C.+Arguments+to+character-handling+functions+must+be+representable+as+an+unsigned+char.

Should fix #1294.

before:
The commit log contains Japanese characters, but they are not displayed correctly.
tig-display-broken-non-ascii-character

after:
The commit log is displayed correctly.
tig-fix-display-non-ascii-character

@koutcher
Copy link
Collaborator

koutcher commented Oct 26, 2023

Thank you @nonakap. Your proposed correction has the exact opposite effect on macOS, it works without and it doesn't work with, but it certainly goes in the right direction. Could you try the following ?

diff --git a/src/string.c b/src/string.c
index a90fc1bb..4cb0910b 100644
--- a/src/string.c
+++ b/src/string.c
@@ -103,7 +103,7 @@ string_expand(char *dst, size_t dstlen, const char *src, int srclen, int tabsize
                                expanded = dstlen - size - 1;
                        memcpy(dst + size, "        ", expanded);
                        size += expanded;
-               } else if (isspace((unsigned char)c) || iscntrl((unsigned char)c)) {
+               } else if (iswspace(c) || iswcntrl(c)) {
                        dst[size++] = ' ';
                } else {
                        dst[size++] = src[pos];
@@ -119,7 +119,7 @@ string_trim_end(char *name)
 {
        int namelen = strlen(name) - 1;

-       while (namelen > 0 && isspace((unsigned char)name[namelen]))
+       while (namelen > 0 && iswspace(name[namelen]))
                name[namelen--] = 0;

        return name;
@@ -128,7 +128,7 @@ string_trim_end(char *name)
 char *
 string_trim(char *name)
 {
-       while (isspace((unsigned char)*name))
+       while (iswspace(*name))
                name++;

        return string_trim_end(name);

EDIT: actually this is a macOS thing only, we'll handle it with a specific case.

@koutcher koutcher merged commit 4ef6807 into jonas:master Oct 28, 2023
@nonakap nonakap deleted the fix-display-non-ascii-character branch November 2, 2023 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chinese (utf-8) character display problem

2 participants