2014-07-29 Ed Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / libgo / runtime / go-strslice.c
blob21e1bc031daf29e4ce54da0a1c0941d0bbf4cf5b
1 /* go-strslice.c -- the go string slice function.
3 Copyright 2009 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
7 #include "go-panic.h"
8 #include "runtime.h"
9 #include "arch.h"
10 #include "malloc.h"
12 String
13 __go_string_slice (String s, intgo start, intgo end)
15 intgo len;
16 String ret;
18 len = s.len;
19 if (end == -1)
20 end = len;
21 if (start > len || end < start || end > len)
22 runtime_panicstring ("string index out of bounds");
23 ret.str = s.str + start;
24 ret.len = end - start;
25 return ret;