00001 /* 00002 * synergy -- mouse and keyboard sharing utility 00003 * Copyright (C) 2004 Chris Schoeneman 00004 * 00005 * This package is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * found in the file COPYING that should have accompanied this file. 00008 * 00009 * This package is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 */ 00014 00015 #include "COSXClipboardAnyTextConverter.h" 00016 #include <algorithm> 00017 00018 // 00019 // COSXClipboardAnyTextConverter 00020 // 00021 00022 COSXClipboardAnyTextConverter::COSXClipboardAnyTextConverter() 00023 { 00024 // do nothing 00025 } 00026 00027 COSXClipboardAnyTextConverter::~COSXClipboardAnyTextConverter() 00028 { 00029 // do nothing 00030 } 00031 00032 IClipboard::EFormat 00033 COSXClipboardAnyTextConverter::getFormat() const 00034 { 00035 return IClipboard::kText; 00036 } 00037 00038 CString 00039 COSXClipboardAnyTextConverter::fromIClipboard(const CString& data) const 00040 { 00041 // convert linefeeds and then convert to desired encoding 00042 return doFromIClipboard(convertLinefeedToMacOS(data)); 00043 } 00044 00045 CString 00046 COSXClipboardAnyTextConverter::toIClipboard(const CString& data) const 00047 { 00048 // convert text then newlines 00049 return convertLinefeedToUnix(doToIClipboard(data)); 00050 } 00051 00052 static 00053 bool 00054 isLF(char ch) 00055 { 00056 return (ch == '\n'); 00057 } 00058 00059 static 00060 bool 00061 isCR(char ch) 00062 { 00063 return (ch == '\r'); 00064 } 00065 00066 CString 00067 COSXClipboardAnyTextConverter::convertLinefeedToMacOS(const CString& src) 00068 { 00069 // note -- we assume src is a valid UTF-8 string 00070 CString copy = src; 00071 00072 std::replace_if(copy.begin(), copy.end(), isLF, '\r'); 00073 00074 return copy; 00075 } 00076 00077 CString 00078 COSXClipboardAnyTextConverter::convertLinefeedToUnix(const CString& src) 00079 { 00080 CString copy = src; 00081 00082 std::replace_if(copy.begin(), copy.end(), isCR, '\n'); 00083 00084 return copy; 00085 }