From f469c25730aaa711b8327be068514c944074cce4 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 22 Jul 2015 03:21:20 +0900 Subject: Add --header-lines option --- src/chunklist.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/chunklist.go') diff --git a/src/chunklist.go b/src/chunklist.go index 52084f2f..ee52d321 100644 --- a/src/chunklist.go +++ b/src/chunklist.go @@ -26,8 +26,13 @@ func NewChunkList(trans ItemBuilder) *ChunkList { trans: trans} } -func (c *Chunk) push(trans ItemBuilder, data *string, index int) { - *c = append(*c, trans(data, index)) +func (c *Chunk) push(trans ItemBuilder, data *string, index int) bool { + item := trans(data, index) + if item != nil { + *c = append(*c, item) + return true + } + return false } // IsFull returns true if the Chunk is full @@ -48,7 +53,7 @@ func CountItems(cs []*Chunk) int { } // Push adds the item to the list -func (cl *ChunkList) Push(data string) { +func (cl *ChunkList) Push(data string) bool { cl.mutex.Lock() defer cl.mutex.Unlock() @@ -57,8 +62,11 @@ func (cl *ChunkList) Push(data string) { cl.chunks = append(cl.chunks, &newChunk) } - cl.lastChunk().push(cl.trans, &data, cl.count) - cl.count++ + if cl.lastChunk().push(cl.trans, &data, cl.count) { + cl.count++ + return true + } + return false } // Snapshot returns immutable snapshot of the ChunkList -- cgit v1.2.3