getBaseName static method

String getBaseName(
  1. String filename
)

Removes all supported extensions from filename to get base name

This method strips ALL occurrences of supported extensions from the filename, not just the last one. This handles cases like 'model.bin.task' -> 'model'.

Examples:

  • 'gemma-2b.task' -> 'gemma-2b'
  • 'model.bin.task' -> 'model'
  • 'tokenizer.model' -> 'tokenizer'
  • 'config.json' -> 'config'
  • 'mymodel' -> 'mymodel' (no extension)

Platform Support: All (no dart:io dependency)

Parameters:

  • filename: The filename to process (can include path)

Returns: The base name with all extensions removed

Implementation

static String getBaseName(String filename) {
  String result = filename;
  for (final ext in supportedExtensions) {
    result = result.replaceAll(ext, '');
  }
  return result;
}