OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [runtime/] [string.goc] - Blame information for rev 791

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// 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 int32) (retk int32) {
36
        int32 l, n;
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
        n = charntorune(&l, s.__data+k, s.__length-k);
52
        retk = k + (n ? n : 1);
53
 
54
out:
55
}
56
 
57
func stringiter2(s String, k int32) (retk int32, retv int32) {
58
        int32 n;
59
 
60
        if(k >= s.__length) {
61
                // retk=0 is end of iteration
62
                retk = 0;
63
                retv = 0;
64
                goto out;
65
        }
66
 
67
        retv = s.__data[k];
68
        if(retv < Runeself) {
69
                retk = k+1;
70
                goto out;
71
        }
72
 
73
        // multi-char rune
74
        n = charntorune(&retv, s.__data+k, s.__length-k);
75
        retk = k + (n ? n : 1);
76
 
77
out:
78
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.