2011-10-08 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / libgo / runtime / go-string-to-int-array.c
blobf59df6739f158426ef7b6ee2c3b961877d426933
1 /* go-string-to-int-array.c -- convert a string to an array of ints in Go.
3 Copyright 2010 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
7 #include "go-alloc.h"
8 #include "go-string.h"
9 #include "array.h"
10 #include "runtime.h"
11 #include "malloc.h"
13 struct __go_open_array
14 __go_string_to_int_array (struct __go_string str)
16 size_t c;
17 const unsigned char *p;
18 const unsigned char *pend;
19 uint32_t *data;
20 uint32_t *pd;
21 struct __go_open_array ret;
23 c = 0;
24 p = str.__data;
25 pend = p + str.__length;
26 while (p < pend)
28 int rune;
30 ++c;
31 p += __go_get_rune (p, pend - p, &rune);
34 data = (uint32_t *) runtime_mallocgc (c * sizeof (uint32_t), FlagNoPointers,
35 1, 0);
36 p = str.__data;
37 pd = data;
38 while (p < pend)
40 int rune;
42 p += __go_get_rune (p, pend - p, &rune);
43 *pd++ = rune;
46 ret.__values = (void *) data;
47 ret.__count = c;
48 ret.__capacity = c;
49 return ret;