using UnityEngine;
using System.Collections.Generic;
public class MaskWordManager{
private static MaskWordManager mIns;
private MaskWordManager(){}
public static MaskWordManager GetMaskWordManagerInstance()
{
if(mIns ==null)
{
mIns =new MaskWordManager();
}
return mIns;
}
private int MaxLen =50;
public void InitMaskWords()
{
TextAsset maskwords= Resources.Load("MaskWord") as TextAsset;
string[] MyList=maskwords.text.Split('\n');
_dictionaryList.Clear();
for(int i=0;i<MaxLen;i++)
{
_dictionaryList.Add(new Dictionary<string,string>());
}
for(int i=0;i<MyList.Length;i++)
{
AddWord(MyList[i].Trim(),GetXingXing(MyList[i].Trim().Length));
}
}
private string GetXingXing(int lenth)
{
string str="";
for(int i=0;i<lenth;i++)
{
str=str+"*";
}
return str;
}
private void AddWord(string src,string dest)
{
int len =src.Length;
Dictionary<string,string> dict = _dictionaryList[len];
if(!dict.ContainsKey(src))
{
dict.Add(src,dest);
}
}
public bool IsMaskWord(string value)
{
int strlen = value.Length;
//Debug.LogError("************value="+value+"*****strlen="+strlen);
for(int leftIter =0;leftIter < strlen;++leftIter)
{
//int maxRight= Mathf.Min(leftIter + _dictionaryList.Count-1,strlen);
int rightIter =leftIter + 1;
while(rightIter <= strlen)
{
string substring= value.Substring(leftIter,rightIter -leftIter);
string replaceString;
if(Filter(substring,out replaceString))
{
return true;
}else{
++rightIter;
}
}
}
return false;
}
bool Filter(string src,out string dest)
{
int len =src.Length;
//Debug.LogError("************str="+src+"********len="+len);
if(_dictionaryList[len].TryGetValue(src,out dest))
{
//Debug.LogError("len1============="+len);
return true;
}else{
//Debug.LogError("len2============="+len);
return false;
}
}
List<Dictionary<string,string>> _dictionaryList=new List<Dictionary<string,string>>();
}
using System.Collections.Generic;
public class MaskWordManager{
private static MaskWordManager mIns;
private MaskWordManager(){}
public static MaskWordManager GetMaskWordManagerInstance()
{
if(mIns ==null)
{
mIns =new MaskWordManager();
}
return mIns;
}
private int MaxLen =50;
public void InitMaskWords()
{
TextAsset maskwords= Resources.Load("MaskWord") as TextAsset;
string[] MyList=maskwords.text.Split('\n');
_dictionaryList.Clear();
for(int i=0;i<MaxLen;i++)
{
_dictionaryList.Add(new Dictionary<string,string>());
}
for(int i=0;i<MyList.Length;i++)
{
AddWord(MyList[i].Trim(),GetXingXing(MyList[i].Trim().Length));
}
}
private string GetXingXing(int lenth)
{
string str="";
for(int i=0;i<lenth;i++)
{
str=str+"*";
}
return str;
}
private void AddWord(string src,string dest)
{
int len =src.Length;
Dictionary<string,string> dict = _dictionaryList[len];
if(!dict.ContainsKey(src))
{
dict.Add(src,dest);
}
}
public bool IsMaskWord(string value)
{
int strlen = value.Length;
//Debug.LogError("************value="+value+"*****strlen="+strlen);
for(int leftIter =0;leftIter < strlen;++leftIter)
{
//int maxRight= Mathf.Min(leftIter + _dictionaryList.Count-1,strlen);
int rightIter =leftIter + 1;
while(rightIter <= strlen)
{
string substring= value.Substring(leftIter,rightIter -leftIter);
string replaceString;
if(Filter(substring,out replaceString))
{
return true;
}else{
++rightIter;
}
}
}
return false;
}
bool Filter(string src,out string dest)
{
int len =src.Length;
//Debug.LogError("************str="+src+"********len="+len);
if(_dictionaryList[len].TryGetValue(src,out dest))
{
//Debug.LogError("len1============="+len);
return true;
}else{
//Debug.LogError("len2============="+len);
return false;
}
}
List<Dictionary<string,string>> _dictionaryList=new List<Dictionary<string,string>>();
}