Implement a flag -fext-numeric-literals that allows control of whether GNU
[official-gcc.git] / libgo / runtime / string.goc
blob240ab0ba5e43da2cefff2bc6074108beb2341792
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 #include "arch.h"
8 #include "malloc.h"
9 #include "go-string.h"
11 #define charntorune(pv, str, len) __go_get_rune(str, len, pv)
13 intgo
14 runtime_findnull(const byte *s)
16         if(s == nil)
17                 return 0;
18         return __builtin_strlen((const char*) s);
21 String
22 runtime_gostringnocopy(const byte *str)
24         String s;
25         
26         s.str = str;
27         s.len = runtime_findnull(str);
28         return s;
31 enum
33         Runeself        = 0x80,
36 func stringiter(s String, k int) (retk int) {
37         int32 l;
39         if(k >= s.len) {
40                 // retk=0 is end of iteration
41                 retk = 0;
42                 goto out;
43         }
45         l = s.str[k];
46         if(l < Runeself) {
47                 retk = k+1;
48                 goto out;
49         }
51         // multi-char rune
52         retk = k + charntorune(&l, s.str+k, s.len-k);
54 out:
57 func stringiter2(s String, k int) (retk int, retv int32) {
58         if(k >= s.len) {
59                 // retk=0 is end of iteration
60                 retk = 0;
61                 retv = 0;
62                 goto out;
63         }
65         retv = s.str[k];
66         if(retv < Runeself) {
67                 retk = k+1;
68                 goto out;
69         }
71         // multi-char rune
72         retk = k + charntorune(&retv, s.str+k, s.len-k);
74 out: