📄 emoticonparser.cs
字号:
namespace Imps.Client.Core
{
using Imps.Client.Resource;
using Imps.Client.Utils;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
public class EmoticonParser
{
private static int BinaryBestMatch(string[] array, int index, int length, int firstToCompare, string text, int offset, ref int end)
{
int num = -1;
int num2 = index;
int num3 = (index + length) - 1;
int num4 = firstToCompare;
if ((num4 < num2) || (num4 > num3))
{
num4 = num2 + ((num3 - num2) >> 1);
}
while (num2 <= num3)
{
int num5 = -1;
string text2 = array[num4];
for (int i = 0; i < text2.Length; i++)
{
int num7 = offset + i;
if (num7 >= text.Length)
{
num5 = 1;
}
else
{
num5 = text2[i] - text[num7];
}
if (num5 != 0)
{
break;
}
}
if (num5 == 0)
{
end = offset + text2.Length;
num = num4;
num2 = num4 + 1;
}
else
{
if (num >= 0)
{
return num;
}
if (num5 < 0)
{
num2 = num4 + 1;
}
else
{
num3 = num4 - 1;
}
}
num4 = (num >= 0) ? num2 : (num2 + ((num3 - num2) >> 1));
}
return num;
}
private static object InnerPeekEmoticon(Imps.Client.Core.User user, string input, int offset, ref int end)
{
if (!string.IsNullOrEmpty(input))
{
int index;
if (user != null)
{
string[] array = user.CustomEmotionManager.OwnerEmotions.SortedShortCuts;
if ((array != null) && (array.Length > 0))
{
index = BinaryBestMatch(array, 0, array.Length, -1, input, offset, ref end);
if (index >= 0)
{
return user.CustomEmotionManager.OwnerEmotions.GetEmotionByShortCut(array[index]);
}
}
}
string[] sortedKeys = ImpsEmoticons.Instance.SortedKeys;
index = BinaryBestMatch(sortedKeys, 0, sortedKeys.Length, -1, input, offset, ref end);
if (index >= 0)
{
Emoticon emoticon = ImpsEmoticons.Instance[sortedKeys[index]];
emoticon.SrcKey = sortedKeys[index];
return emoticon;
}
}
return null;
}
private static object InnerPeekEmoticon(Imps.Client.Core.User user, string strInput, int offset, ref int start, ref int end)
{
if (EnvHelper.DynamicGifCtlRegistered)
{
start = offset;
while (start < strInput.Length)
{
object obj2 = InnerPeekEmoticon(user, strInput, start, ref end);
if (obj2 != null)
{
return obj2;
}
start++;
}
}
return null;
}
public static List<object> ParseString(Imps.Client.Core.User user, string strInput)
{
int emoticonCount = 0;
return ParseString(user, strInput, out emoticonCount);
}
public static List<object> ParseString(Imps.Client.Core.User user, string strInput, out int emoticonCount)
{
emoticonCount = 0;
List<object> list = new List<object>();
if (!string.IsNullOrEmpty(strInput))
{
int offset = 0;
int start = 0;
int end = 0;
while (true)
{
object obj2 = InnerPeekEmoticon(user, strInput, offset, ref start, ref end);
if (obj2 == null)
{
break;
}
if (start > offset)
{
list.Add(strInput.Substring(offset, start - offset));
}
list.Add(obj2);
emoticonCount++;
offset = end;
}
if (offset < strInput.Length)
{
list.Add(strInput.Substring(offset));
}
}
return list;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -