Browse Source

Write code

,.(:.---).
master
Matt Baer 6 years ago
commit
fe0a21acec
4 changed files with 44 additions and 0 deletions
  1. +2
    -0
      .gitignore
  2. +4
    -0
      README.md
  3. +13
    -0
      cmd/main.go
  4. +25
    -0
      punctuation.go

+ 2
- 0
.gitignore View File

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

+ 4
- 0
README.md 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
- 0
cmd/main.go 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
- 0
punctuation.go 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
}

Loading…
Cancel
Save