Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 "remoting/host/clipboard_util.h" | |
| 6 | |
| 7 namespace remoting { | |
| 8 | |
| 9 std::string ClipboardUtil::ReplaceLfByCrLf(const std::string& in) { | |
|
Wez
2012/05/31 22:36:41
This and the reverse can be implemented with Repla
| |
| 10 std::string out; | |
| 11 out.resize(2 * in.size()); | |
| 12 char* out_p_begin = &out[0]; | |
| 13 char* out_p = out_p_begin; | |
| 14 const char* in_p_begin = &in[0]; | |
| 15 const char* in_p_end = &in[in.size()]; | |
| 16 for (const char* in_p = in_p_begin; in_p < in_p_end; ++in_p) { | |
| 17 char c = *in_p; | |
| 18 if (c == '\n') { | |
| 19 *out_p++ = '\r'; | |
| 20 } | |
| 21 *out_p++ = c; | |
| 22 } | |
| 23 out.resize(out_p - out_p_begin); | |
| 24 return out; | |
| 25 } | |
| 26 | |
| 27 std::string ClipboardUtil::ReplaceCrLfByLf(const std::string& in) { | |
| 28 std::string out; | |
| 29 out.resize(in.size()); | |
| 30 char* out_p_begin = &out[0]; | |
| 31 char* out_p = out_p_begin; | |
| 32 const char* in_p_begin = &in[0]; | |
| 33 const char* in_p_end = &in[in.size()]; | |
| 34 for (const char* in_p = in_p_begin; in_p < in_p_end; ++in_p) { | |
| 35 char c = *in_p; | |
| 36 if ((c == '\r') && (in_p + 1 < in_p_end) && (*(in_p + 1) == '\n')) { | |
| 37 *out_p++ = '\n'; | |
| 38 ++in_p; | |
| 39 } else { | |
| 40 *out_p++ = c; | |
| 41 } | |
| 42 } | |
| 43 out.resize(out_p - out_p_begin); | |
| 44 return out; | |
| 45 } | |
| 46 | |
| 47 } // namespace remoting | |
| OLD | NEW |