Vixen
dd8b0a81
csharp
public static class UtilityParser

Takes a class name apart into what it asks for.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

The grammar is [variant:]*utility[-value][/opacity][!], and every one of those separators can also appear inside an arbitrary value. [&>*]:p-4 has a variant containing no colon but plenty of brackets; bg-[url(a/b.png)] has a slash that is not an opacity; content-['a:b'] has a colon that is not a variant separator. So every split here is bracket-aware, and the naive version of each one is a bug that only shows up on the arbitrary values people reach for precisely when nothing else will do.

Deliberately permissive about what a utility is: this only splits, and whether p-4 means anything is UtilityFamilies' question. Scanning is over-inclusive by design — a false positive costs one unused rule — so failing here has to mean "this is not shaped like a utility at all", never "I do not know this one".

⚠ Three escape hatches and not one, and the two beside w-[37px] are both decided in this method because neither has a family to decide it. The arbitrary value w-[37px] is a known family given a value the theme does not hold. The arbitrary property [mask-type:luminance] is a property with no family at all, and it parses to an empty Name with the property in Property — the one candidate a registry lookup must not be asked about. And bg-(--brand) is v4's shorthand for bg-[var(--brand)], which is rewritten into the arbitrary value here so that nothing downstream has to know there were ever two spellings.

⚠ Both of the new two are shape-tested rather than waved through, and a malformed one produces no candidate at all. [1..:red] and [mask type:red] are refused by IsPropertyName here, and the value half is refused by UtilityFamilies.IsPlausibleValue exactly as w-[1..] is — the text[1..] defect has two more ways in now and both are closed.

Methods (1)

  • public static bool TryParse(string candidate, out UtilityCandidate parsed)

    Takes a class name apart.

Used by (8)

  • ApplyExpanderVixen.Ui.Styling.Utilities
  • ArbitraryPropertyTestsVixen.Ui.Styling.Utilities.Tests
  • ParityLedgerVixen.Ui.Styling.Utilities.Tests
  • ShadowedFamilyTestsVixen.Ui.Styling.Utilities.Tests
  • UtilityConsumptionProbeVixen.Ui.Styling.Utilities.Tests
  • UtilityFamiliesVixen.Ui.Styling.Utilities
  • UtilityFixtureVixen.Ui.Styling.Utilities.Tests
  • UtilityGeneratorVixen.Ui.Styling.Utilities