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
81ba399a
Commit
81ba399a
authored
Sep 23, 2010
by
Roger Peppe
Committed by
Rob Pike
Sep 23, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bytes, strings: change lastIndexFunc to use DecodeLastRune
R=r CC=golang-dev, rsc
https://golang.org/cl/2271041
parent
f11271b8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
52 deletions
+8
-52
bytes.go
src/pkg/bytes/bytes.go
+4
-26
strings.go
src/pkg/strings/strings.go
+4
-26
No files found.
src/pkg/bytes/bytes.go
View file @
81ba399a
...
...
@@ -490,34 +490,12 @@ func indexFunc(s []byte, f func(r int) bool, truth bool) int {
// truth==false, the sense of the predicate function is
// inverted.
func
lastIndexFunc
(
s
[]
byte
,
f
func
(
r
int
)
bool
,
truth
bool
)
int
{
end
:=
len
(
s
)
for
end
>
0
{
start
:=
end
-
1
rune
:=
int
(
s
[
start
])
if
rune
>=
utf8
.
RuneSelf
{
// Back up & look for beginning of rune. Mustn't pass start.
for
start
--
;
start
>=
0
;
start
--
{
if
utf8
.
RuneStart
(
s
[
start
])
{
break
}
}
if
start
<
0
{
return
-
1
}
var
wid
int
rune
,
wid
=
utf8
.
DecodeRune
(
s
[
start
:
end
])
// If we've decoded fewer bytes than we expected,
// we've got some invalid UTF-8, so make sure we return
// the last possible index in s.
if
start
+
wid
<
end
&&
f
(
utf8
.
RuneError
)
==
truth
{
return
end
-
1
}
}
for
i
:=
len
(
s
);
i
>
0
;
{
rune
,
size
:=
utf8
.
DecodeLastRune
(
s
[
0
:
i
])
i
-=
size
if
f
(
rune
)
==
truth
{
return
start
return
i
}
end
=
start
}
return
-
1
}
...
...
src/pkg/strings/strings.go
View file @
81ba399a
...
...
@@ -451,34 +451,12 @@ func indexFunc(s string, f func(r int) bool, truth bool) int {
// truth==false, the sense of the predicate function is
// inverted.
func
lastIndexFunc
(
s
string
,
f
func
(
r
int
)
bool
,
truth
bool
)
int
{
end
:=
len
(
s
)
for
end
>
0
{
start
:=
end
-
1
rune
:=
int
(
s
[
start
])
if
rune
>=
utf8
.
RuneSelf
{
// Back up & look for beginning of rune. Mustn't pass start.
for
start
--
;
start
>=
0
;
start
--
{
if
utf8
.
RuneStart
(
s
[
start
])
{
break
}
}
if
start
<
0
{
start
=
0
}
var
wid
int
rune
,
wid
=
utf8
.
DecodeRuneInString
(
s
[
start
:
end
])
// If we've decoded fewer bytes than we expected,
// we've got some invalid UTF-8, so make sure we return
// the last possible index in s.
if
start
+
wid
<
end
&&
f
(
utf8
.
RuneError
)
==
truth
{
return
end
-
1
}
}
for
i
:=
len
(
s
);
i
>
0
;
{
rune
,
size
:=
utf8
.
DecodeLastRuneInString
(
s
[
0
:
i
])
i
-=
size
if
f
(
rune
)
==
truth
{
return
start
return
i
}
end
=
start
}
return
-
1
}
...
...
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