-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.cs
83 lines (72 loc) · 2.39 KB
/
Utils.cs
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using System.Collections;
using System.Text.RegularExpressions;
public class Utils
{
public static string GetDelimitedString(ArrayList list, string delimiter) {
return String.Join(delimiter, (string[]) list.ToArray(typeof(string)));
}
public static ArrayList GetIntersection(ArrayList src, ArrayList dst) {
ArrayList intersectedlist = new ArrayList();
foreach (object s in src) {
if (dst.Contains(s)) intersectedlist.Add(s);
}
return intersectedlist;
}
// Just for string arrays.
public static bool IsStringArrayEqual(ArrayList a1, ArrayList a2) {
if (a1.Count != a2.Count) return false;
foreach (string str in a1) {
if (!a2.Contains(str)) return false;
}
return true;
}
public static ArrayList ParseTagsFromString(string tagstring) {
if (tagstring.Contains("\"")) return null;
string[] tokens = tagstring.Split(' ');
ArrayList tags = new ArrayList();
foreach (string token in tokens) {
if (!token.Trim().Equals("")) {
tags.Add(token.Trim());
}
}
return tags;
}
public static void EnsureDirectoryExists(string dir) {
System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(dir);
if (!dirInfo.Exists) {
dirInfo.Create();
Console.WriteLine("Created directory: " + dir);
}
}
public static bool FileNameExists(string filename) {
System.IO.FileInfo fileinfo = new System.IO.FileInfo(filename);
return fileinfo.Exists;
}
public static void IfExistsDeleteFile(string filename) {
System.IO.FileInfo fileinfo = new System.IO.FileInfo(filename);
if (fileinfo.Exists) {
fileinfo.Delete();
}
}
public static string EscapeForPango(string str) {
/*
if (str == null)
return "";
Regex r = new Regex("<[^>]+>");
str = r.Replace(str, "");
str = str.Replace ("&", "&");
str = str.Replace ("<", "<");
return str;
*/
return GLib.Markup.EscapeText(str);
}
public static bool isImageFile(string filepath) {
System.IO.FileInfo finfo = new System.IO.FileInfo(filepath);
if (!finfo.Exists) return false;
System.StringComparison comp = System.StringComparison.OrdinalIgnoreCase;
if (finfo.Extension.IndexOf("jpg", comp) > -1) return true;
if (finfo.Extension.IndexOf("png", comp) > -1) return true;
return false;
}
}