upcomingHeaderKeys returns an approximation of the number of keys that will be in this header. If it gets confused, it returns 0.
()
| 330 | // upcomingHeaderKeys returns an approximation of the number of keys |
| 331 | // that will be in this header. If it gets confused, it returns 0. |
| 332 | func (r *textprotoReader) upcomingHeaderKeys() (n int) { |
| 333 | // Try to determine the 'hint' size. |
| 334 | r.R.Peek(1) // force a buffer load if empty |
| 335 | s := r.R.Buffered() |
| 336 | if s == 0 { |
| 337 | return |
| 338 | } |
| 339 | peek, _ := r.R.Peek(s) |
| 340 | for len(peek) > 0 && n < 1000 { |
| 341 | var line []byte |
| 342 | line, peek, _ = bytes.Cut(peek, nl) |
| 343 | if len(line) == 0 || (len(line) == 1 && line[0] == '\r') { |
| 344 | // Blank line separating headers from the body. |
| 345 | break |
| 346 | } |
| 347 | if line[0] == ' ' || line[0] == '\t' { |
| 348 | // Folded continuation of the previous line. |
| 349 | continue |
| 350 | } |
| 351 | n++ |
| 352 | } |
| 353 | return n |
| 354 | } |
| 355 | |
| 356 | const toLower = 'a' - 'A' |
| 357 |