Changeset: d1578145f963 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d1578145f963
Modified Files:
        clients/src/mapiclient/mclient.c
Branch: Oct2010
Log Message:

Fix corner case in table display.
If the last line that is to be displayed of a long column happens to
be short due to a newline, the line was not actually truncated.


diffs (118 lines):

diff -r e43e7430fbdb -r d1578145f963 clients/src/mapiclient/mclient.c
--- a/clients/src/mapiclient/mclient.c  Thu Nov 11 14:04:10 2010 +0100
+++ b/clients/src/mapiclient/mclient.c  Fri Nov 12 12:56:08 2010 +0100
@@ -362,15 +362,16 @@
        }
 }
 
-/* return the display length of a UTF-8 string */
+/* return the display length of a UTF-8 string
+   if e is not NULL, return length up to e */
 static size_t
-utf8strlen(const char *s)
+utf8strlen(const char *s, const char *e)
 {
        size_t len = 0;
 
        if (s == NULL)
                return 0;
-       while (*s) {
+       while (*s && (e == NULL || s < e)) {
                /* only count first byte of a sequence */
                if ((*s & 0xC0) != 0x80)
                        len++;
@@ -410,7 +411,7 @@
        if (trim == 1) {
                for (i = 0; i < fields; i++) {
                        if ((t = rest[i]) != NULL &&
-                                       utf8strlen(t) > (size_t) len[i])
+                           utf8strlen(t, NULL) > (size_t) len[i])
                        {
                                /* eat leading whitespace */
                                while (*t != 0 && isspace((int) *t))
@@ -431,7 +432,7 @@
                                                first ? '|' : i > 0 && 
cutafter[i - 1] == 0 ? '>' : ':',
                                                len[i], "");
                        } else {
-                               ulen = utf8strlen(rest[i]);
+                               ulen = utf8strlen(rest[i], NULL);
 
                                if (first && trim == 2) {
                                        /* calculate the height of this field 
according to
@@ -449,6 +450,8 @@
                                 * left-adjust them in the column */
                                t = strchr(rest[i], '\n');
                                if (ulen > (size_t) len[i] || t) {
+                                       char *s;
+
                                        t = utf8skip(rest[i], len[i]);
                                        if (trim == 1) {
                                                while (t > rest[i] && 
!isspace((int) *t))
@@ -458,18 +461,32 @@
                                                        t = utf8skip(rest[i], 
len[i]);
                                        }
                                        mnstr_printf(toConsole, "%c",
-                                                     first ? '|' : i > 0 && 
cutafter[i - 1] == 0 ? '>' : ':');
+                                                    first ? '|' : i > 0 && 
cutafter[i - 1] == 0 ? '>' : ':');
                                        if (numeric[i])
                                                mnstr_printf(toConsole, "%*s",
-                                                             (int) (len[i] - 
(ulen - utf8strlen(t))),
-                                                             "");
-                                       if ((int)(ulen - utf8strlen(t)) >= 
len[i] - 2 &&
-                                                       cutafter[i] == 0)
-                                       {
+                                                            (int) (len[i] - 
(ulen - utf8strlen(t, NULL))),
+                                                            "");
+                                       s = t;
+                                       if (trim == 1)
+                                               while (isascii((int) *s) &&
+                                                      isspace((int) *s))
+                                                       s++;
+                                       if (trim == 2 && *s == '\n')
+                                               s++;
+                                       if (*s && cutafter[i] == 0) {
                                                t = utf8skip(rest[i], len[i] - 
2);
-                                               mnstr_printf(toConsole, " 
%.*s...",
-                                                                 (int) (t - 
rest[i]),
-                                                                 rest[i]);
+                                               s = t;
+                                               if (trim == 1)
+                                                       while (isascii((int) 
*s) &&
+                                                              isspace((int) 
*s))
+                                                               s++;
+                                               if (trim == 2 && *s == '\n')
+                                                       s++;
+                                               mnstr_printf(toConsole, " 
%.*s...%*s",
+                                                            (int) (t - 
rest[i]),
+                                                            rest[i],
+                                                            len[i] - 2 - (int) 
utf8strlen(rest[i], t),
+                                                            "");
                                                croppedfields++;
                                        } else {
                                                mnstr_printf(toConsole, " %.*s 
",
@@ -477,19 +494,15 @@
                                                                  rest[i]);
                                                if (!numeric[i])
                                                        mnstr_printf(toConsole, 
"%*s",
-                                                                         (int) 
(len[i] - (ulen - utf8strlen(t))),
-                                                                         "");
+                                                                    (int) 
(len[i] - (ulen - utf8strlen(t, NULL))),
+                                                                    "");
+                                       }
+                                       rest[i] = *s ? s : 0;
+                                       if (rest[i] == NULL) {
                                                /* avoid > as border marker if 
everything
                                                 * actually just fits */
-                                               if (cutafter[i] == 0)
-                                                       cutafter[i] = -1;
+                                               cutafter[i] = -1;
                                        }
-                                       if (trim == 1)
-                                               while (isspace((int) *t))
-                                                       t++;
-                                       if (trim == 2 && *t == '\n')
-                                               t++;
-                                       rest[i] = *t ? t : 0;
                                        if (cutafter[i] == 0)
                                                rest[i] = NULL;
                                        if (rest[i])
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to