Changeset 2b83ad6 for fmtext.c


Ignore:
Timestamp:
Jul 31, 2010, 7:12:15 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:
30da473
Parents:
c93b8b5
git-author:
David Benjamin <davidben@mit.edu> (07/25/10 18:36:54)
git-committer:
David Benjamin <davidben@mit.edu> (07/31/10 19:12:15)
Message:
Add owl_fmtext_expand_tabs with test case
File:
1 edited

Legend:

Unmodified
Added
Removed
  • fmtext.c

    rc93b8b5 r2b83ad6  
    370370{
    371371  _owl_fmtext_curs_waddstr(f, w, 0);
     372}
     373
     374/* Expands tabs. Tabs are expanded as if given an initial indent of start. */
     375void owl_fmtext_expand_tabs(const owl_fmtext *in, owl_fmtext *out, int start) {
     376  int col = start, numcopied = 0;
     377  char *ptr;
     378
     379  /* Copy the default attributes. */
     380  out->default_attrs = in->default_attrs;
     381  out->default_fgcolor = in->default_fgcolor;
     382  out->default_bgcolor = in->default_bgcolor;
     383
     384  for (ptr = in->textbuff;
     385       ptr < in->textbuff + in->textlen;
     386       ptr = g_utf8_next_char(ptr)) {
     387    gunichar c = g_utf8_get_char(ptr);
     388    int chwidth;
     389    if (c == '\t') {
     390      /* Copy up to this tab */
     391      _owl_fmtext_append_fmtext(out, in, numcopied, ptr - in->textbuff - 1);
     392      /* and then copy spaces for the tab. */
     393      chwidth = OWL_TAB_WIDTH - (col % OWL_TAB_WIDTH);
     394      owl_fmtext_append_spaces(out, chwidth);
     395      col += chwidth;
     396      numcopied = g_utf8_next_char(ptr) - in->textbuff;
     397    } else {
     398      /* Just update col. We'll append later. */
     399      if (c == '\n') {
     400        col = start;
     401      } else if (!owl_fmtext_is_format_char(c)) {
     402        col += mk_wcwidth(c);
     403      }
     404    }
     405  }
     406  /* Append anything we've missed. */
     407  if (numcopied < in->textlen)
     408    _owl_fmtext_append_fmtext(out, in, numcopied, in->textlen - 1);
    372409}
    373410
Note: See TracChangeset for help on using the changeset viewer.