2011-10-08 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / libgo / runtime / string.goc
blob332277c52e2fdd724727f89b96c733f975e32c05
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.
5 package runtime
6 #include "runtime.h"
7 #define charntorune(pv, str, len) __go_get_rune(str, len, pv)
9 enum
11         Runeself        = 0x80,
14 func stringiter(s String, k int32) (retk int32) {
15         int32 l, n;
17         if(k >= s.__length) {
18                 // retk=0 is end of iteration
19                 retk = 0;
20                 goto out;
21         }
23         l = s.__data[k];
24         if(l < Runeself) {
25                 retk = k+1;
26                 goto out;
27         }
29         // multi-char rune
30         n = charntorune(&l, s.__data+k, s.__length-k);
31         retk = k + (n ? n : 1);
33 out:
36 func stringiter2(s String, k int32) (retk int32, retv int32) {
37         int32 n;
39         if(k >= s.__length) {
40                 // retk=0 is end of iteration
41                 retk = 0;
42                 retv = 0;
43                 goto out;
44         }
46         retv = s.__data[k];
47         if(retv < Runeself) {
48                 retk = k+1;
49                 goto out;
50         }
52         // multi-char rune
53         n = charntorune(&retv, s.__data+k, s.__length-k);
54         retk = k + (n ? n : 1);
56 out: