// ------------------------------------------------------------------------------
//
// This code was generated by a tool.
// Mono Runtime Version: 2.0.50727.1433
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
// ------------------------------------------------------------------------------
namespace TableConfig
{
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
using System.Threading;
public partial class DirtyWordConfig : ConfigBase, IConfigPostProcess
{
private static WordGroup[] DIRTYWORLD = new WordGroup[(int)char.MaxValue];
private static List memoryList = new List();
private static bool inited = false;
static int cursor = 0;
static int wordlenght = 0;
static int nextCursor = 0;
public void OnConfigParseCompleted()
{
string key = ToDBC(word);
memoryList.Add(key);
}
private static string ToDBC(string input)
{
char[] c = input.ToCharArray();
for (int i = 0; i < c.Length; i++)
{
if (c[i] == 12288)
{
c[i] = (char)32;
continue;
}
if (c[i] > 65280 && c[i] < 65375)
c[i] = (char)(c[i] - 65248);
}
return new string(c).ToLower();
}
public static string IsDirtWord(string source, char filter)
{
if (!inited)
{
Init();
}
if (source != string.Empty)
{
cursor = 0;
nextCursor = 0;
char[] temp = source.ToCharArray();
source = FitterSpecial(source);
for (int i = 0; i < source.Length; i++)
{
//²éѯÒÔ¸Ã×ÖΪÊ××Ö·ûµÄ´Ê×é
WordGroup group = DIRTYWORLD[(int)ToDBC(source)[i]];
if (group != null)
{
for (int z = 0; z < group.Count(); z++)
{
string word = group.GetWord(z);
if (word.Length == 0 || Check(word, source))
{
string blackword = string.Empty;
for (int pos = 0; pos < wordlenght + 1; pos++)
{
try
{
blackword += temp[pos + cursor].ToString();
temp[pos + cursor] = filter;
}
catch (Exception e)
{
DebugEx.Log(e.Message);
}
}
cursor = cursor + wordlenght;
i = i + wordlenght;
}
}
}
cursor++;
}
return new string(temp);
}
return string.Empty;
}
public static bool IsDirtWord(string source)
{
if (!inited)
{
Init();
}
if (source != string.Empty)
{
cursor = 0;
nextCursor = 0;
for (int i = 0; i < source.Length; i++)
{
//²éѯÒÔ¸Ã×ÖΪÊ××Ö·ûµÄ´Ê×é
WordGroup group = DIRTYWORLD[(int)ToDBC(source)[i]];
if (group != null)
{
for (int z = 0; z < group.Count(); z++)
{
string word = group.GetWord(z);
if (word.Length == 0 || Check(word, source))
{
return true;
}
}
}
cursor++;
}
}
return false;
}
private static bool Check(string blackWord, string source)
{
wordlenght = 0;
int wordCnt = 0;
//¼ì²âÔ´ÏÂһλÓαê
nextCursor = cursor + 1;
bool found = false;
//±éÀú´ÊµÄÿһλ×öÆ¥Åä
for (int i = 0; i < blackWord.Length; i++)
{
//ÌØÊâ×Ö·ûÆ«ÒÆÓαê
int offset = 0;
if (nextCursor >= source.Length)
{
break;
}
else
{
//¼ì²âÏÂλ×Ö·ûÈç¹û²»ÊǺº×Ö Êý×Ö ×Ö·û Æ«ÒÆÁ¿¼Ó1,,¹ýÂËÌØÊâ×Ö·û
for (int y = nextCursor; y < source.Length; y++)
{
//if (!IsCHS(source[y]) && !IsNum(source[y]) && !IsAlphabet(source[y])) {
if (IsSpecial(source[y]))
{
offset++;
//±ÜÈÃÌØÊâ×Ö·û£¬ÏÂλÓαêÈç¹û>=×Ö·û´®³¤¶È Ìø³ö
if (nextCursor + offset >= source.Length) break;
wordlenght++;
}
else break;
}
if (nextCursor + offset >= source.Length)
{
break;
}
if ((int)blackWord[i] == (int)source[nextCursor + offset])
{
wordCnt++;
found = true;
}
else
{
found = false;
break;
}
}
nextCursor = nextCursor + 1 + offset;
wordlenght++;
}
if (blackWord.Length != wordCnt) return false;
return found;
}
private static bool IsSpecial(char character)
{
if (character == ' ')
{
return true;
}
return false;
}
static public void Init()
{
if (inited)
{
return;
}
inited = true;
ThreadPool.QueueUserWorkItem((object aaa) =>
{
memoryList.Sort((string x, string y) =>
{
return x.CompareTo(y);
});
for (int i = memoryList.Count - 1; i > 0; i--)
{
if (memoryList[i].ToString() == memoryList[i - 1].ToString())
{
memoryList.RemoveAt(i);
}
}
foreach (string word in memoryList)
{
WordGroup group = DIRTYWORLD[(int)word[0]];
if (group == null)
{
group = new WordGroup();
DIRTYWORLD[(int)word[0]] = group;
}
group.Add(word.Substring(1));
}
});
}
public static bool IsCHS(char character)
{
// ÖÐÎıíÒâ×Ö·ûµÄ·¶Î§ 4E00-9FA5
int charVal = (int)character;
return (charVal >= 0x4e00 && charVal <= 0x9fa5);
}
private static bool IsNum(char character)
{
int charVal = (int)character;
return (charVal >= 48 && charVal <= 57);
}
private static bool IsAlphabet(char character)
{
int charVal = (int)character;
return ((charVal >= 97 && charVal <= 122) || (charVal >= 65 && charVal <= 90));
}
private const string FACE_REPLACE = @"#~[0-9a-zA-Z]{1,3}";
private static Regex FaceRegex = new Regex(FACE_REPLACE, RegexOptions.Singleline);
public static string FitterSpecial(string source)
{
return FaceRegex.Replace(source, " ");
}
}
class WordGroup
{
private List groupList;
public WordGroup()
{
groupList = new List();
}
public void Add(string word)
{
groupList.Add(word);
}
public int Count()
{
return groupList.Count;
}
public string GetWord(int index)
{
return groupList[index];
}
}
}