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

58 行
1.6 KiB

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