OSDN Git Service

Use backend interface for map descriptors.
[pf3gnuchains/gcc-fork.git] / libgo / runtime / go-string-to-int-array.c
1 /* go-string-to-int-array.c -- convert a string to an array of ints in Go.
2
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.  */
6
7 #include "go-alloc.h"
8 #include "go-string.h"
9 #include "array.h"
10 #include "runtime.h"
11 #include "malloc.h"
12
13 struct __go_open_array
14 __go_string_to_int_array (struct __go_string str)
15 {
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;
22
23   c = 0;
24   p = str.__data;
25   pend = p + str.__length;
26   while (p < pend)
27     {
28       int rune;
29
30       ++c;
31       p += __go_get_rune (p, pend - p, &rune);
32     }
33
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)
39     {
40       int rune;
41
42       p += __go_get_rune (p, pend - p, &rune);
43       *pd++ = rune;
44     }
45
46   ret.__values = (void *) data;
47   ret.__count = c;
48   ret.__capacity = c;
49   return ret;
50 }