113 lines
4.9 KiB
Java
113 lines
4.9 KiB
Java
package com.discord.utilities.textprocessing;
|
|
|
|
import android.content.Context;
|
|
import c.a.t.b.b.b;
|
|
import c.a.t.b.b.e;
|
|
import com.discord.simpleast.core.node.Node;
|
|
import com.discord.simpleast.core.parser.Parser;
|
|
import com.discord.utilities.textprocessing.node.EditedMessageNode;
|
|
import com.discord.utilities.textprocessing.node.ZeroSpaceWidthNode;
|
|
import com.facebook.drawee.span.DraweeSpanStringBuilder;
|
|
import d0.z.d.m;
|
|
import java.util.List;
|
|
import java.util.regex.Pattern;
|
|
import kotlin.NoWhenBranchMatchedException;
|
|
/* compiled from: DiscordParser.kt */
|
|
public final class DiscordParser {
|
|
public static final DiscordParser INSTANCE = new DiscordParser();
|
|
private static final Parser<MessageRenderContext, Node<MessageRenderContext>, MessageParseState> MASKED_LINK_PARSER = createParser$default(true, true, false, 4, null);
|
|
private static final Parser<MessageRenderContext, Node<MessageRenderContext>, MessageParseState> REPLY_PARSER = createParser(false, true, false);
|
|
private static final Parser<MessageRenderContext, Node<MessageRenderContext>, MessageParseState> SAFE_LINK_PARSER = createParser$default(false, true, false, 4, null);
|
|
|
|
/* compiled from: DiscordParser.kt */
|
|
public enum ParserOptions {
|
|
DEFAULT,
|
|
ALLOW_MASKED_LINKS,
|
|
REPLY
|
|
}
|
|
|
|
public final /* synthetic */ class WhenMappings {
|
|
public static final /* synthetic */ int[] $EnumSwitchMapping$0;
|
|
|
|
static {
|
|
ParserOptions.values();
|
|
int[] iArr = new int[3];
|
|
$EnumSwitchMapping$0 = iArr;
|
|
iArr[ParserOptions.DEFAULT.ordinal()] = 1;
|
|
iArr[ParserOptions.ALLOW_MASKED_LINKS.ordinal()] = 2;
|
|
iArr[ParserOptions.REPLY.ordinal()] = 3;
|
|
}
|
|
}
|
|
|
|
private DiscordParser() {
|
|
}
|
|
|
|
public static final Parser<MessageRenderContext, Node<MessageRenderContext>, MessageParseState> createParser(boolean z2, boolean z3, boolean z4) {
|
|
Parser<MessageRenderContext, Node<MessageRenderContext>, MessageParseState> parser = new Parser<>(false, 1, null);
|
|
Rules rules = Rules.INSTANCE;
|
|
parser.addRule(rules.createSoftHyphenRule());
|
|
e eVar = e.h;
|
|
Pattern pattern = e.f;
|
|
m.checkNotNullExpressionValue(pattern, "PATTERN_ESCAPE");
|
|
parser.addRule(new b(eVar, pattern));
|
|
if (z4) {
|
|
parser.addRule(rules.createBlockQuoteRule());
|
|
}
|
|
parser.addRule(rules.createCodeBlockRule());
|
|
parser.addRule(rules.createInlineCodeRule());
|
|
parser.addRule(rules.createSpoilerRule());
|
|
if (z2) {
|
|
parser.addRule(rules.createMaskedLinkRule());
|
|
}
|
|
parser.addRule(rules.createUrlNoEmbedRule());
|
|
parser.addRule(rules.createUrlRule());
|
|
parser.addRule(rules.createCustomEmojiRule());
|
|
parser.addRule(rules.createNamedEmojiRule());
|
|
parser.addRule(rules.createUnescapeEmoticonRule());
|
|
if (z3) {
|
|
parser.addRule(rules.createChannelMentionRule());
|
|
parser.addRule(rules.createRoleMentionRule());
|
|
parser.addRule(rules.createUserMentionRule());
|
|
}
|
|
parser.addRule(rules.createUnicodeEmojiRule());
|
|
parser.addRule(rules.createTimestampRule());
|
|
parser.addRules(e.a(false, false));
|
|
parser.addRule(rules.createTextReplacementRule());
|
|
return parser;
|
|
}
|
|
|
|
public static /* synthetic */ Parser createParser$default(boolean z2, boolean z3, boolean z4, int i, Object obj) {
|
|
if ((i & 4) != 0) {
|
|
z4 = true;
|
|
}
|
|
return createParser(z2, z3, z4);
|
|
}
|
|
|
|
public static final DraweeSpanStringBuilder parseChannelMessage(Context context, String str, MessageRenderContext messageRenderContext, MessagePreprocessor messagePreprocessor, ParserOptions parserOptions, boolean z2) {
|
|
Parser<MessageRenderContext, Node<MessageRenderContext>, MessageParseState> parser;
|
|
m.checkNotNullParameter(context, "context");
|
|
m.checkNotNullParameter(messageRenderContext, "messageRenderContext");
|
|
m.checkNotNullParameter(messagePreprocessor, "preprocessor");
|
|
m.checkNotNullParameter(parserOptions, "parserOptions");
|
|
int ordinal = parserOptions.ordinal();
|
|
if (ordinal == 0) {
|
|
parser = SAFE_LINK_PARSER;
|
|
} else if (ordinal == 1) {
|
|
parser = MASKED_LINK_PARSER;
|
|
} else if (ordinal == 2) {
|
|
parser = REPLY_PARSER;
|
|
} else {
|
|
throw new NoWhenBranchMatchedException();
|
|
}
|
|
if (str == null) {
|
|
str = "";
|
|
}
|
|
List parse$default = Parser.parse$default(parser, str, MessageParseState.Companion.getInitialState(), null, 4, null);
|
|
messagePreprocessor.process(parse$default);
|
|
if (z2) {
|
|
parse$default.add(new EditedMessageNode(context));
|
|
}
|
|
parse$default.add(new ZeroSpaceWidthNode());
|
|
return AstRenderer.render(parse$default, messageRenderContext);
|
|
}
|
|
}
|