MCPcopy Index your code
hub / github.com/cli/cli / Write

Method Write

pkg/cmd/pr/create/regexp_writer.go:20–52  ·  view source on GitHub ↗
(data []byte)

Source from the content-addressed store, hash-verified

18}
19
20func (s *RegexpWriter) Write(data []byte) (int, error) {
21 if len(data) == 0 {
22 return 0, nil
23 }
24
25 filtered := []byte{}
26 repl := []byte(s.repl)
27 lines := bytes.SplitAfter(data, []byte("\n"))
28
29 if len(s.buf) > 0 {
30 lines[0] = append(s.buf, lines[0]...)
31 }
32
33 for i, line := range lines {
34 if i == len(lines) {
35 s.buf = line
36 } else {
37 f := s.re.ReplaceAll(line, repl)
38 if len(f) > 0 {
39 filtered = append(filtered, f...)
40 }
41 }
42 }
43
44 if len(filtered) != 0 {
45 _, err := s.out.Write(filtered)
46 if err != nil {
47 return 0, err
48 }
49 }
50
51 return len(data), nil
52}
53
54func (s *RegexpWriter) Flush() (int, error) {
55 if len(s.buf) > 0 {

Callers 1

Test_WriteFunction · 0.95

Calls 1

WriteMethod · 0.65

Tested by 1

Test_WriteFunction · 0.76