getArray method

Future<List<String>?> getArray(
  1. String arrayName
)

Returns the array with the specified name from the script.

If the script does not exist, returns null. If the array does not exist, returns null.

arrayName is the name of the array to return.

The script must be in the form: var arrayName = ...; The array should be a list of strings, which may be enclosed in single quotes. The strings will be stripped of their single quotes.

Implementation

Future<List<String>?> getArray(String arrayName) async {
  final script = await contents();
  if (script == null) {
    return null;
  }
  final regex = RegExp('$arrayName=\\((.*?)\\)');
  final match = regex.firstMatch(script);

  if (match == null) {
    return null;
  }

  final array = match.group(1)?.split(' ') ?? [];

  return array.map((str) => str.replaceAll(RegExp("^'|'\$"), "")).toList();
}