maint: update all copyright year number ranges
[gnulib.git] / lib / unigbrk / u8-grapheme-breaks.c
1 /* Grapheme cluster breaks function.
2    Copyright (C) 2001-2003, 2006-2013 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@cs.stanford.edu>, 2010,
4    based on code written by Bruno Haible <bruno@clisp.org>, 2009.
5
6    This program is free software: you can redistribute it and/or modify it
7    under the terms of the GNU Lesser General Public License as published
8    by the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
19 #include <config.h>
20
21 /* Specification.  */
22 #include "unigbrk.h"
23
24 #include "unistr.h"
25
26 void
27 u8_grapheme_breaks (const uint8_t *s, size_t n, char *p)
28 {
29   ucs4_t prev;
30   int mblen;
31
32   prev = 0;
33   for (; n > 0; s += mblen, p += mblen, n -= mblen)
34     {
35       ucs4_t next;
36       int i;
37
38       mblen = u8_mbtouc (&next, s, n);
39
40       p[0] = uc_is_grapheme_break (prev, next);
41       for (i = 1; i < mblen; i++)
42         p[i] = 0;
43
44       prev = next;
45     }
46 }