@@ -449,7 +449,7 @@ def render_prefix(self) -> StrGen:
449449 yield self .prefix
450450
451451 def case_insensitive (self ):
452- return self .__class__ ( self . contents .case_insensitive ())
452+ return self .apply ( lambda x : x .case_insensitive ())
453453
454454 def render (self ) -> StrGen :
455455 yield "("
@@ -818,10 +818,8 @@ def __init__(self, *contents: AnyRegexPattern) -> None:
818818 def __add__ (self , other : AnyRegexPattern ) -> Concat :
819819 return Concat (* self .contents , other )
820820
821- def case_insensitive (self ):
822- new = Concat ()
823- new .contents = [part .case_insensitive () for part in self .contents ]
824- return new
821+ def case_insensitive (self ) -> RegexPattern :
822+ return self .apply (lambda x : x .case_insensitive ())
825823
826824 def render (self ) -> StrGen :
827825 for part in self .contents :
@@ -855,13 +853,7 @@ def __init__(self, *alternatives: AnyRegexPattern):
855853 ]
856854
857855 def case_insensitive (self ) -> RegexPattern :
858- new = Option ()
859- alts = [part .case_insensitive () for part in self .alternatives ]
860-
861- if all (isinstance (alt , LocalFlags ) and "i" in alt .flags for alt in alts ):
862- pass
863-
864- return new
856+ return self .apply (lambda x : x .case_insensitive ())
865857
866858 def merge_flags (self ) -> LocalFlags | Option :
867859 self = self .apply (lambda x : x .merge_flags ())
@@ -948,12 +940,7 @@ def __init__(
948940 self .lazy = lazy
949941
950942 def case_insensitive (self ) -> RegexPattern :
951- new = self .contents .case_insensitive ().repeat (self .min_count )
952- if self .max_count is None :
953- new = new .or_more ()
954- else :
955- new = new .to (self .max_count )
956- return new
943+ return self .apply (lambda x : x .case_insensitive ())
957944
958945 def repeat (self , count : int , lazy : bool = False ) -> Range :
959946 """
@@ -1161,13 +1148,6 @@ def __init__(
11611148 self .true_option = respect_priority (true_option , Option .priority + 1 )
11621149 self .false_option = respect_priority (false_option , Option .priority + 1 )
11631150
1164- def case_insensitive (self ) -> RegexPattern :
1165- return ConditionalPattern (
1166- self .group ,
1167- self .true_option .case_insensitive (),
1168- self .false_option .case_insensitive (),
1169- )
1170-
11711151 def render (self ) -> StrGen :
11721152 yield "(?("
11731153 yield str (self .group )
@@ -1184,6 +1164,9 @@ def apply(self, fn: Processor) -> Self:
11841164 fn (self .false_option ),
11851165 )
11861166
1167+ def case_insensitive (self ) -> RegexPattern :
1168+ return self .apply (lambda x : x .case_insensitive ())
1169+
11871170
11881171class Literal (RegexPattern ):
11891172 def __init__ (self , contents : str ) -> None :
0 commit comments