mirror of
https://github.com/thebaer/punctuation.git
synced 2018-07-20 08:25:21 +00:00
Write code
,.(:.---).
This commit is contained in:
commit
fe0a21acec
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.swp
|
||||||
|
cmd/cmd
|
4
README.md
Normal file
4
README.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
punctuation
|
||||||
|
===========
|
||||||
|
|
||||||
|
Words and symbols in, punctuation out. Inspired by an [article on punctuation in novels](https://medium.com/@neuroecology/punctuation-in-novels-8f316d542ec4).
|
13
cmd/main.go
Normal file
13
cmd/main.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/thebaer/punctuation"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
o := punctuation.Extract(os.Stdin)
|
||||||
|
fmt.Println(o)
|
||||||
|
}
|
25
punctuation.go
Normal file
25
punctuation.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// punctuation takes text and gives back only punctuation.
|
||||||
|
package punctuation
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const validPunc = ";:'\",!?.-()"
|
||||||
|
|
||||||
|
func Extract(f *os.File) string {
|
||||||
|
var out string
|
||||||
|
in := bufio.NewScanner(f)
|
||||||
|
for in.Scan() {
|
||||||
|
out += strings.Map(func(r rune) rune {
|
||||||
|
if strings.IndexRune(validPunc, r) >= 0 {
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}, in.Text())
|
||||||
|
}
|
||||||
|
|
||||||
|
return out
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user