using System;  
 | 
    using System.Collections.Generic;  
 | 
    using System.Text.RegularExpressions;  
 | 
    using UnityEngine;  
 | 
    using System.Threading;  
 | 
  
 | 
    public partial class DirtyWordConfig :  IConfigPostProcess  
 | 
    {  
 | 
  
 | 
        private static WordGroup[] DIRTYWORLD = new WordGroup[(int)char.MaxValue];  
 | 
  
 | 
        private static List<string> memoryList = new List<string>();  
 | 
  
 | 
        private static bool dirtyWordInited = false;  
 | 
  
 | 
        static int cursor = 0;  
 | 
  
 | 
        static int wordlenght = 0;  
 | 
  
 | 
        static int nextCursor = 0;  
 | 
  
 | 
        public void OnConfigParseCompleted()  
 | 
        {  
 | 
            if (string.IsNullOrEmpty(word))  
 | 
            {  
 | 
                Debug.LogErrorFormat("ÆÁ±Î×Ö id = {0} µÄÄÚÈÝΪ¿Õ ÐèÒªÐÞ¸Ä", id);  
 | 
                return;  
 | 
            }  
 | 
            var tmpword = word.Replace(" ", "");  
 | 
            string key = ToDBC(tmpword);  
 | 
            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 (!dirtyWordInited)  
 | 
            {  
 | 
                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 (!dirtyWordInited)  
 | 
            {  
 | 
                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 (blackWord[i] == char.ToLower(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 DirtyWordInit()  
 | 
        {  
 | 
            if (dirtyWordInited)  
 | 
            {  
 | 
                return;  
 | 
            }  
 | 
  
 | 
            dirtyWordInited = 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<string> groupList;  
 | 
  
 | 
        public WordGroup()  
 | 
        {  
 | 
            groupList = new List<string>();  
 | 
        }  
 | 
  
 | 
        public void Add(string word)  
 | 
        {  
 | 
            groupList.Add(word);  
 | 
        }  
 | 
  
 | 
        public int Count()  
 | 
        {  
 | 
            return groupList.Count;  
 | 
        }  
 | 
  
 | 
        public string GetWord(int index)  
 | 
        {  
 | 
            return groupList[index];  
 | 
        }  
 | 
    }  
 |