mirror of
https://github.com/kodjodevf/mangayomi.git
synced 2026-08-15 11:04:24 +00:00
- Updated Dart SDK version to ^3.13.0 in pubspec.yaml - Updated various package versions in pubspec.lock - Changed macOS platform version from 10.15 to 12.0 in Podfile and project.pbxproj - Added cupertino_ui dependency - Refactored code for better readability by removing unnecessary line breaks
111 lines
2.8 KiB
Dart
111 lines
2.8 KiB
Dart
import 'dart:ffi';
|
|
|
|
import 'package:ffi/ffi.dart';
|
|
|
|
extension StringExtensions on String {
|
|
String substringAfter(String pattern) {
|
|
final startIndex = indexOf(pattern);
|
|
if (startIndex == -1) return substring(0);
|
|
|
|
final start = startIndex + pattern.length;
|
|
return substring(start);
|
|
}
|
|
|
|
String substringAfterLast(String pattern) {
|
|
return split(pattern).last;
|
|
}
|
|
|
|
String substringBefore(String pattern) {
|
|
final endIndex = indexOf(pattern);
|
|
if (endIndex == -1) return substring(0);
|
|
|
|
return substring(0, endIndex);
|
|
}
|
|
|
|
String substringBeforeLast(String pattern) {
|
|
final endIndex = lastIndexOf(pattern);
|
|
if (endIndex == -1) return substring(0);
|
|
|
|
return substring(0, endIndex);
|
|
}
|
|
|
|
String substringBetween(String left, String right) {
|
|
int startIndex = 0;
|
|
int index = indexOf(left, startIndex);
|
|
if (index == -1) return "";
|
|
int leftIndex = index + left.length;
|
|
int rightIndex = indexOf(right, leftIndex);
|
|
if (rightIndex == -1) return "";
|
|
startIndex = rightIndex + right.length;
|
|
return substring(leftIndex, rightIndex);
|
|
}
|
|
|
|
String replaceForbiddenCharacters(String source) {
|
|
return replaceAll(
|
|
RegExp(r'[\\/:*?"<>|\0]|(^CON$|^PRN$|^AUX$|^NUL$|^COM[1-9]$|^LPT[1-9]$)'),
|
|
source,
|
|
);
|
|
}
|
|
|
|
String get getUrlWithoutDomain {
|
|
final uri = Uri.parse(replaceAll(' ', '%20'));
|
|
String out = uri.path;
|
|
if (uri.query.isNotEmpty) {
|
|
out += '?${uri.query}';
|
|
}
|
|
if (uri.fragment.isNotEmpty) {
|
|
out += '#${uri.fragment}';
|
|
}
|
|
return out;
|
|
}
|
|
|
|
bool isMediaVideo() {
|
|
// Match against the URL path only — query strings (e.g. AnimeGG's
|
|
// `?for=...`) and fragments must not defeat the suffix check. Use a
|
|
// leading `.` so e.g. `flashmp4` doesn't accidentally match.
|
|
final lower = (Uri.tryParse(this)?.path ?? this).toLowerCase();
|
|
return const [
|
|
"3gp",
|
|
"avi",
|
|
"mpg",
|
|
"mpeg",
|
|
"webm",
|
|
"ogg",
|
|
"flv",
|
|
"m4v",
|
|
"mvp",
|
|
"mp4",
|
|
"wmv",
|
|
"mkv",
|
|
"mov",
|
|
].any((extension) => lower.endsWith(".$extension"));
|
|
}
|
|
}
|
|
|
|
extension DefaultValueExtension on String? {
|
|
String? trimmedOrDefault(String? defaultValue) {
|
|
if (this?.trim().isNotEmpty ?? false) {
|
|
return this!.trim();
|
|
}
|
|
return defaultValue;
|
|
}
|
|
}
|
|
|
|
extension NativeStringExtensions on List<String> {
|
|
Pointer<Pointer<Int8>> strListToPointer() {
|
|
final strings = this;
|
|
List<Pointer<Int8>> int8PointerList = strings
|
|
.map((str) => str.toNativeUtf8().cast<Int8>())
|
|
.toList();
|
|
|
|
final Pointer<Pointer<Int8>> pointerPointer = malloc.allocate(
|
|
int8PointerList.length,
|
|
);
|
|
|
|
strings.asMap().forEach((index, utf) {
|
|
pointerPointer[index] = int8PointerList[index];
|
|
});
|
|
|
|
return pointerPointer;
|
|
}
|
|
}
|