-
-
Save hyuki/7ac6bfceb2c16dc69f2a3df03ea128e2 to your computer and use it in GitHub Desktop.
■をh1に、●をh2に変換するテスト
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" | |
"fmt" | |
"os" | |
"log" | |
"regexp" | |
) | |
func check(err error) { | |
if err != nil { | |
log.Fatal(err) | |
} | |
} | |
func main() { | |
if len(os.Args) != 3 { | |
fmt.Printf("Usage: %s input-filename output-filename\n", os.Args[0]) | |
os.Exit(1) | |
} | |
infilename := os.Args[1] | |
outfilename := os.Args[2] | |
fmt.Printf("input-filename = %s\n", infilename) | |
fmt.Printf("output-filename = %s\n", outfilename) | |
infile, err := os.Open(infilename) | |
check(err) | |
outfile, err := os.Create(outfilename) | |
check(err) | |
linenumber := 0 | |
scanner := bufio.NewScanner(infile) | |
h1 := regexp.MustCompile("^■(.*)") | |
h2 := regexp.MustCompile("^●(.*)") | |
for scanner.Scan() { | |
line := scanner.Text() | |
if s := h1.FindStringSubmatch(line); s != nil { | |
fmt.Fprintf(outfile, "<h1>%s</h1>\n", s[1]) | |
} else if s := h2.FindStringSubmatch(line); s != nil { | |
fmt.Fprintf(outfile, "<h2>%s</h2>\n", s[1]) | |
} else { | |
fmt.Fprintf(outfile, "%s\n", line) | |
} | |
linenumber++ | |
} | |
check(scanner.Err()) | |
check(infile.Close()) | |
check(outfile.Close()) | |
} |
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
■これは見出し | |
これは見出しではない。 | |
■Hello, World. | |
●これは小見出し | |
■ |
Author
hyuki
commented
Apr 9, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment