OSDN Git Service

runtime: Copy runtime_panicstring from master library.
[pf3gnuchains/gcc-fork.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 #define charntorune(pv, str, len) __go_get_rune(str, len, pv)
8
9 int32
10 runtime_findnull(const byte *s)
11 {
12         if(s == nil)
13                 return 0;
14         return __builtin_strlen((const char*) s);
15 }
16
17 String
18 runtime_gostringnocopy(const byte *str)
19 {
20         String s;
21         
22         s.__data = (const unsigned char *) str;
23         s.__length = runtime_findnull(str);
24         return s;
25 }
26
27 enum
28 {
29         Runeself        = 0x80,
30 };
31
32 func stringiter(s String, k int32) (retk int32) {
33         int32 l, n;
34
35         if(k >= s.__length) {
36                 // retk=0 is end of iteration
37                 retk = 0;
38                 goto out;
39         }
40
41         l = s.__data[k];
42         if(l < Runeself) {
43                 retk = k+1;
44                 goto out;
45         }
46
47         // multi-char rune
48         n = charntorune(&l, s.__data+k, s.__length-k);
49         retk = k + (n ? n : 1);
50
51 out:
52 }
53
54 func stringiter2(s String, k int32) (retk int32, retv int32) {
55         int32 n;
56
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         n = charntorune(&retv, s.__data+k, s.__length-k);
72         retk = k + (n ? n : 1);
73
74 out:
75 }