feat(tvix/eval): add builtins.stringLength
Fairly straightforward, only thing of note is that we coerce (weakly) to string here as well. Change-Id: I03b427e657e402f1f9eb0f795b689bbf5092aba1 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6745 Tested-by: BuildkiteCI Reviewed-by: wpcarro <wpcarro@gmail.com> Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
		
							parent
							
								
									64d3efcc2c
								
							
						
					
					
						commit
						bd9cda2af7
					
				
					 3 changed files with 16 additions and 0 deletions
				
			
		|  | @ -234,6 +234,11 @@ fn pure_builtins() -> Vec<Builtin> { | |||
|                 .collect::<Vec<Value>>(); | ||||
|             Ok(Value::List(NixList::construct(parts.len(), parts))) | ||||
|         }), | ||||
|         Builtin::new("stringLength", &[false], |args, vm| { | ||||
|             // also forces the value
 | ||||
|             let s = args[0].coerce_to_string(CoercionKind::Weak, vm)?; | ||||
|             Ok(Value::Integer(s.as_str().len() as i64)) | ||||
|         }), | ||||
|         Builtin::new( | ||||
|             "sub", | ||||
|             &[false, false], | ||||
|  |  | |||
|  | @ -0,0 +1 @@ | |||
| [ 3 "hello" 9 4 ] | ||||
|  | @ -0,0 +1,10 @@ | |||
| [ | ||||
|   (builtins.stringLength "foo") | ||||
|   (let s = "hello"; in (builtins.substring 0 (builtins.stringLength s) s)) | ||||
|   (builtins.stringLength ("foo" + "${"bar" + "baz"}")) | ||||
| 
 | ||||
|   # feel free to delete this test case at any time, it's just to show: This is a | ||||
|   # thing at the moment. We may want to break compatibility with this aspect of | ||||
|   # the C++ Nix implementation at any time. | ||||
|   (builtins.stringLength "😀") | ||||
| ] | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue