list contains implemented
This commit is contained in:
parent
da0709c4db
commit
b638918a89
7 changed files with 36 additions and 9 deletions
|
|
@ -120,6 +120,7 @@ pub fn run_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
|||
if let Ok(s) = current_dir() {
|
||||
prefixes.push(String::from(s.to_str().unwrap()));
|
||||
}
|
||||
prefixes.push(String::from("/"));
|
||||
if let Ctr::String(ref filename) = *ast.car {
|
||||
for prefix in prefixes {
|
||||
let candidate = Path::new(&prefix.clone()).join(filename);
|
||||
|
|
|
|||
|
|
@ -68,13 +68,13 @@ pub fn static_stdlib(syms: &mut SymTable) -> Result<(), String> {
|
|||
);
|
||||
|
||||
syms.insert(
|
||||
"contains".to_string(),
|
||||
"substr?".to_string(),
|
||||
Symbol {
|
||||
name: String::from("contains"),
|
||||
name: String::from("substr?"),
|
||||
args: Args::Strict(vec![Type::String, Type::String]),
|
||||
conditional_branches: false,
|
||||
docs: strings::CONTAINS_DOCSTRING.to_string(),
|
||||
value: ValueType::Internal(Rc::new(strings::contains_callback)),
|
||||
docs: strings::SUBSTR_DOCSTRING.to_string(),
|
||||
value: ValueType::Internal(Rc::new(strings::substr_callback)),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -90,10 +90,10 @@ pub fn strcast_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String>
|
|||
}
|
||||
}
|
||||
|
||||
pub const CONTAINS_DOCSTRING: &str =
|
||||
pub const SUBSTR_DOCSTRING: &str =
|
||||
"Takes two strings. Returns true if string1 contains at least one instance of string2";
|
||||
|
||||
pub fn contains_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String> {
|
||||
pub fn substr_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String> {
|
||||
let parent_str: String;
|
||||
if let Ctr::String(ref s) = *ast.car {
|
||||
parent_str = s.to_string();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue