isExplicit static method

bool isExplicit(
  1. String source
)

Whether source uses unambiguous selector syntax rather than free text.

Implementation

static bool isExplicit(String source) {
  final normalized = source.trim();
  if (normalized.isEmpty) return false;
  if (normalized.startsWith('#') ||
      normalized.startsWith(':') ||
      normalized.startsWith('@') ||
      normalized.startsWith('[') ||
      normalized.contains('>>') ||
      normalized.contains(':nth(')) {
    return true;
  }
  return RegExp(
    r'^[A-Za-z_$][A-Za-z0-9_.$]*\s*(?:#|@|\[(?:"|(?:id|sem|key|text|tip|type|route|path)\s*(?:=|\*=|~=)))',
  ).hasMatch(normalized);
}