explainValue static method

String explainValue({
  1. required Lib lib,
  2. required SharedOptions options,
  3. required String content,
  4. required void callback(
    1. ImageAssetItem asset
    ),
})
override

Implementation

static String explainValue({
  required Lib lib,
  required SharedOptions options,
  required String content,
  required void Function(ImageAssetItem asset) callback
}) {
  // 解析AssetItem参数
  final String reArg = '[\'"]{0,1}([^\\s\\;\'"]+)[\'"]{0,1}';
  // 解析AssetItem备注
  final String reMark = '[\\n\\s]*\\/\\*\\s*([^\\s]+)\\s+(Y|N)\\s*\\*\\/';
  // 解析AssetItem数据
  final String reAssetItem = '$reMark[\\n\\s]+static\\s+const\\s+String\\s+([\\w\\d]+)\\s*\\=\\s*$reArg\\s*;[\\n\\s]+static\\s+const\\s+int\\s+[\\w\\d]+\\\$width\\s*\\=\\s*$reArg\\s*;[\\n\\s]+static\\s+const\\s+int\\s+[\\w\\d]+\\\$height\\s*\\=\\s*$reArg\\s*;';
  return content.replaceAllMapped(RegExp(reAssetItem), (Match match) {
    final String hash = match.group(1)!;
    final String name = match.group(3)!;
    final String path = match.group(4)!;
    final int width = int.parse(match.group(5)!);
    final int height = int.parse(match.group(6)!);
    callback(
      ImageAssetItem(
        path: path,
        name: name,
        hash: hash,
        width: width,
        height: height,
        lib: lib,
        options: options,
      ),
    );
    return '';
  });
}