Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix display non-ascii character. #1299

Merged
merged 1 commit into from
Oct 28, 2023

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
8 of 9 checks passed
@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