OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/password_manager/proxy/message_reader.h" |
| 6 |
| 7 // This library is part of a very small helper binary that runs without any |
| 8 // dependencies on base. Thus we can't use normal logging; we use assert. |
| 9 #include <assert.h> |
| 10 |
| 11 size_t MessageReader::HandleData(const char* data, size_t size) { |
| 12 assert(!is_complete_); |
| 13 size_t used = 0; |
| 14 while (used < size) { |
| 15 size_t end; |
| 16 for (end = used; end < size && data[end] != '\n'; ++end) {} |
| 17 lines_.back().append(&data[used], end - used); |
| 18 if (end < size) { |
| 19 // We found a newline. Skip past it and figure out what to do. |
| 20 used = end + 1; |
| 21 if (lines_.back().size() > 0) { |
| 22 // The previous line was not empty. Start a new one. |
| 23 lines_.resize(lines_.size() + 1); |
| 24 } else { |
| 25 // If the previous line was empty, this message is complete. |
| 26 lines_.resize(lines_.size() - 1); |
| 27 is_complete_ = true; |
| 28 break; |
| 29 } |
| 30 } else { |
| 31 // There was no newline, just the end of the input. Skip to the end. |
| 32 used = end; |
| 33 } |
| 34 } |
| 35 return used; |
| 36 } |
OLD | NEW |