ModIndexer/Misc.cs

94 lines
1.8 KiB
C#

using System;
using System.Text;
namespace ModIndexer
{
public static class Misc
{
// Including the forum number as value
public enum FETCH_TYPE
{
REL_MODS = 11,
WIP_MODS = 9,
REL_GAMES = 15,
WIP_GAMES = 50,
OLD_MODS = 13
}
// The number in the database for the type
public enum DATA_TYPE
{
INVALID = 0,
REL_MOD = 1,
REL_MP = 2,
WIP_MOD = 3,
WIP_MP = 4,
OLD_MOD = 5,
REL_GAME = 6,
WIP_GAME = 7
}
// Convert special characters to HTML code
public static string EscapeXML(this string t)
{
char[] fromCr = { '"', '\'', '\\', '{', '}', '|', '%', ':', '<', '>' };
string[] toStr = { "&quot;", "&#39;", "&#92;", "&#123;", "&#125;", "&#124;", "&#37;", "&#58;", "&lt;", "&gt;" };
StringBuilder sb = new StringBuilder();
bool wasSpace = true;
for (int i = 0; i < t.Length; i++) {
char cur = t[i];
bool isSpace = char.IsWhiteSpace(cur);
if (wasSpace && isSpace)
continue;
// Cut off non-ASCII
if ((ushort)t[i] > 0xFF)
continue;
bool found = false;
for (int k = 0; k < fromCr.Length; k++) {
if (cur == fromCr[k]) {
sb.Append(toStr[k]);
found = true;
break;
}
}
wasSpace = isSpace;
if (!found)
sb.Append(cur);
}
return sb.ToString();
}
public static int IndexOf<T>(this T[] me, T value)
{
for (int i = 0; i < me.Length; i++)
if (me[i].Equals(value))
return i;
return -1;
}
}
class ForumData
{
public int topicId, userId, type;
public string title, userName, link;
public ForumData(int topicId, string title, int type,
int userId, string userName, string link)
{
this.topicId = topicId;
this.title = title;
this.type = type;
this.userId = userId;
this.userName = userName;
this.link = link;
}
}
}