Chromium Code Reviews| Index: remoting/host/clipboard_util.cc |
| diff --git a/remoting/host/clipboard_util.cc b/remoting/host/clipboard_util.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..87ef7cf1f09ae31827a92d6a8d0ca159a6e39537 |
| --- /dev/null |
| +++ b/remoting/host/clipboard_util.cc |
| @@ -0,0 +1,47 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "remoting/host/clipboard_util.h" |
| + |
| +namespace remoting { |
| + |
| +std::string ClipboardUtil::ReplaceLfByCrLf(const std::string& in) { |
|
Wez
2012/05/31 22:36:41
This and the reverse can be implemented with Repla
|
| + std::string out; |
| + out.resize(2 * in.size()); |
| + char* out_p_begin = &out[0]; |
| + char* out_p = out_p_begin; |
| + const char* in_p_begin = &in[0]; |
| + const char* in_p_end = &in[in.size()]; |
| + for (const char* in_p = in_p_begin; in_p < in_p_end; ++in_p) { |
| + char c = *in_p; |
| + if (c == '\n') { |
| + *out_p++ = '\r'; |
| + } |
| + *out_p++ = c; |
| + } |
| + out.resize(out_p - out_p_begin); |
| + return out; |
| +} |
| + |
| +std::string ClipboardUtil::ReplaceCrLfByLf(const std::string& in) { |
| + std::string out; |
| + out.resize(in.size()); |
| + char* out_p_begin = &out[0]; |
| + char* out_p = out_p_begin; |
| + const char* in_p_begin = &in[0]; |
| + const char* in_p_end = &in[in.size()]; |
| + for (const char* in_p = in_p_begin; in_p < in_p_end; ++in_p) { |
| + char c = *in_p; |
| + if ((c == '\r') && (in_p + 1 < in_p_end) && (*(in_p + 1) == '\n')) { |
| + *out_p++ = '\n'; |
| + ++in_p; |
| + } else { |
| + *out_p++ = c; |
| + } |
| + } |
| + out.resize(out_p - out_p_begin); |
| + return out; |
| +} |
| + |
| +} // namespace remoting |