Changeset 7b4d90e for fmtext.c


Ignore:
Timestamp:
Sep 25, 2009, 7:43:51 PM (15 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
dd6af02
Parents:
da60ba9
Message:
Handle missing newline in owl_fmtext_truncate_cols

Fixes #51. Also document some behavior of the function and add a test.

Signed-off-by: David Benjamin <davidben@mit.edu>
File:
1 edited

Legend:

Unmodified
Added
Removed
  • fmtext.c

    r89b2daf r7b4d90e  
    418418/* Truncate the message so that each line begins at column 'acol' and
    419419 * ends at 'bcol' or sooner.  The first column is number 0.  The new
    420  * message is placed in 'out'.  The message is * expected to end in a
    421  * new line for now. NOTE: This needs to be modified to deal with
    422  * backing up if we find a SPACING COMBINING MARK at the end of a
    423  * line. If that happens, we should back up to the last non-mark
    424  * character and stop there.
     420 * message is placed in 'out'.
     421 *
     422 * NOTE: This needs to be modified to deal with backing up if we find
     423 * a SPACING * COMBINING MARK at the end of a line. If that happens,
     424 * we should back up to * the last non-mark character and stop there.
     425 *
     426 * NOTE: If a line ends at bcol, we omit the newline. This is so printing
     427 * to ncurses works.
    425428 */
    426429void owl_fmtext_truncate_cols(const owl_fmtext *in, int acol, int bcol, owl_fmtext *out)
     
    439442    ptr_e=strchr(ptr_s, '\n');
    440443    if (!ptr_e) {
    441       /* but this shouldn't happen if we end in a \n */
    442       break;
     444      /* set it to the NULL at the end of the string, to handle a line that is
     445       * not newline-terminated */
     446      ptr_e = last+1;
    443447    }
    444448   
     
    495499      owl_fmtext_append_normal(out, "\n");
    496500    }
    497     ptr_s = g_utf8_next_char(ptr_e);
     501    /* Be careful if ptr_e is pointing to the NULL if we do not end with a
     502     * newline. We don't really need this check, but pointing ptr_s past the
     503     * NULL byte is just asking for problems later.
     504     */
     505    ptr_s = (ptr_e <= last) ? g_utf8_next_char(ptr_e) : ptr_e;
    498506  }
    499507}
Note: See TracChangeset for help on using the changeset viewer.