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

140 行
3.5 KiB

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using ChatComponents;
using JetBrains.Annotations;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.async;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine.UIElements;
using Image = Unity.UIWidgets.widgets.Image;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace UIWidgetsSample
{
public static class urlLinkifierUtils
{
public static Regex _urlRegex = new Regex(
@"^(.*?)((?:https?:\/\/|www\.)[^\s/$.?#].[^\s]*)"
);
public static Regex _looseUrlRegex =new Regex(
@"^(.*?)((https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*))"
);
public static Regex _protocolIdentifierRegex =new Regex(
@"^(https?:\/\/)"
);
}
// Utility class that implements [Linkifier.parse] method.
/// Used to find links in the text.
/*public class UrlLinkifier : Linkifier {
/// Default constructor
UrlLinkifier();
/// Parses text to find all links inside it
@override
List<LinkifyElement> parse(elements, options) {
final list = <LinkifyElement>[];
elements.forEach((element) {
if (element is TextElement) {
var loose = false;
var match = _urlRegex.firstMatch(element.text);
if (match?.group(1)?.isNotEmpty == true) {
final looseMatch = _looseUrlRegex.firstMatch(match!.group(1)!);
if (looseMatch != null) {
match = looseMatch;
loose = true;
}
}
if (match == null && options.looseUrl) {
match = _looseUrlRegex.firstMatch(element.text);
loose = true;
}
if (match == null) {
list.add(element);
} else {
final text = element.text.replaceFirst(match.group(0)!, "");
if (match.group(1)?.isNotEmpty == true) {
list.add(TextElement(match.group(1)!));
}
if (match.group(2)?.isNotEmpty == true) {
var originalUrl = match.group(2)!;
String? end;
if (options.excludeLastPeriod &&
originalUrl[originalUrl.length - 1] == ".") {
end = ".";
originalUrl = originalUrl.substring(0, originalUrl.length - 1);
}
final url = originalUrl;
if (loose || !originalUrl.startsWith(_protocolIdentifierRegex)) {
originalUrl = (options.defaultToHttps ? "https://" : "http://") +
originalUrl;
}
list.add(
UrlElement(
originalUrl,
url,
),
);
if (end != null) {
list.add(TextElement(end));
}
}
if (text.isNotEmpty) {
list.addAll(parse([TextElement(text)], options));
}
}
} else {
list.add(element);
}
});
return list;
}
}
/// Represents an element containing a link
class UrlElement : LinkableElement {
/// Creates [UrlElement]
UrlElement(String url, [String? text]) : super(text, url);
@override
String toString() {
return "LinkElement: "$url" ($text)";
}
@override
bool operator ==(other) => equals(other);
@override
bool equals(other) => other is UrlElement && super.equals(other);
@override
// ignore: unnecessary_overrides
int get hashCode => super.hashCode;
}*/
//}
}