ซอร์สที่เผยแพร่
ดาวน์โหลด ZIP ของซอร์ส
CH-J SM Mobile
เรียกดูไดเรกทอรีและไฟล์ของรุ่นแอปพลิเคชันที่ระบุ
CH-J / SM Mobile
175 ไฟล์
sm-mobile-20261016T185235Z-8e93ecc1b59a
วันที่เพิ่ม: · วันที่บิลด์:
1
import 'dart:convert';2
import 'package:xml/xml.dart';3
import 'package:yaml/yaml.dart';5
/// A syntax problem found by a validator: 1-based line and column.6
class Problem {7
final String message;8
final int? line, column;9
const Problem(this.message, {this.line, this.column});10
}12
/// Which validator applies to a syntax id, if any.13
String? validatorFor(String syntax) => switch (syntax) {14
'json' || 'jsonl' => syntax,15
'yaml' => 'yaml',16
'xml' || 'plist' || 'svg' => 'xml',17
_ => null,18
};20
(int, int) _position(String text, int offset) {21
var line = 1, column = 1;22
for (var i = 0; i < offset && i < text.length; i++) {23
if (text.codeUnitAt(i) == 0x0a) {24
line++;25
column = 1;26
} else {27
column++;28
}29
}30
return (line, column);31
}33
/// Checks [text] without changing it. Returns null when it is valid.34
Problem? validate(String syntax, String text) {35
switch (validatorFor(syntax)) {36
case 'json':37
try {38
jsonDecode(text);39
return null;40
} on FormatException catch (e) {41
final offset = e.offset;42
if (offset == null) return Problem(e.message);43
final (line, column) = _position(text, offset);44
return Problem(e.message, line: line, column: column);45
}46
case 'jsonl':47
final lines = text.split('\n');48
for (var i = 0; i < lines.length; i++) {49
final l = lines[i].trim();50
if (l.isEmpty) continue;51
try {52
jsonDecode(l);53
} on FormatException catch (e) {54
return Problem(e.message, line: i + 1, column: (e.offset ?? 0) + 1);55
}56
}57
return null;58
case 'yaml':59
try {60
loadYamlStream(text);61
return null;62
} on YamlException catch (e) {63
final span = e.span;64
return Problem(65
e.message,66
line: span == null ? null : span.start.line + 1,67
column: span == null ? null : span.start.column + 1,68
);69
}70
case 'xml':71
try {72
XmlDocument.parse(text);73
return null;74
} on XmlParserException catch (e) {75
return Problem(e.message, line: e.line, column: e.column);76
} on XmlTagException catch (e) {77
return Problem(e.message, line: e.line, column: e.column);78
} on XmlException catch (e) {79
return Problem(e.message);80
}81
}82
return null;83
}85
/// Pretty-printed JSON or XML, produced only when the user asks for it.86
/// Returns null when the syntax has no formatter or the text is invalid.87
String? formatText(String syntax, String text, {int indent = 2}) {88
try {89
switch (validatorFor(syntax)) {90
case 'json':91
return JsonEncoder.withIndent(' ' * indent).convert(jsonDecode(text));92
case 'xml':93
return XmlDocument.parse(94
text,95
).toXmlString(pretty: true, indent: ' ' * indent);96
}97
} catch (_) {98
return null;99
}100
return null;101
}SHA-256
8b945d931ceeadaa9d9b3b89fc7766c415abf34a3a07b58f407bacc4740addefCH-J Proprietary Software License 1.14 · ซอร์สโค้ดนี้ให้ไว้ภายใต้ CH-J Proprietary Software License 1.14 การเปิดให้เข้าถึงไม่ได้เปลี่ยนแปลงเงื่อนไขของสัญญาอนุญาตหรือให้สิทธิ์เพิ่มเติม
SHA-256 ของไฟล์บีบอัด
46e427a43e87af091004f36145590bda8fe90086dfb0f631afeb5029fb0b5655