2010-12-03 05:34:57 +01:00
|
|
|
// Copyright 2009, 2010 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package runtime
|
|
|
|
#include "runtime.h"
|
2012-01-13 06:11:45 +01:00
|
|
|
#include "arch.h"
|
|
|
|
#include "malloc.h"
|
2012-11-01 04:02:13 +01:00
|
|
|
#include "go-string.h"
|
2012-01-13 06:11:45 +01:00
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
#define charntorune(pv, str, len) __go_get_rune(str, len, pv)
|
|
|
|
|
2012-11-01 04:02:13 +01:00
|
|
|
intgo
|
2011-11-14 23:26:45 +01:00
|
|
|
runtime_findnull(const byte *s)
|
|
|
|
{
|
|
|
|
if(s == nil)
|
|
|
|
return 0;
|
|
|
|
return __builtin_strlen((const char*) s);
|
|
|
|
}
|
|
|
|
|
|
|
|
String
|
2011-11-30 01:21:52 +01:00
|
|
|
runtime_gostringnocopy(const byte *str)
|
2011-11-14 23:26:45 +01:00
|
|
|
{
|
|
|
|
String s;
|
|
|
|
|
2012-11-01 04:02:13 +01:00
|
|
|
s.str = str;
|
|
|
|
s.len = runtime_findnull(str);
|
2011-11-14 23:26:45 +01:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
Runeself = 0x80,
|
|
|
|
};
|
|
|
|
|
2012-10-23 06:31:11 +02:00
|
|
|
func stringiter(s String, k int) (retk int) {
|
|
|
|
int32 l;
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2012-11-01 04:02:13 +01:00
|
|
|
if(k >= s.len) {
|
2010-12-03 05:34:57 +01:00
|
|
|
// retk=0 is end of iteration
|
|
|
|
retk = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2012-11-01 04:02:13 +01:00
|
|
|
l = s.str[k];
|
2010-12-03 05:34:57 +01:00
|
|
|
if(l < Runeself) {
|
|
|
|
retk = k+1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
// multi-char rune
|
2012-11-01 04:02:13 +01:00
|
|
|
retk = k + charntorune(&l, s.str+k, s.len-k);
|
2010-12-03 05:34:57 +01:00
|
|
|
|
|
|
|
out:
|
|
|
|
}
|
|
|
|
|
2012-10-23 06:31:11 +02:00
|
|
|
func stringiter2(s String, k int) (retk int, retv int) {
|
2012-11-01 04:02:13 +01:00
|
|
|
if(k >= s.len) {
|
2010-12-03 05:34:57 +01:00
|
|
|
// retk=0 is end of iteration
|
|
|
|
retk = 0;
|
|
|
|
retv = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2012-11-01 04:02:13 +01:00
|
|
|
retv = s.str[k];
|
2010-12-03 05:34:57 +01:00
|
|
|
if(retv < Runeself) {
|
|
|
|
retk = k+1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
// multi-char rune
|
2012-11-01 04:02:13 +01:00
|
|
|
retk = k + charntorune(&retv, s.str+k, s.len-k);
|
2010-12-03 05:34:57 +01:00
|
|
|
|
|
|
|
out:
|
|
|
|
}
|