]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgo/runtime/string.goc
libgo: Update to current sources.
[thirdparty/gcc.git] / libgo / runtime / string.goc
CommitLineData
7a938933
ILT
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
5package runtime
6#include "runtime.h"
df4aa89a
ILT
7#include "arch.h"
8#include "malloc.h"
9
7a938933
ILT
10#define charntorune(pv, str, len) __go_get_rune(str, len, pv)
11
5c262e94
ILT
12int32
13runtime_findnull(const byte *s)
14{
15 if(s == nil)
16 return 0;
17 return __builtin_strlen((const char*) s);
18}
19
20String
b8797494 21runtime_gostringnocopy(const byte *str)
5c262e94
ILT
22{
23 String s;
24
25 s.__data = (const unsigned char *) str;
26 s.__length = runtime_findnull(str);
27 return s;
28}
29
7a938933
ILT
30enum
31{
32 Runeself = 0x80,
33};
34
4ccad563
ILT
35func stringiter(s String, k int) (retk int) {
36 int32 l;
7a938933
ILT
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
4ccad563 51 retk = k + charntorune(&l, s.__data+k, s.__length-k);
7a938933
ILT
52
53out:
54}
55
4ccad563 56func stringiter2(s String, k int) (retk int, retv int) {
7a938933
ILT
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
4ccad563 71 retk = k + charntorune(&retv, s.__data+k, s.__length-k);
7a938933
ILT
72
73out:
74}