Add --header-lines option

This commit is contained in:
Junegunn Choi
2015-07-22 03:21:20 +09:00
parent 18469b6954
commit f469c25730
8 changed files with 143 additions and 77 deletions

View File

@@ -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