MCPcopy Index your code
hub / github.com/256dpi/gcode / StripComments

Function StripComments

tools.go:4–33  ·  view source on GitHub ↗

StripComments will remove all inline and line comments from file.

(f *File)

Source from the content-addressed store, hash-verified

2
3// StripComments will remove all inline and line comments from file.
4func 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.
36func OffsetXYZ(f *File, x, y, z float64) {

Callers 2

stripFunction · 0.92
TestStripCommentsFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestStripCommentsFunction · 0.68