Changeset e0022d2


Ignore:
Timestamp:
Aug 2, 2010, 11:38:03 PM (14 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.7, release-1.8, release-1.9
Children:
fd03b12
Parents:
30da473
git-author:
David Benjamin <davidben@mit.edu> (07/25/10 18:58:30)
git-committer:
David Benjamin <davidben@mit.edu> (08/02/10 23:38:03)
Message:
Expand tabs first in owl_fmtext_truncate_cols

Although the previous commit already expanded tabs from messages, a
fmtext may still get tabs in it. For instance, a :pexec. So, before
truncating, we expand all tabs.

Also adds a test case with tabs for owl_fmtext_truncate_cols.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • fmtext.c

    r30da473 re0022d2  
    450450}
    451451
    452 /* Truncate the message so that each line begins at column 'acol' and
    453  * ends at 'bcol' or sooner.  The first column is number 0.  The new
    454  * message is placed in 'out'.  The message is expected to end in a
    455  * new line for now.
    456  *
    457  * NOTE: This needs to be modified to deal with backing up if we find
    458  * a SPACING COMBINING MARK at the end of a line. If that happens, we
    459  * should back up to the last non-mark character and stop there.
    460  *
    461  * NOTE: If a line ends at bcol, we omit the newline. This is so printing
    462  * to ncurses works.
    463  */
    464 void owl_fmtext_truncate_cols(const owl_fmtext *in, int acol, int bcol, owl_fmtext *out)
     452/* Implementation of owl_fmtext_truncate_cols. Does not support tabs in input. */
     453void _owl_fmtext_truncate_cols_internal(const owl_fmtext *in, int acol, int bcol, owl_fmtext *out)
    465454{
    466455  const char *ptr_s, *ptr_e, *ptr_c, *last;
     
    536525}
    537526
     527/* Truncate the message so that each line begins at column 'acol' and
     528 * ends at 'bcol' or sooner.  The first column is number 0.  The new
     529 * message is placed in 'out'.  The message is expected to end in a
     530 * new line for now.
     531 *
     532 * NOTE: This needs to be modified to deal with backing up if we find
     533 * a SPACING COMBINING MARK at the end of a line. If that happens, we
     534 * should back up to the last non-mark character and stop there.
     535 *
     536 * NOTE: If a line ends at bcol, we omit the newline. This is so printing
     537 * to ncurses works.
     538 */
     539void owl_fmtext_truncate_cols(const owl_fmtext *in, int acol, int bcol, owl_fmtext *out)
     540{
     541  owl_fmtext notabs;
     542
     543  /* _owl_fmtext_truncate_cols_internal cannot handle tabs. */
     544  if (strchr(in->textbuff, '\t')) {
     545    owl_fmtext_init_null(&notabs);
     546    owl_fmtext_expand_tabs(in, &notabs, 0);
     547    _owl_fmtext_truncate_cols_internal(&notabs, acol, bcol, out);
     548    owl_fmtext_cleanup(&notabs);
     549  } else {
     550    _owl_fmtext_truncate_cols_internal(in, acol, bcol, out);
     551  }
     552}
     553
    538554/* Return the number of lines in 'f' */
    539555int owl_fmtext_num_lines(const owl_fmtext *f)
  • tester.c

    r2b83ad6 re0022d2  
    470470  owl_free(str);
    471471
     472  owl_fmtext_clear(&fm1);
     473  owl_fmtext_append_normal(&fm1, "12\t1234");
     474  owl_fmtext_append_bold(&fm1, "56\n");
     475  owl_fmtext_append_bold(&fm1, "12345678\t\n");
     476
     477  owl_fmtext_clear(&fm2);
     478  owl_fmtext_truncate_cols(&fm1, 4, 13, &fm2);
     479  str = owl_fmtext_print_plain(&fm2);
     480  FAIL_UNLESS("columns correctly truncated",
     481              str && !strcmp(str, "    123456"
     482                                  "5678      "));
     483  owl_free(str);
     484
    472485  /* Test owl_fmtext_expand_tabs. */
    473486  owl_fmtext_clear(&fm1);
Note: See TracChangeset for help on using the changeset viewer.