-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClipboardUtils.hx
60 lines (54 loc) · 1.62 KB
/
ClipboardUtils.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package haxe.extension;
class ClipboardUtils {
/**
* Build a html clibboard
* @param input string
* @return String in the correct clipboard format
*/
public static function formatHTML(input:String):String
{
var len = input.length;
var output = "Version:0.9\n";
output += "StartHTML:0000000105\n";
output += "EndHTML:" + formatIndex(105, len) + "\n";
output += "StartFragment:0000000141\n";
output += "EndFragment:" + formatIndex(141, len) + "\n";
output += "<html>\n";
output += "<body>\n";
output += "<!--StartFragment-->" + input + "<!--EndFragment-->\n";
output += "</body>\n";
output += "</html>\n";
return output;
}
public static function getString(str:String, format:EClipboard = HTML):String
{
if(str != "")
{
switch(format)
{
case HTML:
var begin = str.indexOf("<!--StartFragment-->");
var end = str.indexOf("<!--EndFragment-->");
return str.substring(begin + 20, end);
case SVG:
var end = str.indexOf("</svg>");
return str.substring(0, end + 6);
default:
return str;
}
}
return str;
}
static function formatIndex(start:Int, len:Int):String
{
var str:String = "";
var fullLen = start + len;
var fStr = Std.string(fullLen);
for(i in fStr.length...10)
{
str += "0";
}
str += fStr;
return str;
}
}