Skip to content

Commit

Permalink
0.9.495
Browse files Browse the repository at this point in the history
- More string methods
  • Loading branch information
RobbyV2 committed Nov 22, 2024
1 parent 8196463 commit e179e5f
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[package]
name = "fplc"
version = "0.9.494"
version = "0.9.495"
edition = "2021"
description = "A pseudolang interpreter written in Rust"

Expand Down
8 changes: 8 additions & 0 deletions Pseudolang.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ Returns a string of characters from index `start` to index `end` of the given st
`CONCAT("ab", "cd")`
Returns a single string with the two given strings combined

`CONTAINS(string, text)`

Returns TRUE if the string contains the given text, FALSE otherwise.

`FIND(string, text)`

Returns the index position of the first occurrence of text in string (1-based indexing). Returns -1 if text is not found.

`SPLIT(string, delimiter)`

Splits a string into parts based on the given delimiter and returns a list of strings.
Expand Down
4 changes: 2 additions & 2 deletions installer/pseudolang.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

!define MUI_ICON "Pseudolang-Logo.ico"

Name "PseudoLang Installer v0.9.494"
Name "PseudoLang Installer v0.9.495"
InstallDir "$PROGRAMFILES\PseudoLang\"
OutFile "../release/installer/pseudolang-setup-x64.exe"
BrandingText "(c) 2024 PseudoLang Software Foundation"
Expand Down Expand Up @@ -33,7 +33,7 @@ Section ""
WriteRegStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$INSTDIR;$R0"

WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Pseudolang" "DisplayName" "Pseudolang"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Pseudolang" "DisplayVersion" "0.9.494"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Pseudolang" "DisplayVersion" "0.9.495"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Pseudolang" "Publisher" "Pseudolang Software Foundation"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Pseudolang" "DisplayIcon" "$INSTDIR\Pseudolang-Logo.ico"

Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div align="center">
<p>
<img src="https://github.com/PseudoLang-Software-Foundation/Pseudolang/actions/workflows/build.yml/badge.svg" alt="Build and Test Pseudolang">
<img src="https://img.shields.io/badge/Version-0.9.493-green" alt="Version">
<img src="https://img.shields.io/badge/Version-0.9.495-green" alt="Version">
<a href="https://nightly.link/PseudoLang-Software-Foundation/Pseudolang/workflows/build/main"><img src="https://img.shields.io/badge/Nightly-Releases-purple" alt="Nightly Releases"></a>
</p>
</div>
Expand Down
25 changes: 25 additions & 0 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,31 @@ fn evaluate_node(
.collect();
Ok(Value::List(tzs))
}
"CONTAINS" => {
if args.len() != 2 {
return Err("CONTAINS requires two arguments".to_string());
}
let str_val = evaluate_node(&args[0], Rc::clone(&env), debug)?;
let text_val = evaluate_node(&args[1], Rc::clone(&env), debug)?;
match (str_val, text_val) {
(Value::String(s), Value::String(t)) => Ok(Value::Boolean(s.contains(&t))),
_ => Err("CONTAINS requires two string arguments".to_string()),
}
}
"FIND" => {
if args.len() != 2 {
return Err("FIND requires two arguments".to_string());
}
let str_val = evaluate_node(&args[0], Rc::clone(&env), debug)?;
let text_val = evaluate_node(&args[1], Rc::clone(&env), debug)?;
match (str_val, text_val) {
(Value::String(s), Value::String(t)) => match s.find(&t) {
Some(index) => Ok(Value::Integer((index + 1) as i64)),
None => Ok(Value::Integer(-1)),
},
_ => Err("FIND requires two string arguments".to_string()),
}
}
_ => {
let procedure = env
.borrow()
Expand Down
33 changes: 33 additions & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2123,4 +2123,37 @@ DISPLAY(arr)"#,
"HE11O WOR1D",
);
}

#[test]
fn test_string_search() {
assert_output(
r#"
DISPLAY(CONTAINS("Hello World", "World"))
DISPLAY(CONTAINS("Hello World", "Goodbye"))
DISPLAY(CONTAINS("Hello", "ell"))
DISPLAY(CONTAINS("", ""))
"#,
"true\nfalse\ntrue\ntrue",
);

assert_output(
r#"
DISPLAY(FIND("Hello World", "World"))
DISPLAY(FIND("Hello World", "Goodbye"))
DISPLAY(FIND("Hello", "ell"))
DISPLAY(FIND("Testing", "t"))
"#,
"7\n-1\n2\n4",
);

assert_output(
r#"
text <- "The quick brown fox"
needle <- "quick"
DISPLAY(CONTAINS(text, needle))
DISPLAY(FIND(text, needle))
"#,
"true\n5",
);
}
}

0 comments on commit e179e5f

Please sign in to comment.