Changeset 3e8ff1e


Ignore:
Timestamp:
Jul 15, 2009, 11:03:48 PM (9 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.
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • tester.c

    reab5aa1 r3e8ff1e  
    77owl_global g;
    88
    9 #define OWL_UTIL_NTESTS  6
     9#define OWL_UTIL_NTESTS  9
    1010#define OWL_DICT_NTESTS  19
    1111#define OWL_OBARRAY_NTESTS  6
  • 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
  • util.c

    r7bf51d5 r3e8ff1e  
    789789              !strcmp("meep", skiptokens("foo 'bar quux' meep", 2)));
    790790
     791  FAIL_UNLESS("expand_tabs 1",
     792              !strcmp("        hi", owl_text_expand_tabs("\thi")));
     793
     794  FAIL_UNLESS("expand_tabs 2",
     795              !strcmp("        hi\nword    tab", owl_text_expand_tabs("\thi\nword\ttab")));
     796
     797  FAIL_UNLESS("expand_tabs 3",
     798              !strcmp("                2 tabs", owl_text_expand_tabs("\t\t2 tabs")));
     799
    791800  /* if (numfailed) printf("*** WARNING: failures encountered with owl_util\n"); */
    792801  printf("# END testing owl_util (%d failures)\n", numfailed);
Note: See TracChangeset for help on using the changeset viewer.