Commit Graph

152 Commits

Author SHA1 Message Date
Florian Richer
3b883d3cdf
lib/strings: Add makeIncludePath (#296237)
* Update strings.nix

* Fix typo in docs

* Update lib/strings.nix

Co-authored-by: lolbinarycat <dogedoge61+github@gmail.com>

* Update lib/strings.nix

Co-authored-by: lolbinarycat <dogedoge61+github@gmail.com>

* Add unit test with strings

* Move test to strings

* Add unit test with package structure

* testMakeIncludePathWithPkgs: use real pkgs

* Revert "testMakeIncludePathWithPkgs: use real pkgs"

This reverts commit fb1850c069cfb324f3a43323da740a27a11793f3.

* Update lib/tests/misc.nix

Co-authored-by: lolbinarycat <dogedoge61+github@gmail.com>

* Update lib/tests/misc.nix

Co-authored-by: Silvan Mosberger <github@infinisil.com>

---------

Co-authored-by: lolbinarycat <dogedoge61+github@gmail.com>
Co-authored-by: Silvan Mosberger <github@infinisil.com>
2024-04-02 19:01:05 +02:00
adisbladis
b3cc51a20f lib.toInt/toIntBase10: Make more efficient by hoisting up internal strings into higher scope 2024-03-03 16:52:31 +13:00
Silvan Mosberger
f2c837700d lib.strings: Remove unneeded polyfill
Nix 2.3 (the minimum version needed to evaluate Nixpkgs) supports these, so no need to keep them around.
2024-02-09 05:46:05 +01:00
Alois Wohlschlager
d33127863e
lib: make deprecation warnings consistent
The deprecation warnings in lib were wildly inconsistent. Different
formulations were used in different places for the same meaning. Some warnings
used builtins.trace instead of lib.warn, which prevents silencing; one even
only had a comment instead. Make everything more uniform.
2024-02-03 19:01:39 +01:00
Silvan Mosberger
04efefaa4c
Merge pull request #273473 from adisbladis/lib-isConvertibleToString-static-list
lib.isConvertibleToString: Statically compute types list
2023-12-11 17:46:48 +01:00
adisbladis
2d47874820 lib.cmakeOptionType: Statically compute types list 2023-12-11 16:47:22 +13:00
adisbladis
a128a3f234 lib.isConvertibleToString: Statically compute types list 2023-12-11 16:42:13 +13:00
adisbladis
bd817120c4 lib.strings: Dont create scopes for getName/getVersion
We can create the `parse` function in a scope one level up to avoid recomputing it every time.
2023-12-11 14:49:11 +13:00
h7x4
206d20426c
lib.strings: add replicate
`strings.replicate` returns n copies of a string, concatenated into a new
string

Co-authored-by: Silvan Mosberger <github@infinisil.com>
2023-10-31 20:25:41 +01:00
Anderson Torres
0de25e25b0 lib: refactor
- rename `(enable|with)Feature(As|)` inputs to more descriptive names
2023-10-09 17:49:02 -03:00
Anderson Torres
cc3383d12b lib: add cmakeOptionType, cmakeBool and cmakeFeature 2023-09-27 20:49:38 -03:00
Silvan Mosberger
150217c1ac lib.removePrefix: Optimise 2023-08-14 23:32:42 +02:00
figsoda
57ca44c0ae lib: simplify stringToCharacters 2023-06-22 18:27:15 -04:00
Silvan Mosberger
592213ad3f lib.path.hasPrefix: init 2023-06-15 22:29:46 +02:00
Silvan Mosberger
4f35a58184
Merge pull request #221204 from tweag/deprecate-paths-to-strings
lib.strings: Prevent paths as inputs in some functions
2023-04-04 18:35:06 +02:00
Silvan Mosberger
61012f6daf lib.strings.remove{Prefix,Suffix}: Deprecate for path prefix/suffix arguments
See also parent commits
2023-03-15 19:51:38 +01:00
Silvan Mosberger
5e8b9de728 lib.strings.normalizePath: Deprecate for path values
There's no need to call this function on path data types, and it's
confusing with the new lib.path library functions
2023-03-15 19:42:45 +01:00
Silvan Mosberger
99bc90e301 lib.strings: Deprecate path prefix/suffix/infix arguments
lib.{hasPrefix,hasInfix,hasSuffix} would otherwise return an
always-false result, which can be very unexpected:

    nix-repl> lib.strings.hasPrefix ./lib ./lib/meta.nix
    false
2023-03-15 19:42:43 +01:00
Naïm Favier
a342ebe166
lib/strings: hide asciiTable
Since it's an attribute set, the lib function location generating code
tries to generate locations for each of the characters...
2023-03-04 13:20:49 +01:00
Patrick Widmer
7089294f10 strings: add escapeQuery for url encoding 2023-03-03 20:48:55 +01:00
Silvan Mosberger
50e4dbf35b
Merge pull request #205557 from ncfavier/concatLines
lib/strings: add `concatLines`
2023-01-31 18:05:53 +01:00
Robert Hensing
d103811173 lib.isStringLike: Remove use of list
In the current implementation of Nix, this list would be allocated
over and over. Iirc pennae tried to optimize static list allocation,
but gained no significant performance improvement.
2022-12-31 01:33:47 +01:00
Robert Hensing
23c25d5231 lib.strings.isConvertibleWithToString: Refactor to reuse isStringLike 2022-12-31 01:33:47 +01:00
Robert Hensing
834f0d660a lib.strings: isMoreCoercibleString -> isConvertibleWithToString
Yes, this function name is inconveniently long, but it is important
for the name to explicitly reference the function and not be mistaken
for the implicit string conversions, which only happen for a smaller
set of values.
2022-12-31 01:33:47 +01:00
Robert Hensing
872a24ebbc lib.strings: isSimpleCoercibleString -> isStringLike 2022-12-31 01:33:46 +01:00
Robert Hensing
fed5dc66f8 treewide: isCoercibleToString -> isMoreCoercibleToString
No change in behavior.
2022-12-31 01:03:24 +01:00
Robert Hensing
68b6443ed6 lib.strings: Rename isCoercibleToString -> isMoreCoercibleToString 2022-12-31 01:03:24 +01:00
Robert Hensing
03063f65a5 lib.strings.toShellVar: Use isSimpleCoercibleString
Expecting no change in behavior.
2022-12-31 01:03:24 +01:00
Robert Hensing
2b4a8db032 lib.strings.isStorePath: Use isSimpleCoercibleToString
Expecting no change in behavior.
2022-12-31 01:03:24 +01:00
Robert Hensing
67cfc7a8f6 lib.strings: Add isSimpleCoercibleToString 2022-12-31 01:03:23 +01:00
Naïm Favier
8b5deda7d8
lib/strings: replace poop emoji (#206999) 2022-12-20 13:48:09 +01:00
figsoda
695d4bc76b lib: fix typos 2022-12-17 18:59:29 -05:00
Artturin
05a2dfd674 lib.replaceChars: warn about being a deprecated alias
replaceStrings has been in nix since 2015(nix 1.10)

so it is safe to remove the fallback

d6d5885c15
2022-12-15 22:25:51 +02:00
Robert Hensing
efa1140e83
Merge pull request #205457 from h7x4/lib-strings-toInt-broken-for-negative-numbers
lib.strings: fix negative number handling for `toInt` and `toIntBase10`
2022-12-11 02:26:42 +01:00
Naïm Favier
ed0b8c26f1
lib/strings: add concatLines
Like `unlines` from Haskell.

The aim is to replace the `concatStringsSep "\n"` pattern for generated
files, which doesn't add a final newline.
2022-12-10 15:56:30 +01:00
h7x4
62e863e98c
lib.strings: fix negative number handling for toInt and toIntBase10
The previous version would be unstable due to an input validation regex
not expecting a '-' in front of the number.
2022-12-10 13:16:45 +01:00
Naïm Favier
22af649d14
Merge pull request #204087 from ncfavier/splitString-simplify 2022-12-08 13:30:50 +01:00
AndersonTorres
762f0a599e lib/strings.nix: add mesonOption utility function
And some friends, to help write Meson commandline invocations.
2022-12-06 23:09:36 -03:00
Naïm Favier
3c2124c471
lib/strings: simplify splitString
There's no need to use `unsafeDiscardStringContext` since
ee7fe64c0a
(Nix 1.8).

Also the separator can't have a context since `builtins.split` would fail, so
we can assume it doesn't.
2022-12-02 12:04:36 +01:00
Robert Hensing
bc4ce318bf
Merge pull request #173949 from jacoblambda/fix-toInt-zero-padding
lib: add strings.toIntBase10 to parse zero-padded strings
2022-10-24 13:22:42 +02:00
Guillaume Girol
956e35d0b1 lib.normalizePath: the empty string is not a valid regex on darwin
presumably due to using libc++'s regex lib instead of libstdc++ on linux

Fixes https://github.com/NixOS/nixpkgs/pull/177273#issuecomment-1287562800
2022-10-24 12:25:34 +10:00
Jacob Abel
ed71173841
lib/strings: Update docs and restructured code to improve readability of toInt and toIntBase10. 2022-10-23 17:50:24 -04:00
Jacob Abel
88b18dcf44
lib/strings: Improve error message for octal ambiguity in toInt 2022-10-23 17:50:24 -04:00
Jacob Abel
39a4ab78a1
lib/strings: Refactor toInt into toInt and toIntBase10 2022-10-23 17:50:24 -04:00
Jacob Abel
3d196a5f2a
lib/strings: Update toInt to handle intermixed ws and zeros. Added tests 2022-10-23 17:50:23 -04:00
Jacob Abel
febff1dccd
lib/strings: allow toInt to parse zero-padded strings 2022-10-23 17:50:20 -04:00
ajs124
4284ac9dfb lib.strings: Add normalizePath
dedupes extranous /'s in filepaths

Co-authored-by: Daniel Olsen <daniel.olsen99@gmail.com>
2022-10-20 20:12:15 +02:00
Daniel Olsen
4c420ee485 lib.strings: Add function to do C-style escaping 2022-10-20 20:12:15 +02:00
Daniel Olsen
a08741ffbd lib.strings: Add function to convert character to number 2022-10-20 18:58:44 +02:00
Naïm Favier
4d2ea62d82
lib/strings/toShellVars: handle derivations as strings 2022-05-07 17:01:51 +02:00