Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / libgo / runtime / go-strslice.c
blob94ecee92e4d77a09487c579a61a81023c80357f6
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-string.h"
8 #include "go-panic.h"
9 #include "runtime.h"
10 #include "malloc.h"
12 struct __go_string
13 __go_string_slice (struct __go_string s, int start, int end)
15 int len;
16 struct __go_string ret;
18 len = s.__length;
19 if (end == -1)
20 end = len;
21 if (start > len || end < start || end > len)
22 __go_panic_msg ("string index out of bounds");
23 ret.__data = s.__data + start;
24 ret.__length = end - start;
25 return ret;