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

64 行
1.6 KiB

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