go-strslice.c 605 B

123456789101112131415161718192021222324252627
  1. /* go-strslice.c -- the go string slice function.
  2. Copyright 2009 The Go Authors. All rights reserved.
  3. Use of this source code is governed by a BSD-style
  4. license that can be found in the LICENSE file. */
  5. #include "go-panic.h"
  6. #include "runtime.h"
  7. #include "arch.h"
  8. #include "malloc.h"
  9. String
  10. __go_string_slice (String s, intgo start, intgo end)
  11. {
  12. intgo len;
  13. String ret;
  14. len = s.len;
  15. if (end == -1)
  16. end = len;
  17. if (start > len || end < start || end > len)
  18. runtime_panicstring ("string index out of bounds");
  19. ret.str = s.str + start;
  20. ret.len = end - start;
  21. return ret;
  22. }