@@ -94,9 +94,16 @@ build_bitstr_each(Fun, [H|T], Meta, S, Acc) ->
9494
9595build_bitstr_each (Fun , T , Meta , S , Acc , H , Size , Types ) ->
9696 { Expr , NS } = Fun (H , S ),
97- case (is_default_or_utf (Types ) andalso Expr ) of
98- { bin , _ ,[{ bin_element , 0 , { string , 0 , String }, default , default }] } ->
97+
98+ AllowString = types_allow_string (Types ),
99+ AllowSplice = types_allow_splice (Types ),
100+ AllowAny = (AllowString orelse AllowSplice ) andalso (Size == default ),
101+
102+ case AllowAny andalso Expr of
103+ { bin , _ , [{ bin_element , 0 , { string , 0 , String }, default , default }] } when AllowString ->
99104 build_bitstr_each (Fun , T , Meta , NS , [{ bin_element , ? line (Meta ), { string , 0 , String }, Size , Types }|Acc ]);
105+ { bin , _ , Elements } when AllowSplice ->
106+ build_bitstr_each (Fun , T , Meta , NS , lists :reverse (Elements ) ++ Acc );
100107 { cons , _ , _ , _ } = Cons ->
101108 build_bitstr_each (Fun , T , Meta , NS , rehash_cons (Cons , Size , Types , []) ++ Acc );
102109 { nil , _ } ->
@@ -109,10 +116,15 @@ rehash_cons({ nil, _ }, _Size, _Types, Acc) -> Acc;
109116rehash_cons ({ cons , Line , Left , Right }, Size , Types , Acc ) ->
110117 rehash_cons (Right , Size , Types , [{ bin_element , Line , Left , Size , Types }|Acc ]).
111118
112- is_default_or_utf (default ) -> true ;
113- is_default_or_utf ([UTF |_ ]) when UTF == utf8 ; UTF == utf16 ; UTF == utf32 -> true ;
114- is_default_or_utf ([_ |T ]) -> is_default_or_utf (T );
115- is_default_or_utf ([]) -> false .
119+ types_allow_string ([End |T ]) when End == little ; End == big -> types_allow_string (T );
120+ types_allow_string ([UTF |T ]) when UTF == utf8 ; UTF == utf16 ; UTF == utf32 -> types_allow_string (T );
121+ types_allow_string ([]) -> true ;
122+ types_allow_string (_ ) -> false .
123+
124+ types_allow_splice (default ) -> true ;
125+ types_allow_splice ([binary ]) -> true ;
126+ types_allow_splice ([bitstring ]) -> true ;
127+ types_allow_splice (_ ) -> false .
116128
117129% % Extra bitstring specifiers
118130
0 commit comments