X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Funistr%2Fu16-mbsnlen.c;h=fb0df36ab160d20c7ef285f5bf239006a91adf13;hb=56c2804916c20464b13800341b426536c842191d;hp=1bc99690fa28c1233019e9bea500df699313528c;hpb=b2e2010c7c902235b5efb5bd3c6529f61b093aa4;p=gnulib.git diff --git a/lib/unistr/u16-mbsnlen.c b/lib/unistr/u16-mbsnlen.c index 1bc99690f..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-2010 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; }