Changeset e30ed92


Ignore:
Timestamp:
Aug 17, 2009, 10:03:53 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:
14acbbd
Parents:
8bce750
git-author:
Nelson Elhage <nelhage@mit.edu> (08/17/09 22:03:45)
git-committer:
Nelson Elhage <nelhage@mit.edu> (08/17/09 22:03:53)
Message:
skiptokens: Handle quotes more correctly.

This fixes ctl's bug about not being able to bind the ' key. In
addition, add some tests for skiptokens.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tester.c

    r8bce750 re30ed92  
    7070  FAIL_UNLESS("expand_tabs 3",
    7171              !strcmp("                2 tabs", owl_text_expand_tabs("\t\t2 tabs")));
     72
     73  FAIL_UNLESS("skiptokens 1",
     74              !strcmp("world", skiptokens("hello world", 1)));
     75
     76  FAIL_UNLESS("skiptokens 2",
     77              !strcmp("c d e", skiptokens("a   b c d e", 2)));
     78
     79  FAIL_UNLESS("skiptokens 3",
     80              !strcmp("\"b\" c d e", skiptokens("a \"b\" c d e", 1)));
     81
     82  FAIL_UNLESS("skiptokens 4",
     83              !strcmp("c d e", skiptokens("a \"b\" c d e", 2)));
     84
     85  FAIL_UNLESS("skiptokens 5",
     86              !strcmp("c d e", skiptokens("a \"'\" c d e", 2)));
    7287
    7388  /* if (numfailed) printf("*** WARNING: failures encountered with owl_util\n"); */
  • util.c

    r8bce750 re30ed92  
    158158
    159159const char *skiptokens(const char *buff, int n) {
    160   /* skips n tokens and returns where that would be.
    161    * TODO: handle quotes more sanely. */
    162  
    163   int inquotes=0;
     160  /* skips n tokens and returns where that would be. */
     161  char quote = 0;
    164162  while (*buff && n>0) {
    165163      while (*buff == ' ') buff++;
    166       while (*buff && (inquotes || *buff != ' ')) {
    167         if (*buff == '"' || *buff == '\'') inquotes=!inquotes;
    168         buff++;
     164      while (*buff && (quote || *buff != ' ')) {
     165        if(quote) {
     166          if(*buff == quote) quote = 0;
     167        } else if(*buff == '"' || *buff == '\'') {
     168          quote = *buff;
     169        }
     170        buff++;
    169171      }
    170172      while (*buff == ' ') buff++;
Note: See TracChangeset for help on using the changeset viewer.