]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgo/runtime/string.goc
libgo: Update to current sources.
[thirdparty/gcc.git] / libgo / runtime / string.goc
1 // Copyright 2009, 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package runtime
6 #include "runtime.h"
7 #include "arch.h"
8 #include "malloc.h"
9
10 #define charntorune(pv, str, len) __go_get_rune(str, len, pv)
11
12 int32
13 runtime_findnull(const byte *s)
14 {
15 if(s == nil)
16 return 0;
17 return __builtin_strlen((const char*) s);
18 }
19
20 String
21 runtime_gostringnocopy(const byte *str)
22 {
23 String s;
24
25 s.__data = (const unsigned char *) str;
26 s.__length = runtime_findnull(str);
27 return s;
28 }
29
30 enum
31 {
32 Runeself = 0x80,
33 };
34
35 func stringiter(s String, k int) (retk int) {
36 int32 l;
37
38 if(k >= s.__length) {
39 // retk=0 is end of iteration
40 retk = 0;
41 goto out;
42 }
43
44 l = s.__data[k];
45 if(l < Runeself) {
46 retk = k+1;
47 goto out;
48 }
49
50 // multi-char rune
51 retk = k + charntorune(&l, s.__data+k, s.__length-k);
52
53 out:
54 }
55
56 func stringiter2(s String, k int) (retk int, retv int) {
57 if(k >= s.__length) {
58 // retk=0 is end of iteration
59 retk = 0;
60 retv = 0;
61 goto out;
62 }
63
64 retv = s.__data[k];
65 if(retv < Runeself) {
66 retk = k+1;
67 goto out;
68 }
69
70 // multi-char rune
71 retk = k + charntorune(&retv, s.__data+k, s.__length-k);
72
73 out:
74 }