StripComments will remove all inline and line comments from file.
(f *File)
| 2 | |
| 3 | // StripComments will remove all inline and line comments from file. |
| 4 | func StripComments(f *File) { |
| 5 | cl := 0 |
| 6 | for i := range f.Lines { |
| 7 | j := i - cl |
| 8 | l := f.Lines[j] |
| 9 | |
| 10 | cd := 0 |
| 11 | for ii := range l.Codes { |
| 12 | jj := ii - cd |
| 13 | c := l.Codes[jj] |
| 14 | |
| 15 | // remove codes with comments |
| 16 | if c.Comment != "" { |
| 17 | l.Codes = append(l.Codes[:jj], l.Codes[jj+1:]...) |
| 18 | cd++ |
| 19 | continue |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | // remove lines with comments or no codes |
| 24 | if l.Comment != "" || len(l.Codes) == 0 { |
| 25 | f.Lines = append(f.Lines[:j], f.Lines[j+1:]...) |
| 26 | cl++ |
| 27 | continue |
| 28 | } |
| 29 | |
| 30 | // update line |
| 31 | f.Lines[j] = l |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | // OffsetXYZ will offset all X, Y and Z G-Code values by the specified values. |
| 36 | func OffsetXYZ(f *File, x, y, z float64) { |
no outgoing calls