Changeset e0e0e5a for fmtext.c


Ignore:
Timestamp:
Jul 31, 2010, 7:11:42 PM (11 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.7, release-1.8, release-1.9
Children:
c93b8b5
Parents:
6772d19
git-author:
David Benjamin <davidben@mit.edu> (07/25/10 17:35:41)
git-committer:
David Benjamin <davidben@mit.edu> (07/31/10 19:11:42)
Message:
Make _owl_fmtext_append_fmtext take a half-open range

Inclusive on both endpoints is weird. This also makes the usage in
owl_fmtext_append_fmtext correct. It otherwise appends an extra '\0',
causing textlen to be off. This fixes a failure in the owl_fmtext test.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • fmtext.c

    r6772d19 re0e0e5a  
    175175
    176176
    177 /* Internal function.  Append text from 'in' between index 'start' and
    178  * 'stop', inclusive, to the end of 'f'. This function works with
    179  * bytes.
     177/* Internal function.  Append text from 'in' between index 'start'
     178 * inclusive and 'stop' exclusive, to the end of 'f'. This function
     179 * works with bytes.
    180180 */
    181181static void _owl_fmtext_append_fmtext(owl_fmtext *f, const owl_fmtext *in, int start, int stop)
     
    194194  /* We will reset to defaults after appending the text. We may need
    195195     to set initial attributes. */
    196   newlen=strlen(f->textbuff)+(stop-start+1) + (4 * (a + fg + bg)) + 12;
     196  newlen=strlen(f->textbuff)+(stop-start) + (4 * (a + fg + bg)) + 12;
    197197  _owl_fmtext_realloc(f, newlen);
    198198
     
    207207            g_unichar_to_utf8(OWL_FMTEXT_UC_BGCOLOR | bgcolor, attrbuff));
    208208
    209   strncat(f->textbuff, in->textbuff+start, stop-start+1);
     209  strncat(f->textbuff, in->textbuff+start, stop-start);
    210210
    211211  /* Reset attributes */
     
    402402    ptr2 = strchr(ptr1, '\n');
    403403    if (!ptr2) {
    404       _owl_fmtext_append_fmtext(out, in, offset, (in->textlen) - 1);
     404      /* Copy to the end of the buffer. */
     405      _owl_fmtext_append_fmtext(out, in, offset, in->textlen);
    405406      return(-1);
    406407    }
    407     _owl_fmtext_append_fmtext(out, in, offset, (ptr2 - ptr1) + offset);
     408    /* Copy up to, and including, the new line. */
     409    _owl_fmtext_append_fmtext(out, in, offset, (ptr2 - ptr1) + offset + 1);
    408410    ptr1 = ptr2 + 1;
    409411  }
     
    475477      owl_fmtext_append_spaces(out, padding);
    476478      if (ptr_c == ptr_e) {
    477         /* We made it to the newline. */
    478         _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff);
     479        /* We made it to the newline. Append up to, and including it. */
     480        _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff + 1);
    479481      }
    480482      else if (chwidth > 1) {
    481483        /* Last char is wide, truncate. */
    482         _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff - 1);
     484        _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff);
    483485        owl_fmtext_append_normal(out, "\n");
    484486      }
    485487      else {
    486         /* Last char fits perfectly, We skip to the next char and back
    487          * up a byte to make sure we get it all.
    488          */
     488        /* Last char fits perfectly, We stop at the next char to make
     489         * sure we get it all. */
    489490        ptr_c = g_utf8_next_char(ptr_c);
    490         _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff - 1);
     491        _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff);
    491492      }
    492493    }
Note: See TracChangeset for help on using the changeset viewer.