@@ -939,46 +939,46 @@ replaceStrings
939939 -> NValue t f m
940940 -> m (NValue t f m )
941941-- `ns*` goes for NixString here, which are with context - remember
942- replaceStrings tfrom tto ts = fromValue (Deeper tfrom) >>= \ (nsFrom :: [NixString ]) ->
943- fromValue (Deeper tto) >>= \ (nsTo :: [NixString ]) ->
944- fromValue ts >>= \ (ns :: NixString ) -> do
942+ replaceStrings tfrom tto ts =
943+ fromValue (Deeper tfrom) >>= \ (nsFrom :: [NixString ]) ->
944+ fromValue (Deeper tto) >>= \ (nsTo :: [NixString ]) ->
945+ fromValue ts >>= \ (ns :: NixString ) ->
946+ do
945947 when (length nsFrom /= length nsTo)
946948 $ throwError $ ErrorCall " builtins.replaceStrings: Arguments `from`&`to` are lists `from` what replace `to` what, so the number of their inhabitanting elements must always match."
947949 let
948950
949951 from = fmap stringIgnoreContext nsFrom
950952
951- lookupPrefix s = do -- monadic context handles Maybe result here, aka if Nothing returned
952- (prefix, replacement) <- find ((`Text.isPrefixOf` s) . fst )
953- $ zip from nsTo
954- let rest = Text. drop (Text. length prefix) s
955- pure (prefix, replacement, rest)
953+ lookupPrefix s =
954+ do -- monadic context handles Maybe result here, aka if Nothing returned
955+ (prefix, replacement) <- find ((`Text.isPrefixOf` s) . fst )
956+ $ zip from nsTo
957+ let rest = Text. drop (Text. length prefix) s
958+ pure (prefix, replacement, rest)
956959
957960 finish b =
958961 makeNixString (LazyText. toStrict $ Builder. toLazyText b)
959962
960963 go orig result ctx = case lookupPrefix orig of
961- Nothing -> case Text. uncons orig of
962- Nothing -> finish result ctx
963- Just (h, t) -> go t (result <> Builder. singleton h) ctx
964+ Nothing ->
965+ case Text. uncons orig of
966+ Nothing ->
967+ finish result ctx
968+ Just (h, t) ->
969+ go t (result <> Builder. singleton h) ctx
964970 Just (prefix, replacementNS, rest) ->
965971 case prefix of
966- " " -> case Text. uncons rest of
967- Nothing -> finish
968- (result <> Builder. fromText replacement)
969- (ctx <> newCtx)
970- Just (h, t) -> go
971- t
972- (mconcat
973- [ result
974- , Builder. fromText replacement
975- , Builder. singleton h
976- ]
977- )
978- (ctx <> newCtx)
979- _ -> go rest
980- (result <> Builder. fromText replacement)
981- (ctx <> newCtx)
972+ " " ->
973+ case Text. uncons rest of
974+ Nothing ->
975+ finish (result <> Builder. fromText replacement) (ctx <> newCtx)
976+ Just (h, t) ->
977+ go t (mconcat [ result
978+ , Builder. fromText replacement
979+ , Builder. singleton h ]) (ctx <> newCtx)
980+ _prefix ->
981+ go rest (result <> Builder. fromText replacement) (ctx <> newCtx)
982982 where
983983 replacement = stringIgnoreContext replacementNS
984984 newCtx = NixString. getContext replacementNS
0 commit comments