Created
April 21, 2015 11:12
-
-
Save aalemayhu/e59c02c5ae93dab15014 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"errors" | |
"fmt" | |
"io/ioutil" | |
"os" | |
"strings" | |
) | |
func usage() { | |
fmt.Println("Please specify a new and old po file") | |
} | |
// Modified version a example call from go/src/bufio/example_test.go | |
func getLine() (string, error) { | |
var line string | |
scanner := bufio.NewScanner(os.Stdin) | |
if scanner.Scan() { | |
line = scanner.Text() | |
} else { | |
return "", errors.New("Could not read line") | |
} | |
return string(line), nil | |
} | |
func linesFromFile(filename string) ([]string, error) { | |
content, err := ioutil.ReadFile(filename) | |
if err != nil { | |
return nil, err | |
} | |
return strings.Split(string(content), "\n"), nil | |
} | |
func main() { | |
argc := len(os.Args) | |
if argc <= 1 { | |
usage() | |
return | |
} | |
filename := os.Args[1] | |
lines, err := linesFromFile(filename) | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
lineLen := len(lines) | |
for i := 0; i < lineLen; i++ { | |
line := lines[i] | |
isArticle := strings.Contains(line, "<article>") | |
isType := strings.Contains(line, "#. type: Attribute") || strings.Contains(line, "#. type: Content") | |
newline := !isType || isArticle | |
if i+1 < lineLen && newline { | |
if isArticle && !isType { | |
line = line[2:] | |
} | |
fmt.Println(line) | |
} else { | |
fmt.Print(line) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment