Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Unified Diff: remoting/base/util.cc

Issue 10441131: [Chromoting] Handle CR-LF correctly when transferring text items to and from the clipboard on a Win… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add a static_cast to a unit test. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/base/util.h ('k') | remoting/base/util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/base/util.cc
diff --git a/remoting/base/util.cc b/remoting/base/util.cc
index b126f1547d43406baa4b7df910a6545e0c831481..efc27d0557f0c5cedce141946d779692278d3270 100644
--- a/remoting/base/util.cc
+++ b/remoting/base/util.cc
@@ -265,4 +265,42 @@ void CopyRGB32Rect(const uint8* source_buffer,
SkIRect::MakeWH(dest_rect.width(), dest_rect.height()));
}
+std::string ReplaceLfByCrLf(const std::string& in) {
+ 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 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
« no previous file with comments | « remoting/base/util.h ('k') | remoting/base/util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698