summaryrefslogtreecommitdiff
path: root/src/gopher.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-07-02 09:10:50 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-07-02 09:10:50 +0300
commite85d491fa6ef340f19a5b757ae8d7c0b7c6a2677 (patch)
tree81729b2d035c5a3b33088b357f086dd33e675ed3 /src/gopher.c
parent40683c227f4878331855291b487d44e51e69276f (diff)
Gopher: Improved ASCII art detection
Diffstat (limited to 'src/gopher.c')
-rw-r--r--src/gopher.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/gopher.c b/src/gopher.c
index 2933a5d3..d12745ec 100644
--- a/src/gopher.c
+++ b/src/gopher.c
@@ -38,10 +38,37 @@ iLocalDef iBool isDiagram_(char ch) {
38 return strchr("^*_-=~/|\\<>()[]{}", ch) != NULL; 38 return strchr("^*_-=~/|\\<>()[]{}", ch) != NULL;
39} 39}
40 40
41iLocalDef iBool isBoxDrawing_Char(iChar c) {
42 return (c >= 0x2500 && c <= 0x257f);
43}
44
41static iBool isPreformatted_(iRangecc text) { 45static iBool isPreformatted_(iRangecc text) {
42 int numDiag = 0; 46 int numDiag = 0;
43 int numSpace = 0; 47 int numSpace = 0;
48 int numRepeat = 0;
49 char chPrev = 0;
44 for (const char *ch = text.start; ch != text.end; ch++) { 50 for (const char *ch = text.start; ch != text.end; ch++) {
51 if (*ch < 0) {
52 iChar uc;
53 int len = decodeBytes_MultibyteChar(ch, text.end, &uc);
54 if (len > 0) {
55 if (isBoxDrawing_Char(uc)) {
56 if (++numDiag == 3)
57 return iTrue;
58 }
59 ch += len - 1;
60 continue;
61 }
62 }
63 if (*ch != '.' && *ch == chPrev) {
64 if (numRepeat++ == 6) {
65 return iTrue;
66 }
67 }
68 else {
69 numRepeat = 0;
70 }
71 chPrev = *ch;
45 if (isDiagram_(*ch)) { 72 if (isDiagram_(*ch)) {
46 if (++numDiag == 3) 73 if (++numDiag == 3)
47 return iTrue; 74 return iTrue;