Process records, slicing src field and saving the result to the dest field
(r baker.Record, next func(baker.Record))
| 61 | |
| 62 | // Process records, slicing src field and saving the result to the dest field |
| 63 | func (f *Slice) Process(r baker.Record, next func(baker.Record)) { |
| 64 | src := r.Get(f.src) |
| 65 | |
| 66 | // if end is 0 or greater than the field => end = len(field) |
| 67 | end := f.endIdx |
| 68 | if end > len(src) || end == 0 { |
| 69 | end = len(src) |
| 70 | } |
| 71 | |
| 72 | // if start is greater or equal the length of the field, then we write an empty result |
| 73 | start := f.startIdx |
| 74 | if start >= len(src) { |
| 75 | start = len(src) |
| 76 | } |
| 77 | |
| 78 | var empty []byte |
| 79 | r.Set(f.dst, append(empty, src[start:end]...)) |
| 80 | |
| 81 | next(r) |
| 82 | } |
| 83 | |
| 84 | // Stats implements baker.Filter. |
| 85 | func (f *Slice) Stats() baker.FilterStats { |