Changeset 3e8ff1e for text.c


Ignore:
Timestamp:
Jul 15, 2009, 11:03:48 PM (12 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
a52d13a
Parents:
72ab15f
git-author:
Nelson Elhage <nelhage@mit.edu> (07/12/09 21:45:00)
git-committer:
Nelson Elhage <nelhage@mit.edu> (07/15/09 23:03:48)
Message:
Implement owl_text_expand_tabs, and tests.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • text.c

    rf34dd65 r3e8ff1e  
    125125
    126126  return(out2);
     127}
     128
     129#define OWL_TAB_WIDTH 8
     130
     131/* Caller must free return */
     132char *owl_text_expand_tabs(char *in)
     133{
     134  int ntabs = 0;
     135  char *p = in;
     136  char *ret, *out;
     137  int col;
     138
     139  while(*p) {
     140    if (*(p++) == '\t') ntabs++;
     141  }
     142
     143  ret = owl_malloc(strlen(in) + 1 + OWL_TAB_WIDTH * ntabs);
     144
     145  p = in;
     146  out = ret;
     147
     148  col = 0;
     149  while(*p) {
     150    switch(*p) {
     151    case '\t':
     152      do {*(out++) = ' '; col++; } while (col % OWL_TAB_WIDTH);
     153      break;
     154    case '\n':
     155      col = -1;
     156    default:
     157      col++;
     158      *(out++) = *p;
     159    }
     160    p++;
     161  }
     162
     163  *out = 0;
     164
     165  return ret;
    127166}
    128167
Note: See TracChangeset for help on using the changeset viewer.