Improve longest word (punctuation)
This commit is contained in:
parent
59e20d36c1
commit
0433c6344c
@ -7,6 +7,8 @@ import "os"
|
||||
import "bufio"
|
||||
import "strings"
|
||||
|
||||
var PUNCTUATION = []string{".", ",", "\"", "—", "-", "/"}
|
||||
|
||||
func longest(r io.Reader) string {
|
||||
lw := ""
|
||||
s := bufio.NewScanner(r)
|
||||
@ -14,14 +16,12 @@ func longest(r io.Reader) string {
|
||||
for s.Scan() {
|
||||
word := s.Text()
|
||||
word = strings.ToLower(word)
|
||||
word = strings.Replace(word, ".", "", -1)
|
||||
word = strings.Replace(word, ",", "", -1)
|
||||
word = strings.Replace(word, "\"", "", -1)
|
||||
for _, word := range strings.Split(word, "—") {
|
||||
if len(word) > len(lw) {
|
||||
if !strings.HasPrefix(word, "http://") {
|
||||
lw = word
|
||||
for _, c := range PUNCTUATION {
|
||||
word = strings.Replace(word, c, " ", -1)
|
||||
}
|
||||
for _, word := range strings.Fields(word) {
|
||||
if len(word) > len(lw) {
|
||||
lw = word
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user