Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: haskell-nix/hnix
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 33815b6cf544550a28a635f4041f71bb7b6d12bc
Choose a base ref
..
head repository: haskell-nix/hnix
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d38db1c2fcacac13906f1e55ad68a356837005f6
Choose a head ref
Showing with 8 additions and 8 deletions.
  1. +8 −8 src/Nix/Builtins.hs
16 changes: 8 additions & 8 deletions src/Nix/Builtins.hs
Original file line number Diff line number Diff line change
@@ -269,7 +269,7 @@ builtinsList = sequence
-}
, add' Normal "stringLength" (arity1 $ Text.length . principledStringIgnoreContext)
, add' Normal "sub" (arity2 ((-) @Integer))
, add' Normal "substring" (substring @e @t @f @m)
, add' Normal "substring" substring
, add Normal "tail" tail_
, add0 Normal "true" (pure $ nvConstant $ NBool True)
, add TopLevel "throw" throw_
@@ -668,13 +668,13 @@ splitMatches numDropped (((_, (start, len)) : captures) : mts) haystack =
thunkStr s = nvStr (hackyMakeNixStringWithoutContext (decodeUtf8 s))

substring :: forall e t f m. MonadNix e t f m => Int -> Int -> NixString -> Prim m NixString
substring start len str = Prim $ if start < 0 --NOTE: negative values of 'len' are OK
then
throwError
$ ErrorCall
$ "builtins.substring: negative start position: "
++ show start
else pure $ principledModifyNixContents (Text.take len . Text.drop start) str
substring start len str = Prim $
if start < 0
then throwError $ ErrorCall $ "builtins.substring: negative start position: " ++ show start
else pure $ principledModifyNixContents (take . Text.drop start) str
where
--NOTE: negative values of 'len' are OK, and mean "take everything"
take = if len < 0 then id else Text.take len

attrNames
:: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)