X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Funistr%2Fu16-mbsnlen.c;h=fb0df36ab160d20c7ef285f5bf239006a91adf13;hb=56c2804916c20464b13800341b426536c842191d;hp=57aa3599da16507eabd19dfd5e52a2c69333732a;hpb=3030c5b5e0a5199e16b05927da72c43c42f211c3;p=gnulib.git diff --git a/lib/unistr/u16-mbsnlen.c b/lib/unistr/u16-mbsnlen.c index 57aa3599d..fb0df36ab 100644 --- a/lib/unistr/u16-mbsnlen.c +++ b/lib/unistr/u16-mbsnlen.c @@ -1,5 +1,5 @@ /* Count characters in UTF-16 string. - Copyright (C) 2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2011 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software: you can redistribute it and/or modify it @@ -28,12 +28,15 @@ u16_mbsnlen (const uint16_t *s, size_t n) characters = 0; while (n > 0) { - int count = u16_mblen (s, n); + ucs4_t uc; + int count = u16_mbtoucr (&uc, s, n); + characters++; + if (count == -2) + break; if (count <= 0) count = 1; s += count; n -= count; - characters++; } return characters; }