??1??????????? ?????
/// <summary>
/// SQL??????????
/// </summary>
public class SqlConverter : IKeywordsConvertible
{
public SqlConverter(string[] keywords)
{
Keywords = keywords;
}
public SqlConverter() { }
/// <summary>
/// ????????
/// </summary>
public string[] Keywords
{
get { return keywords; }
set
{
this.keywords = new string[value.Length];
for (int i = 0; i < value.Length; i++)
{
this.keywords[i] = value[i].ToLower();
}
}
}
private string[] keywords;
/// <summary>
/// ?????????
/// </summary>
private StringBuilder charBuilder = new StringBuilder();
/// <summary>
/// ?????????
/// </summary>
private StringBuilder symboBuilder = new StringBuilder();
/// <summary>
/// ?????????
/// </summary>
private StringBuilder resBuilder = new StringBuilder();
/// <summary>
/// ????????????????
/// </summary>
private bool lastIsLetter;
/// <summary>
/// ???????
/// </summary>
private string temp;
/// <summary>
/// ???
/// </summary>
/// <param name="source">???????????</param>
/// <returns>??????</returns>
public string Convert(string source)
{
charBuilder.Clear();
symboBuilder.Clear();
resBuilder.Clear();
lastIsLetter = true;
temp = string.Empty;
// ?????????
char[] charArray = source.ToArray<char>();
// ????
foreach (var c in charArray)
{
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
{
// ??????????????????????????????????
if (!lastIsLetter)
{
PushSymbols();
}
charBuilder.Append(c);
lastIsLetter = true;
}
else
{
// ??????????????????????????????????
if (lastIsLetter)
{
PushLetters();
}
symboBuilder.Append(c);
lastIsLetter = false;
}
}
// ??????????????
if (lastIsLetter)
{
PushLetters();
}
else
{
PushSymbols();
}
return resBuilder.ToString();
}
/// <summary>
/// ????????????????????????
/// </summary>
private void PushLetters()
{
temp = charBuilder.ToString();
if (Keywords.Contains(temp.ToLower()))
{
resBuilder.Append(temp.ToUpper());
}
else
{
resBuilder.Append(temp);
}
charBuilder.Clear();
}
/// <summary>
/// ????????????????????????
/// </summary>
private void PushSymbols()
{
resBuilder.Append(symboBuilder.ToString());
symboBuilder.Clear();
}
}
????2?????
????????? ???????SQL????????????????? ?????-?????-?????-?????-?????-????? ????
????????? ??????ж????????????????????????д
?????????? ???????Щ???????
????3?????
??????????????????????????
?????????????????
????1???????????????????????????????????????
????2?????л????????????
??????????
????1??????????char????
????2????? ??????ж? ?????? ????????????????????л????????????????????????
????3???????????Σ???????????????????л???????
????4?????Ч??

????5?????
??????????????SQL?淶?????SQL??????д????????д??????????????????????????????????????????????????????
???????????????????????????д????????
??????????????????????????????????????????????????Σ???????????????????????????????
?????????????????????????????
???????????????????????????????????????????
?????????????????????????????SQL???????д?????????????????????????????????Щ????????????????ò???????????????????????????????????и??????????
???????????????
?????????????????????????????????????£?????????ü?????
??????????????д??????????????????вο??????????????
?????????????????????????????