ezpz case actually looks ok
parent
683bd62b87
commit
3dde3a723a
31
main.go
31
main.go
|
|
@ -3,7 +3,6 @@ package main
|
|||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"flag"
|
||||
"io"
|
||||
"os"
|
||||
|
|
@ -57,14 +56,36 @@ func _readPage(d byte, r *bufio.Reader) ([]byte, error) {
|
|||
}
|
||||
|
||||
func putPage(b []byte) error {
|
||||
return _putPage(stdout, b)
|
||||
return _putPage(stdout, b, []byte(columnDelimiter)[0], minimumInstances)
|
||||
}
|
||||
|
||||
func _putPage(w io.Writer, b []byte) error {
|
||||
func _putPage(w io.Writer, b []byte, d byte, instances int) error {
|
||||
nonFirstColumn := []byte{}
|
||||
for _, line := range lines(b) {
|
||||
_ = line
|
||||
//line = bytes.TrimSpace(line)
|
||||
i := 0
|
||||
for i < len(line) && line[i] == d {
|
||||
i += 1
|
||||
}
|
||||
for i < len(line) {
|
||||
j := 0
|
||||
for j+i < len(line) && line[i+j] == d {
|
||||
j += 1
|
||||
}
|
||||
if j >= instances {
|
||||
nonFirstColumn = append(nonFirstColumn, line[i+j:]...)
|
||||
line = line[:i+j]
|
||||
break
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
w.Write(line)
|
||||
w.Write([]byte{'\n'})
|
||||
}
|
||||
return errors.New("not impl")
|
||||
if len(nonFirstColumn) > 0 {
|
||||
return _putPage(w, nonFirstColumn, d, instances)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func lines(b []byte) [][]byte {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ import (
|
|||
)
|
||||
|
||||
func Test_Main(t *testing.T) {
|
||||
stdin = strings.NewReader("\ta a a\t\tb b b\na a\t\tb b\fc c\td d\nc c\td.")
|
||||
input := "\ta a a\t\tb b b\na a\t\tb b\fc c\td d\nc c\td."
|
||||
stdin = strings.NewReader(input)
|
||||
stdout = bytes.NewBuffer(nil)
|
||||
columnDelimiter = "\t"
|
||||
pageDelimiter = "\f"
|
||||
|
|
@ -18,7 +19,8 @@ func Test_Main(t *testing.T) {
|
|||
if err := _main(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
t.Errorf("%s", stdout.(*bytes.Buffer).Bytes())
|
||||
t.Logf("input:\n%s", input)
|
||||
t.Errorf("result:\n%s", stdout.(*bytes.Buffer).Bytes())
|
||||
}
|
||||
|
||||
func TestReadPage(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue