Skip to content

Commit 3ba7e80

Browse files
committed
(hacky->principled)MakeNixStringWithoutContext
1 parent 208106d commit 3ba7e80

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/Nix/Builtins.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ withNixContext mpath action = do
104104
opts :: Options <- asks (view hasLens)
105105
let i = nvList $ map
106106
( nvStr
107-
. hackyMakeNixStringWithoutContext
107+
. principledMakeNixStringWithoutContext
108108
. Text.pack
109109
)
110110
(include opts)
@@ -341,12 +341,12 @@ nixPath = fmap nvList $ flip foldNixPath [] $ \p mn ty rest ->
341341
PathEntryPath -> ("path", nvPath p)
342342
PathEntryURI ->
343343
( "uri"
344-
, nvStr $ hackyMakeNixStringWithoutContext $ Text.pack p
344+
, nvStr $ principledMakeNixStringWithoutContext $ Text.pack p
345345
)
346346

347347
, ( "prefix"
348348
, nvStr
349-
$ hackyMakeNixStringWithoutContext $ Text.pack $ fromMaybe "" mn
349+
$ principledMakeNixStringWithoutContext $ Text.pack $ fromMaybe "" mn
350350
)
351351
]
352352
)
@@ -657,7 +657,7 @@ splitMatches numDropped (((_, (start, len)) : captures) : mts) haystack =
657657
caps = nvList (map f captures)
658658
f (a, (s, _)) = if s < 0 then nvConstant NNull else thunkStr a
659659

660-
thunkStr s = nvStr (hackyMakeNixStringWithoutContext (decodeUtf8 s))
660+
thunkStr s = nvStr (principledMakeNixStringWithoutContext (decodeUtf8 s))
661661

662662
substring :: forall e t f m. MonadNix e t f m => Int -> Int -> NixString -> Prim m NixString
663663
substring start len str = Prim $
@@ -1321,7 +1321,7 @@ fromJSON arg = demand arg $ fromValue >=> fromStringNoContext >=> \encoded ->
13211321
jsonToNValue = \case
13221322
A.Object m -> flip nvSet M.empty <$> traverse jsonToNValue m
13231323
A.Array l -> nvList <$> traverse jsonToNValue (V.toList l)
1324-
A.String s -> pure $ nvStr $ hackyMakeNixStringWithoutContext s
1324+
A.String s -> pure $ nvStr $ principledMakeNixStringWithoutContext s
13251325
A.Number n -> pure $ nvConstant $ case floatingOrInteger n of
13261326
Left r -> NFloat r
13271327
Right i -> NInt i

src/Nix/Convert.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ instance Convertible e t f m
303303

304304
instance Convertible e t f m
305305
=> ToValue ByteString m (NValue' t f m (NValue t f m)) where
306-
toValue = pure . nvStr' . hackyMakeNixStringWithoutContext . decodeUtf8
306+
toValue = pure . nvStr' . principledMakeNixStringWithoutContext . decodeUtf8
307307

308308
instance Convertible e t f m
309309
=> ToValue Path m (NValue' t f m (NValue t f m)) where

src/Nix/String.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,6 @@ hackyStringIgnoreContext (NixString s _) = s
177177
stringHasContext :: NixString -> Bool
178178
stringHasContext (NixString _ c) = not (null c)
179179

180-
-- | Constructs a NixString without a context
181-
hackyMakeNixStringWithoutContext :: Text -> NixString
182-
hackyMakeNixStringWithoutContext = flip NixString mempty
183-
184180
-- | Constructs a NixString without a context
185181
principledMakeNixStringWithoutContext :: Text -> NixString
186182
principledMakeNixStringWithoutContext = flip NixString mempty
@@ -252,3 +248,7 @@ hackyStringMappend (NixString s1 t1) (NixString s2 t2) =
252248
hackyStringMConcat :: [NixString] -> NixString
253249
hackyStringMConcat = foldr principledStringMappend (NixString mempty mempty)
254250

251+
-- | Constructs a NixString without a context
252+
hackyMakeNixStringWithoutContext :: Text -> NixString
253+
hackyMakeNixStringWithoutContext = principledMakeNixStringWithoutContext
254+

0 commit comments

Comments
 (0)