about summary refs log tree commit diff
path: root/lib/strings.nix
AgeCommit message (Collapse)AuthorFilesLines
2023-04-04Merge pull request #221204 from tweag/deprecate-paths-to-stringsSilvan Mosberger1-11/+75
lib.strings: Prevent paths as inputs in some functions
2023-03-15lib.strings.remove{Prefix,Suffix}: Deprecate for path prefix/suffix argumentsSilvan Mosberger1-5/+23
See also parent commits
2023-03-15lib.strings.normalizePath: Deprecate for path valuesSilvan Mosberger1-1/+14
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-15lib.strings: Deprecate path prefix/suffix/infix argumentsSilvan Mosberger1-5/+38
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-04lib/strings: hide asciiTableNaïm Favier1-2/+2
Since it's an attribute set, the lib function location generating code tries to generate locations for each of the characters...
2023-03-03strings: add escapeQuery for url encodingPatrick Widmer1-3/+18
2023-01-31Merge pull request #205557 from ncfavier/concatLinesSilvan Mosberger1-0/+11
lib/strings: add `concatLines`
2022-12-31lib.isStringLike: Remove use of listRobert Hensing1-1/+3
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-31lib.strings.isConvertibleWithToString: Refactor to reuse isStringLikeRobert Hensing1-4/+3
2022-12-31lib.strings: isMoreCoercibleString -> isConvertibleWithToStringRobert Hensing1-5/+6
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-31lib.strings: isSimpleCoercibleString -> isStringLikeRobert Hensing1-7/+7
2022-12-31treewide: isCoercibleToString -> isMoreCoercibleToStringRobert Hensing1-1/+1
No change in behavior.
2022-12-31lib.strings: Rename isCoercibleToString -> isMoreCoercibleToStringRobert Hensing1-2/+11
2022-12-31lib.strings.toShellVar: Use isSimpleCoercibleStringRobert Hensing1-1/+1
Expecting no change in behavior.
2022-12-31lib.strings.isStorePath: Use isSimpleCoercibleToStringRobert Hensing1-1/+1
Expecting no change in behavior.
2022-12-31lib.strings: Add isSimpleCoercibleToStringRobert Hensing1-0/+11
2022-12-20lib/strings: replace poop emoji (#206999)Naïm Favier1-1/+1
2022-12-17lib: fix typosfigsoda1-2/+2
2022-12-15lib.replaceChars: warn about being a deprecated aliasArtturin1-17/+6
replaceStrings has been in nix since 2015(nix 1.10) so it is safe to remove the fallback https://github.com/nixos/nix/commit/d6d5885c1567454754a0d260521bafa0bd5e7fdb
2022-12-11Merge pull request #205457 from ↵Robert Hensing1-6/+7
h7x4/lib-strings-toInt-broken-for-negative-numbers lib.strings: fix negative number handling for `toInt` and `toIntBase10`
2022-12-10lib/strings: add `concatLines`Naïm Favier1-0/+11
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-10lib.strings: fix negative number handling for `toInt` and `toIntBase10`h7x41-6/+7
The previous version would be unstable due to an input validation regex not expecting a '-' in front of the number.
2022-12-08Merge pull request #204087 from ncfavier/splitString-simplifyNaïm Favier1-6/+4
2022-12-06lib/strings.nix: add mesonOption utility functionAndersonTorres1-0/+55
And some friends, to help write Meson commandline invocations.
2022-12-02lib/strings: simplify `splitString`Naïm Favier1-6/+4
There's no need to use `unsafeDiscardStringContext` since https://github.com/NixOS/nix/commit/ee7fe64c0ac00f2be11604a2a6509eb86dc19f0a (Nix 1.8). Also the separator can't have a context since `builtins.split` would fail, so we can assume it doesn't.
2022-10-24Merge pull request #173949 from jacoblambda/fix-toInt-zero-paddingRobert Hensing1-6/+87
lib: add strings.toIntBase10 to parse zero-padded strings
2022-10-24lib.normalizePath: the empty string is not a valid regex on darwinGuillaume Girol1-1/+1
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-23lib/strings: Update docs and restructured code to improve readability of ↵Jacob Abel1-21/+37
toInt and toIntBase10.
2022-10-23lib/strings: Improve error message for octal ambiguity in toIntJacob Abel1-3/+2
2022-10-23lib/strings: Refactor toInt into toInt and toIntBase10Jacob Abel1-3/+51
2022-10-23lib/strings: Update toInt to handle intermixed ws and zeros. Added testsJacob Abel1-7/+13
2022-10-23lib/strings: allow toInt to parse zero-padded stringsJacob Abel1-4/+16
2022-10-20lib.strings: Add normalizePathajs1241-0/+10
dedupes extranous /'s in filepaths Co-authored-by: Daniel Olsen <daniel.olsen99@gmail.com>
2022-10-20lib.strings: Add function to do C-style escapingDaniel Olsen1-0/+13
2022-10-20lib.strings: Add function to convert character to numberDaniel Olsen1-0/+15
2022-05-07lib/strings/toShellVars: handle derivations as stringsNaïm Favier1-4/+5
2022-05-01lib/strings: convert to string within hasInfixDaniel Thwaites1-1/+1
This should fix the issue mentioned here: https://github.com/NixOS/nixpkgs/pull/168175#issuecomment-1107830574
2022-04-27lib/strings: fix quoting of exampleNaïm Camille Favier1-1/+1
Co-authored-by: Silvan Mosberger <github@infinisil.com>
2022-04-27lib/strings: add toShellVarsNaïm Favier1-0/+60
A straightforward piece of plumbing to safely inject Nix variables into shell scripts: '' ${lib.toShellVars { inherit foo bar; }} cmd "$foo" --bar "$bar" ''
2022-04-22lib/strings: optimise hasInfix function (#168175)Daniel Thwaites1-4/+1
* lib/strings: optimise hasInfix function * lib/strings: optimise hasInfix further using regex * rstudio: call hasInfix with a string * lib/strings: remove let from hasInfix Co-authored-by: pennae <82953136+pennae@users.noreply.github.com> Co-authored-by: pennae <82953136+pennae@users.noreply.github.com>
2022-04-05Merge pull request #166383 from hercules-ci/always-sanitize-derivation-nameRobert Hensing1-1/+8
Always sanitize derivation name
2022-04-05lib.sanitizeDerivationName: Simplify regexRobert Hensing1-1/+1
`^` and `$` are implicit in `match`.
2022-04-01lib/strings: Add levenshtein distance functionsSilvan Mosberger1-0/+127
Adds some functions related to string similarity: - lib.strings.commonPrefixLength - lib.strings.commonSuffixLength - lib.strings.levenshtein - lib.strings.levenshteinAtMost
2022-03-31lib.sanitizeDerivationName: Optimize the common caseRobert Hensing1-1/+8
2021-11-02lib: fix escapeXML example in documentationRobert Helgesson1-1/+1
The previous example output was forgotten copy-paste from some other function.
2021-10-03lib: add function escapeXMLRobert Helgesson1-0/+13
Given a string, this function returns a string that can be inserted verbatim in an XML document.
2021-08-26lib/strings: fix infinite recursion on concatStringsSep fallbackpolykernel1-1/+1
The current implementation of the concatStringsSep fallback references concatStrings whcih is just a partial application of concatStringsSep, forming a circular dependency. Although this will almost never be encountered as (assuming the user does not explicitly trigger it): 1. the or operator will short circuit both in lazy and strict evaluation 2. this can only occur in Nix versions prior to 1.10 which is not compatible with various nix operations as of 2.3.15 However it is still important if scopedImport is used or the builtins have been overwritten. lib.foldl' is used instead of builtins.foldl' as the foldl' primops was introduced in the same release as concatStringsSep.
2021-07-04strings.nix: Fix overly monomorphic type signature commentsNiklas Hambüchen1-2/+2
These functions work on lists of anything, not just lists of strings.
2021-05-07lib/strings: forbid lists in isStorePathsternenseemann1-1/+1
When a list is passed to isStorePath this is most likely a mistake and it is therefore better to just return false. There is one case where this theoretically makes sense (if a list contains a single element for which isStorePath elem), but since that case is also probably seldomly intentional, it may save someone from debbuging unclear evaluation errors.
2021-05-07lib/strings: fix example for isStorePathsternenseemann1-1/+1
Since it checks if dirOf x is the nix store dir, a trailing slash will break this check and make it return false.