From 5029ba7ac2c4ab9421c66ef430e3ba7ff417def1 Mon Sep 17 00:00:00 2001 From: lareii Date: Wed, 26 Jul 2023 23:42:03 +0300 Subject: [PATCH] add capitalize string algorithm --- README.md | 1 + string/capitalize.jule | 3 +++ test.jule | 5 +++++ 3 files changed, 9 insertions(+) create mode 100644 string/capitalize.jule diff --git a/README.md b/README.md index 63bf30a..280da53 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Algorithms and data structures implemented in the Jule programming language. - [Lower Case](./string/lower_case.jule) - [Upper Case](./string/upper_case.jule) - [Reverse](./string/reverse.jule) + - [Capitalize](./string/capitalize.jule) ## Contributing diff --git a/string/capitalize.jule b/string/capitalize.jule new file mode 100644 index 0000000..900d60e --- /dev/null +++ b/string/capitalize.jule @@ -0,0 +1,3 @@ +pub fn capitalize(mut string: str): str { + ret upper_case((str)(string[0])) + lower_case(string[1:]) +} \ No newline at end of file diff --git a/test.jule b/test.jule index 3299299..c135789 100644 --- a/test.jule +++ b/test.jule @@ -16,6 +16,7 @@ use string::{ upper_case, lower_case, reverse, + capitalize, } static mut TESTS: TestStack = TestStack.new() @@ -93,6 +94,10 @@ fn add_tests_string() { TESTS.add("reverse", fn(): bool { ret reverse("FooBar") == "raBooF" }) + + TESTS.add("capitalize", fn(): bool { + ret capitalize("foo BAR") == "Foo bar" + }) } fn main() {