Changeset fca4683


Ignore:
Timestamp:
2016-11-12T03:38:34Z (7 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
701ab812
Parents:
727a68b
Message:

word_wrap: truncate utf8 safely

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/misc.c

    r727a68b rfca4683  
    549549}
    550550
    551 /* Word wrapping. Yes, I know this isn't UTF-8 clean. I'm willing to take the risk. */
    552551char *word_wrap(const char *msg, int line_len)
    553552{
     
    582581                }
    583582                if (i == 0) {
    584                         g_string_append_len(ret, msg, line_len);
     583                        const char *end;
     584                        size_t len;
     585
     586                        g_utf8_validate(msg, line_len, &end);
     587
     588                        len = (end != msg) ? end - msg : line_len;
     589
     590                        g_string_append_len(ret, msg, len);
    585591                        g_string_append_c(ret, '\n');
    586                         msg += line_len;
     592                        msg += len;
    587593                }
    588594        }
  • tests/check_util.c

    r727a68b rfca4683  
    137137                5,
    138138                "aaaaa\naaaaa\naaaaa\naaaaa\naaaaa\naaaaa\naaaaa\na",
     139        },
     140        {
     141                "áááááááááá",
     142                11,
     143                "ááááá\nááááá",
    139144        },
    140145        {
Note: See TracChangeset for help on using the changeset viewer.