OLD | NEW |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package textproto | 5 package textproto |
6 | 6 |
7 import ( | 7 import ( |
8 "bufio" | 8 "bufio" |
9 "bytes" | 9 "bytes" |
10 "io" | 10 "io" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 if line != nil { | 43 if line != nil { |
44 buf := make([]byte, len(line)) | 44 buf := make([]byte, len(line)) |
45 copy(buf, line) | 45 copy(buf, line) |
46 line = buf | 46 line = buf |
47 } | 47 } |
48 return line, err | 48 return line, err |
49 } | 49 } |
50 | 50 |
51 func (r *Reader) readLineSlice() ([]byte, os.Error) { | 51 func (r *Reader) readLineSlice() ([]byte, os.Error) { |
52 r.closeDot() | 52 r.closeDot() |
53 » line, _, err := r.R.ReadLine() | 53 » var line []byte |
54 » return line, err | 54 » for { |
| 55 » » l, more, err := r.R.ReadLine() |
| 56 » » if err != nil { |
| 57 » » » return nil, err |
| 58 » » } |
| 59 » » // Avoid the copy if the first call produced a full line. |
| 60 » » if line == nil && !more { |
| 61 » » » return l, nil |
| 62 » » } |
| 63 » » line = append(line, l...) |
| 64 » » if !more { |
| 65 » » » break |
| 66 » » } |
| 67 » } |
| 68 » return line, nil |
55 } | 69 } |
56 | 70 |
57 // ReadContinuedLine reads a possibly continued line from r, | 71 // ReadContinuedLine reads a possibly continued line from r, |
58 // eliding the final trailing ASCII white space. | 72 // eliding the final trailing ASCII white space. |
59 // Lines after the first are considered continuations if they | 73 // Lines after the first are considered continuations if they |
60 // begin with a space or tab character. In the returned data, | 74 // begin with a space or tab character. In the returned data, |
61 // continuation lines are separated from the previous line | 75 // continuation lines are separated from the previous line |
62 // only by a single space: the newline and leading white space | 76 // only by a single space: the newline and leading white space |
63 // are removed. | 77 // are removed. |
64 // | 78 // |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 if upper && 'a' <= v && v <= 'z' { | 536 if upper && 'a' <= v && v <= 'z' { |
523 a[i] = v + 'A' - 'a' | 537 a[i] = v + 'A' - 'a' |
524 } | 538 } |
525 if !upper && 'A' <= v && v <= 'Z' { | 539 if !upper && 'A' <= v && v <= 'Z' { |
526 a[i] = v + 'a' - 'A' | 540 a[i] = v + 'a' - 'A' |
527 } | 541 } |
528 upper = v == '-' | 542 upper = v == '-' |
529 } | 543 } |
530 return string(a) | 544 return string(a) |
531 } | 545 } |
OLD | NEW |