ConfigMemory.parse constructor

ConfigMemory.parse(
  1. String mem
)

Implementation

factory ConfigMemory.parse(String mem) {
  final match = _memoryRegex.firstMatch(mem);
  if (match == null) {
    throw FormatException(
        'invalid memory string, expected integer value with '
        'B/KiB/MiB/GiB/TiB/PiB units');
  }
  int bytes = int.parse(match.namedGroup('bytes')!, radix: 10);
  switch (match.namedGroup('prefix')) {
    case 'Ki':
      bytes *= KiB;
      break;
    case 'Mi':
      bytes *= MiB;
      break;
    case 'Gi':
      bytes *= GiB;
      break;
    case 'Ti':
      bytes *= TiB;
      break;
    case 'Pi':
      bytes *= PiB;
      break;
  }
  return ConfigMemory(bytes);
}