Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
aa4c638b
Commit
aa4c638b
authored
Nov 20, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x[y:] for strings
R=ken2
https://golang.org/cl/157114
parent
3e8bb54c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
32 additions
and
6 deletions
+32
-6
builtin.c.boot
src/cmd/gc/builtin.c.boot
+1
-0
const.c
src/cmd/gc/const.c
+1
-1
runtime.go
src/cmd/gc/runtime.go
+1
-0
walk.c
src/cmd/gc/walk.c
+10
-4
string.cgo
src/pkg/runtime/string.cgo
+18
-0
string.go
test/ken/string.go
+1
-1
No files found.
src/cmd/gc/builtin.c.boot
View file @
aa4c638b
...
...
@@ -19,6 +19,7 @@ char *runtimeimport =
"func runtime.catstring (? string, ? string) (? string)\n"
"func runtime.cmpstring (? string, ? string) (? int)\n"
"func runtime.slicestring (? string, ? int, ? int) (? string)\n"
"func runtime.slicestring1 (? string, ? int) (? string)\n"
"func runtime.indexstring (? string, ? int) (? uint8)\n"
"func runtime.intstring (? int64) (? string)\n"
"func runtime.slicebytetostring (? []uint8) (? string)\n"
...
...
src/cmd/gc/const.c
View file @
aa4c638b
...
...
@@ -55,7 +55,7 @@ truncfltlit(Mpflt *oldv, Type *t)
void
convlit
(
Node
**
np
,
Type
*
t
)
{
return
convlit1
(
np
,
t
,
0
);
convlit1
(
np
,
t
,
0
);
}
/*
...
...
src/cmd/gc/runtime.go
View file @
aa4c638b
...
...
@@ -27,6 +27,7 @@ func printsp()
func
catstring
(
string
,
string
)
string
func
cmpstring
(
string
,
string
)
int
func
slicestring
(
string
,
int
,
int
)
string
func
slicestring1
(
string
,
int
)
string
func
indexstring
(
string
,
int
)
byte
func
intstring
(
int64
)
string
func
slicebytetostring
([]
byte
)
string
...
...
src/cmd/gc/walk.c
View file @
aa4c638b
...
...
@@ -918,10 +918,16 @@ walkexpr(Node **np, NodeList **init)
case
OSLICESTR
:
// sys_slicestring(s, lb, hb)
n
=
mkcall
(
"slicestring"
,
n
->
type
,
init
,
conv
(
n
->
left
,
types
[
TSTRING
]),
conv
(
n
->
right
->
left
,
types
[
TINT
]),
conv
(
n
->
right
->
right
,
types
[
TINT
]));
if
(
n
->
right
->
right
)
{
n
=
mkcall
(
"slicestring"
,
n
->
type
,
init
,
conv
(
n
->
left
,
types
[
TSTRING
]),
conv
(
n
->
right
->
left
,
types
[
TINT
]),
conv
(
n
->
right
->
right
,
types
[
TINT
]));
}
else
{
n
=
mkcall
(
"slicestring1"
,
n
->
type
,
init
,
conv
(
n
->
left
,
types
[
TSTRING
]),
conv
(
n
->
right
->
left
,
types
[
TINT
]));
}
goto
ret
;
case
OINDEXSTR
:
...
...
src/pkg/runtime/string.cgo
View file @
aa4c638b
...
...
@@ -142,6 +142,24 @@ func slicestring(si String, lindex int32, hindex int32) (so String) {
//
mcpy
(
so
.
str
,
si
.
str
+
lindex
,
l
);
}
func
slicestring1
(
si
String
,
lindex
int32
)
(
so
String
)
{
int32
l
;
if
(
lindex
<
0
||
lindex
>
si
.
len
)
{
runtime
·
printpc
(&
si
);
prints
(
" "
);
prbounds
(
"slice"
,
lindex
,
si
.
len
,
si
.
len
);
}
l
=
si
.
len
-
lindex
;
so
.
str
=
si
.
str
+
lindex
;
so
.
len
=
l
;
//
alternate
to
create
a
new
string
//
so
=
gostringsize
(
l
);
//
mcpy
(
so
.
str
,
si
.
str
+
lindex
,
l
);
}
func
indexstring
(
s
String
,
i
int32
)
(
b
byte
)
{
if
(
i
<
0
||
i
>=
s
.
len
)
{
runtime
·
printpc
(&
s
);
...
...
test/ken/string.go
View file @
aa4c638b
...
...
@@ -64,7 +64,7 @@ main()
}
/* slice strings */
print
(
c
[
0
:
3
],
c
[
3
:
6
]);
print
(
c
[
0
:
3
],
c
[
3
:
]);
print
(
"
\n
"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment