2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2012-06-10 16:50:54 +00:00
|
|
|
*/
|
|
|
|
|
|
2014-02-28 12:36:45 +00:00
|
|
|
#include "platform/OSXClipboardAnyTextConverter.h"
|
|
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
|
|
//
|
2014-11-11 13:51:47 +00:00
|
|
|
// OSXClipboardAnyTextConverter
|
2012-06-10 16:50:54 +00:00
|
|
|
//
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
OSXClipboardAnyTextConverter::OSXClipboardAnyTextConverter()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
// do nothing
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
OSXClipboardAnyTextConverter::~OSXClipboardAnyTextConverter()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
// do nothing
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
IClipboard::EFormat OSXClipboardAnyTextConverter::getFormat() const
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
return IClipboard::kText;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string OSXClipboardAnyTextConverter::fromIClipboard(const std::string &data) const
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
// convert linefeeds and then convert to desired encoding
|
|
|
|
|
return doFromIClipboard(convertLinefeedToMacOS(data));
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string OSXClipboardAnyTextConverter::toIClipboard(const std::string &data) const
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
// convert text then newlines
|
|
|
|
|
return convertLinefeedToUnix(doToIClipboard(data));
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
static bool isLF(char ch)
|
|
|
|
|
{
|
|
|
|
|
return (ch == '\n');
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
static bool isCR(char ch)
|
|
|
|
|
{
|
|
|
|
|
return (ch == '\r');
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string OSXClipboardAnyTextConverter::convertLinefeedToMacOS(const std::string &src)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
// note -- we assume src is a valid UTF-8 string
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string copy = src;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
std::replace_if(copy.begin(), copy.end(), isLF, '\r');
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
return copy;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string OSXClipboardAnyTextConverter::convertLinefeedToUnix(const std::string &src)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string copy = src;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
std::replace_if(copy.begin(), copy.end(), isCR, '\n');
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
return copy;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|