Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
37
Task/CSV-to-HTML-translation/Go/csv-to-html-translation-1.go
Normal file
37
Task/CSV-to-HTML-translation/Go/csv-to-html-translation-1.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var c = `Character,Speech
|
||||
The multitude,The messiah! Show us the messiah!
|
||||
Brians mother,<angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry>
|
||||
The multitude,Who are you?
|
||||
Brians mother,I'm his mother; that's who!
|
||||
The multitude,Behold his mother! Behold his mother!`
|
||||
|
||||
func main() {
|
||||
if h, err := csvToHtml(c); err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
fmt.Print(h)
|
||||
}
|
||||
}
|
||||
|
||||
func csvToHtml(c string) (string, error) {
|
||||
data, err := csv.NewReader(bytes.NewBufferString(c)).ReadAll()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
var b strings.Builder
|
||||
err = template.Must(template.New("").Parse(`<table>
|
||||
{{range .}} <tr>{{range .}}<td>{{.}}</td>{{end}}</tr>
|
||||
{{end}}</table>
|
||||
`)).Execute(&b, data)
|
||||
return b.String(), err
|
||||
}
|
||||
57
Task/CSV-to-HTML-translation/Go/csv-to-html-translation-2.go
Normal file
57
Task/CSV-to-HTML-translation/Go/csv-to-html-translation-2.go
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
"flag"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var csvStr = `Character,Speech
|
||||
The multitude,The messiah! Show us the messiah!
|
||||
Brians mother,<angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry>
|
||||
The multitude,Who are you?
|
||||
Brians mother,I'm his mother; that's who!
|
||||
The multitude,Behold his mother! Behold his mother!`
|
||||
|
||||
func main() {
|
||||
headings := flag.Bool("h", false, "format first row as column headings")
|
||||
flag.Parse()
|
||||
if html, err := csvToHtml(csvStr, *headings); err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
fmt.Print(html)
|
||||
}
|
||||
}
|
||||
|
||||
func csvToHtml(csvStr string, headings bool) (string, error) {
|
||||
data, err := csv.NewReader(bytes.NewBufferString(csvStr)).ReadAll()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
tStr := tPlain
|
||||
if headings {
|
||||
tStr = tHeadings
|
||||
}
|
||||
var b strings.Builder
|
||||
err = template.Must(template.New("").Parse(tStr)).Execute(&b, data)
|
||||
return b.String(), err
|
||||
}
|
||||
|
||||
const (
|
||||
tPlain = `<table>
|
||||
{{range .}} <tr>{{range .}}<td>{{.}}</td>{{end}}</tr>
|
||||
{{end}}</table>
|
||||
`
|
||||
tHeadings = `<table>{{if .}}
|
||||
{{range $x, $e := .}}{{if $x}}
|
||||
<tr>{{range .}}<td>{{.}}</td>{{end}}</tr>{{else}} <thead>
|
||||
<tr>{{range .}}<th>{{.}}</th>{{end}}</tr>
|
||||
</thead>
|
||||
<tbody>{{end}}{{end}}
|
||||
</tbody>{{end}}
|
||||
</table>
|
||||
`
|
||||
)
|
||||
12
Task/CSV-to-HTML-translation/Go/csv-to-html-translation-3.go
Normal file
12
Task/CSV-to-HTML-translation/Go/csv-to-html-translation-3.go
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<table>
|
||||
<thead>
|
||||
<tr><th>Character</th><th>Speech</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr><td>The multitude</td><td>The messiah! Show us the messiah!</td></tr>
|
||||
<tr><td>Brians mother</td><td><angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry></td></tr>
|
||||
<tr><td>The multitude</td><td>Who are you?</td></tr>
|
||||
<tr><td>Brians mother</td><td>I'm his mother; that's who!</td></tr>
|
||||
<tr><td>The multitude</td><td>Behold his mother! Behold his mother!</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<table>
|
||||
<tr><td>Character</td><td>Speech</td></tr>
|
||||
<tr><td>The multitude</td><td>The messiah! Show us the messiah!</td></tr>
|
||||
<tr><td>Brians mother</td><td><angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry></td></tr>
|
||||
<tr><td>The multitude</td><td>Who are you?</td></tr>
|
||||
<tr><td>Brians mother</td><td>I'm his mother; that's who!</td></tr>
|
||||
<tr><td>The multitude</td><td>Behold his mother! Behold his mother!</td></tr>
|
||||
</table>
|
||||
Loading…
Add table
Add a link
Reference in a new issue