您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

74 行
1.7 KiB

using System;
namespace UIWidgets.ui
{
public class WordSeparate
{
enum Direction
{
Forward,
Backward,
}
enum characterType
{
LetterLike,
Symbol,
WhiteSpace
}
private string _text;
public WordSeparate(string text)
{
this._text = text;
}
public IndexRange findWordRange(int index)
{
if (index >= _text.Length)
{
return new IndexRange(0, 0);
}
var t = classifyChar(index);
int start = index;
for (int i = index; i >= 0; --i)
{
if (!char.IsLowSurrogate(_text[start]))
{
if (classifyChar(i) != t)
{
break;
}
start = i;
}
}
int end = index;
for (int i = index; i < _text.Length; ++i)
{
if (!char.IsLowSurrogate(_text[i]))
{
if (classifyChar(i) != t)
{
break;
}
end = i;
}
}
return new IndexRange(start, end + 1);
}
private characterType classifyChar(int index)
{
if (char.IsWhiteSpace(_text, index))
return characterType.WhiteSpace;
if (char.IsLetterOrDigit(_text, index) || _text[index] == '\'')
return characterType.LetterLike;
return characterType.Symbol;
}
}
}