Skip to content

Commit f785d75

Browse files
gadenbuiecpsievert
andauthored
refactor: Simplify splitting css value and unit
Co-authored-by: Carson Sievert <[email protected]>
1 parent db42401 commit f785d75

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

shiny/ui/_theme_brand.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -392,19 +392,7 @@ def maybe_convert_font_size_to_rem(x: str) -> CssUnit:
392392

393393

394394
def split_css_value_and_unit(x: str) -> tuple[str, str]:
395-
digit_chars = [".", *[str(s) for s in range(10)]]
396-
397-
value = ""
398-
unit = ""
399-
in_unit = False
400-
for chr in x:
401-
if chr in digit_chars:
402-
if not in_unit:
403-
value += chr
404-
else:
405-
in_unit = True
406-
407-
if in_unit:
408-
unit += chr
409-
410-
return value.strip(), unit.strip()
395+
match = re.match(r'^(-?\d*\.?\d+)([a-zA-Z%]*)$', x)
396+
if not match:
397+
raise ValueError(f"Invalid CSS value format: {x}")
398+
return match.groups()

0 commit comments

Comments
 (0)