LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Package strings implements simple functions to manipulate strings. | 5 // Package strings implements simple functions to manipulate strings. |
6 package strings | 6 package strings |
7 | 7 |
8 import ( | 8 import ( |
9 "unicode" | 9 "unicode" |
10 "unicode/utf8" | 10 "unicode/utf8" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 if h == hashsep && s[:n] == sep { | 148 if h == hashsep && s[:n] == sep { |
149 return 0 | 149 return 0 |
150 } | 150 } |
151 for i := n; i < len(s); { | 151 for i := n; i < len(s); { |
152 h *= primeRK | 152 h *= primeRK |
153 h += uint32(s[i]) | 153 h += uint32(s[i]) |
154 h -= pow * uint32(s[i-n]) | 154 h -= pow * uint32(s[i-n]) |
155 i++ | 155 i++ |
156 if h == hashsep && s[i-n:i] == sep { | 156 if h == hashsep && s[i-n:i] == sep { |
157 return i - n | 157 return i - n |
158 } | |
159 } | |
160 return -1 | |
161 } | |
162 | |
163 // IndexByte returns the index of the first instance of c in s, or -1 if c is no
t present in s. | |
164 func IndexByte(s string, c byte) int { | |
165 for i := 0; i < len(s); i++ { | |
166 if s[i] == c { | |
167 return i | |
168 } | 158 } |
169 } | 159 } |
170 return -1 | 160 return -1 |
171 } | 161 } |
172 | 162 |
173 // LastIndex returns the index of the last instance of sep in s, or -1 if sep is
not present in s. | 163 // LastIndex returns the index of the last instance of sep in s, or -1 if sep is
not present in s. |
174 func LastIndex(s, sep string) int { | 164 func LastIndex(s, sep string) int { |
175 n := len(sep) | 165 n := len(sep) |
176 if n == 0 { | 166 if n == 0 { |
177 return len(s) | 167 return len(s) |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 } | 719 } |
730 if r == tr { | 720 if r == tr { |
731 continue | 721 continue |
732 } | 722 } |
733 return false | 723 return false |
734 } | 724 } |
735 | 725 |
736 // One string is empty. Are both? | 726 // One string is empty. Are both? |
737 return s == t | 727 return s == t |
738 } | 728 } |
LEFT | RIGHT |