annotate libgo/runtime/go-strslice.c @ 136:4627f235cf2a

fix c-next example
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 08 Nov 2018 14:11:56 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* go-strslice.c -- the go string slice function.
kono
parents:
diff changeset
2
kono
parents:
diff changeset
3 Copyright 2009 The Go Authors. All rights reserved.
kono
parents:
diff changeset
4 Use of this source code is governed by a BSD-style
kono
parents:
diff changeset
5 license that can be found in the LICENSE file. */
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 #include "runtime.h"
kono
parents:
diff changeset
8
kono
parents:
diff changeset
9 String
kono
parents:
diff changeset
10 __go_string_slice (String s, intgo start, intgo end)
kono
parents:
diff changeset
11 {
kono
parents:
diff changeset
12 intgo len;
kono
parents:
diff changeset
13 String ret;
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 len = s.len;
kono
parents:
diff changeset
16 if (end == -1)
kono
parents:
diff changeset
17 end = len;
kono
parents:
diff changeset
18 if (start > len || end < start || end > len)
kono
parents:
diff changeset
19 runtime_panicstring ("string index out of bounds");
kono
parents:
diff changeset
20 ret.len = end - start;
kono
parents:
diff changeset
21 // If the length of the new string is zero, the str field doesn't
kono
parents:
diff changeset
22 // matter, so just set it to nil. This avoids the problem of
kono
parents:
diff changeset
23 // s.str + start pointing just past the end of the string,
kono
parents:
diff changeset
24 // which may keep the next memory block alive unnecessarily.
kono
parents:
diff changeset
25 if (ret.len == 0)
kono
parents:
diff changeset
26 ret.str = nil;
kono
parents:
diff changeset
27 else
kono
parents:
diff changeset
28 ret.str = s.str + start;
kono
parents:
diff changeset
29 return ret;
kono
parents:
diff changeset
30 }