String? _getExcerptAsStringLegacy()

in packages/code_excerpt_updater/lib/src/excerpt_getter.dart [101:134]


  String? _getExcerptAsStringLegacy(String relativePath, String region) {
    const fragExtension = '.txt';
    final String file;
    if (region.isNotEmpty) {
      final dir = p.dirname(relativePath);
      final basename = p.basenameWithoutExtension(relativePath);
      final ext = p.extension(relativePath);
      file = p.join(dir, '$basename-$region$ext$fragExtension');
    } else {
      file = relativePath + fragExtension;
    }

    // First look for a matching fragment
    final fragPath = p.join(fragmentDirPath, pathBase, file);
    try {
      return File(fragPath).readAsStringSync();
    } on FileSystemException {
      if (region != '') {
        _reporter.error('cannot read fragment file "$fragPath"');
        return null;
      }
      // Fall through
    }

    // No fragment file file. Look for a source file with a matching file name.
    final srcFilePath = p.join(srcDirPath, pathBase, relativePath);
    try {
      return File(srcFilePath).readAsStringSync();
    } on FileSystemException {
      _reporter.error('cannot find a source file "$srcFilePath", '
          'nor fragment file "$fragPath"');
      return null;
    }
  }