SubStringSource.java
net.minecraft.network.chat.SubStringSource
信息
- 全限定名:net.minecraft.network.chat.SubStringSource
- 类型:public class
- 包:net.minecraft.network.chat
- 源码路径:src/main/java/net/minecraft/network/chat/SubStringSource.java
- 起始行号:L12
- 职责:
TODO
字段/常量
-
plainText- 类型:
String - 修饰符:
private final - 源码定位:
L13 - 说明:
TODO
- 类型:
-
charStyles- 类型:
List<Style> - 修饰符:
private final - 源码定位:
L14 - 说明:
TODO
- 类型:
-
reverseCharModifier- 类型:
Int2IntFunction - 修饰符:
private final - 源码定位:
L15 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
private SubStringSource(String plainText, List<Style> charStyles, Int2IntFunction reverseCharModifier) @ L17
- 构造器名:SubStringSource
- 源码定位:L17
- 修饰符:private
参数:
- plainText: String
- charStyles: List
- reverseCharModifier: Int2IntFunction
说明:
TODO
方法
下面的方法块按源码顺序生成。
public String getPlainText() @ L23
- 方法名:getPlainText
- 源码定位:L23
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
public List<FormattedCharSequence> substring(int start, int length, boolean reverse) @ L27
- 方法名:substring
- 源码定位:L27
- 返回类型:List
- 修饰符:public
参数:
- start: int
- length: int
- reverse: boolean
说明:
TODO
public static SubStringSource create(FormattedText text) @ L63
- 方法名:create
- 源码定位:L63
- 返回类型:SubStringSource
- 修饰符:public static
参数:
- text: FormattedText
说明:
TODO
public static SubStringSource create(FormattedText text, Int2IntFunction reverseCharModifier, UnaryOperator<String> shaper) @ L67
- 方法名:create
- 源码定位:L67
- 返回类型:SubStringSource
- 修饰符:public static
参数:
- text: FormattedText
- reverseCharModifier: Int2IntFunction
- shaper: UnaryOperator
说明:
TODO
代码
public class SubStringSource {
private final String plainText;
private final List<Style> charStyles;
private final Int2IntFunction reverseCharModifier;
private SubStringSource(String plainText, List<Style> charStyles, Int2IntFunction reverseCharModifier) {
this.plainText = plainText;
this.charStyles = ImmutableList.copyOf(charStyles);
this.reverseCharModifier = reverseCharModifier;
}
public String getPlainText() {
return this.plainText;
}
public List<FormattedCharSequence> substring(int start, int length, boolean reverse) {
if (length == 0) {
return ImmutableList.of();
} else {
List<FormattedCharSequence> parts = Lists.newArrayList();
Style currentRunStyle = this.charStyles.get(start);
int currentRunStart = start;
for (int i = 1; i < length; i++) {
int actualIndex = start + i;
Style charStyle = this.charStyles.get(actualIndex);
if (!charStyle.equals(currentRunStyle)) {
String currentRunText = this.plainText.substring(currentRunStart, actualIndex);
parts.add(
reverse
? FormattedCharSequence.backward(currentRunText, currentRunStyle, this.reverseCharModifier)
: FormattedCharSequence.forward(currentRunText, currentRunStyle)
);
currentRunStyle = charStyle;
currentRunStart = actualIndex;
}
}
if (currentRunStart < start + length) {
String lastRunText = this.plainText.substring(currentRunStart, start + length);
parts.add(
reverse
? FormattedCharSequence.backward(lastRunText, currentRunStyle, this.reverseCharModifier)
: FormattedCharSequence.forward(lastRunText, currentRunStyle)
);
}
return reverse ? Lists.reverse(parts) : parts;
}
}
public static SubStringSource create(FormattedText text) {
return create(text, ch -> ch, s -> s);
}
public static SubStringSource create(FormattedText text, Int2IntFunction reverseCharModifier, UnaryOperator<String> shaper) {
StringBuilder plainText = new StringBuilder();
List<Style> charStyles = Lists.newArrayList();
text.visit((style, contents) -> {
StringDecomposer.iterateFormatted(contents, style, (position, charStyle, codepoint) -> {
plainText.appendCodePoint(codepoint);
int charCount = Character.charCount(codepoint);
for (int i = 0; i < charCount; i++) {
charStyles.add(charStyle);
}
return true;
});
return Optional.empty();
}, Style.EMPTY);
return new SubStringSource(shaper.apply(plainText.toString()), charStyles, reverseCharModifier);
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
方法调用/返回值 - 关联成员:
FormattedCharSequence.backward(), FormattedCharSequence.forward()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
StringDecomposer.iterateFormatted()
- 引用位置: