diff --git a/Makefile b/Makefile index 5474dc2..e4e4162 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,9 @@ export GOPATH all: $(TARGETS) +%: src/%.go + go build $@ + %: %.go go build $< diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..be33ee9 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,3 @@ +all: +%: + $(MAKE) -C .. $@ diff --git a/src/fred/gaptest.go b/src/fred/gaptest.go new file mode 100644 index 0000000..7797da6 --- /dev/null +++ b/src/fred/gaptest.go @@ -0,0 +1,14 @@ +package main + +import ( + "fmt" + "netarch" +) + +func main() { + g := new(netarch.Gapstr) + g = g.AppendString("hello") + g = g.AppendGap(12) + g = g.AppendString("world") + fmt.Println("hi", g.String()) +} diff --git a/src/netarch/gapstr.go b/src/netarch/gapstr.go new file mode 100644 index 0000000..9ecc54e --- /dev/null +++ b/src/netarch/gapstr.go @@ -0,0 +1,40 @@ +package netarch + +import ( + "bytes" +) + +type chunk interface{} + +type Gapstr struct { + chunks []chunk +} + +func GapstrOfString(s string) *Gapstr { + return &Gapstr{[]chunk{s}} +} + +func (g *Gapstr) appendChunk(c chunk) *Gapstr { + return &Gapstr{append(g.chunks, c)} +} + +func (g *Gapstr) AppendString(s string) *Gapstr { + return g.appendChunk(s) +} + +func (g *Gapstr) AppendGap(len int) *Gapstr { + return g.appendChunk(len) +} + +func (g *Gapstr) String() string { + var b bytes.Buffer + for _, c := range g.chunks { + switch c.(type) { + case int: + b.Write(bytes.Repeat([]byte{0}, c.(int))) + case string: + b.WriteString(c.(string)) + } + } + return b.String() +} \ No newline at end of file