File tree Expand file tree Collapse file tree 5 files changed +12
-32
lines changed
compiled_starters/go/cmd/mygrep
starter_templates/go/code/cmd/mygrep Expand file tree Collapse file tree 5 files changed +12
-32
lines changed Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
- // Uncomment this to pass the first stage
5
- // "bytes"
4
+ "bytes"
6
5
"fmt"
7
6
"io"
8
7
"os"
9
8
"unicode/utf8"
10
9
)
11
10
11
+ // Ensures gofmt doesn't remove the "bytes" import above (feel free to remove this!)
12
+ var _ = bytes .ContainsAny
13
+
12
14
// Usage: echo <input_text> | your_program.sh -E <pattern>
13
15
func main () {
14
16
if len (os .Args ) < 3 || os .Args [1 ] != "-E" {
Original file line number Diff line number Diff line change 8
8
"unicode/utf8"
9
9
)
10
10
11
+ // Ensures gofmt doesn't remove the "bytes" import above (feel free to remove this!)
12
+ var _ = bytes .ContainsAny
13
+
11
14
// Usage: echo <input_text> | your_program.sh -E <pattern>
12
15
func main () {
13
16
if len (os .Args ) < 3 || os .Args [1 ] != "-E" {
Original file line number Diff line number Diff line change 1
- @@ -1,54 +1,49 @@
2
- package main
3
-
4
- import (
5
- - // Uncomment this to pass the first stage
6
- - // "bytes"
7
- + "bytes"
8
- "fmt"
9
- "io"
10
- "os"
11
- "unicode/utf8"
12
- )
13
-
14
- // Usage: echo <input_text> | your_program.sh -E <pattern>
15
- func main() {
16
- if len(os.Args) < 3 || os.Args[1] != "-E" {
17
- fmt.Fprintf(os.Stderr, "usage: mygrep -E <pattern>\n")
18
- os.Exit(2) // 1 means no lines were selected, >1 means error
19
- }
20
-
21
- pattern := os.Args[2]
22
-
23
- line, err := io.ReadAll(os.Stdin) // assume we're only dealing with a single line
1
+ @@ -24,33 +24,29 @@
24
2
if err != nil {
25
3
fmt.Fprintf(os.Stderr, "error: read input text: %v\n", err)
26
4
os.Exit(2)
Original file line number Diff line number Diff line change @@ -2,11 +2,6 @@ The entry point for your grep implementation is in `cmd/mygrep/main.go`.
2
2
3
3
Study and uncomment the relevant code:
4
4
5
- ``` go
6
- // Uncomment this to pass the first stage
7
- " bytes"
8
- ```
9
-
10
5
``` go
11
6
// Uncomment this to pass the first stage
12
7
ok = bytes.ContainsAny (line, pattern)
Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
- // Uncomment this to pass the first stage
5
- // "bytes"
4
+ "bytes"
6
5
"fmt"
7
6
"io"
8
7
"os"
9
8
"unicode/utf8"
10
9
)
11
10
11
+ // Ensures gofmt doesn't remove the "bytes" import above (feel free to remove this!)
12
+ var _ = bytes .ContainsAny
13
+
12
14
// Usage: echo <input_text> | your_program.sh -E <pattern>
13
15
func main () {
14
16
if len (os .Args ) < 3 || os .Args [1 ] != "-E" {
You can’t perform that action at this time.
0 commit comments