// "Therefore those skilled at the unorthodox
// are infinite as heaven and earth,
// inexhaustible as the great rivers.
// When they come to an end,
// they begin again,
// like the days and months;
// they die and are reborn,
// like the four seasons."
//
// - Sun Tsu,
// "The Art of War"
using System;
using System.Text;
using System.Windows.Forms;
namespace TheArtOfDev.HtmlRenderer.WinForms.Utilities
{
///
/// Helper to encode and set HTML fragment to clipboard.
/// See http://theartofdev.wordpress.com/2012/11/11/setting-html-and-plain-text-formatting-to-clipboard/.
/// .
///
///
/// The MIT License (MIT) Copyright (c) 2014 Arthur Teplitzki.
///
internal static class ClipboardHelper
{
#region Fields and Consts
///
/// The string contains index references to other spots in the string, so we need placeholders so we can compute the offsets.
/// The _ strings are just placeholders. We'll back-patch them actual values afterwards.
/// The string layout () also ensures that it can't appear in the body of the html because the
/// character must be escaped.
///
private const string Header = @"Version:0.9
StartHTML:<<<<<<<<1
EndHTML:<<<<<<<<2
StartFragment:<<<<<<<<3
EndFragment:<<<<<<<<4
StartSelection:<<<<<<<<3
EndSelection:<<<<<<<<4";
///
/// html comment to point the beginning of html fragment
///
public const string StartFragment = "";
///
/// html comment to point the end of html fragment
///
public const string EndFragment = @"";
///
/// Used to calculate characters byte count in UTF-8
///
private static readonly char[] _byteCount = new char[1];
#endregion
///
/// Create with given html and plain-text ready to be used for clipboard or drag and drop.
/// Handle missing ]]> tags, specified start\end segments and Unicode characters.
///
///
///
/// Windows Clipboard works with UTF-8 Unicode encoding while .NET strings use with UTF-16 so for clipboard to correctly
/// decode Unicode string added to it from .NET we needs to be re-encoded it using UTF-8 encoding.
///
///
/// Builds the CF_HTML header correctly for all possible HTMLs
/// If given html contains start/end fragments then it will use them in the header:
/// hello world