1
0
mirror of https://github.com/thebaer/punctuation.git synced 2018-07-20 08:25:21 +00:00

Write code

,.(:.---).
This commit is contained in:
Matt Baer 2016-02-26 13:52:03 -05:00
commit fe0a21acec
4 changed files with 44 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.swp
cmd/cmd

4
README.md Normal file
View 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
View 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
View 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
}