diff --git a/binaries/vintLang_android_arm64_v0.1.0.tar.gz b/binaries/vintLang_android_arm64_v0.1.0.tar.gz deleted file mode 100644 index ff5d5b5..0000000 Binary files a/binaries/vintLang_android_arm64_v0.1.0.tar.gz and /dev/null differ diff --git a/binaries/vintLang_android_arm64_v0.1.3.tar.gz b/binaries/vintLang_android_arm64_v0.1.3.tar.gz new file mode 100644 index 0000000..c9ffd48 Binary files /dev/null and b/binaries/vintLang_android_arm64_v0.1.3.tar.gz differ diff --git a/binaries/vintLang_linux_amd64_v0.1.0.tar.gz b/binaries/vintLang_linux_amd64_v0.1.0.tar.gz deleted file mode 100644 index c88ce5f..0000000 Binary files a/binaries/vintLang_linux_amd64_v0.1.0.tar.gz and /dev/null differ diff --git a/binaries/vintLang_linux_amd64_v0.1.2.tar.gz b/binaries/vintLang_linux_amd64_v0.1.2.tar.gz deleted file mode 100644 index 7040368..0000000 Binary files a/binaries/vintLang_linux_amd64_v0.1.2.tar.gz and /dev/null differ diff --git a/binaries/vintLang_mac_amd64_v0.1.0.tar.gz b/binaries/vintLang_mac_amd64_v0.1.0.tar.gz deleted file mode 100644 index 003c040..0000000 Binary files a/binaries/vintLang_mac_amd64_v0.1.0.tar.gz and /dev/null differ diff --git a/binaries/vint_android_arm64_v0.5.1.tar.gz b/binaries/vint_android_arm64_v0.5.1.tar.gz deleted file mode 100644 index d92af56..0000000 Binary files a/binaries/vint_android_arm64_v0.5.1.tar.gz and /dev/null differ diff --git a/module/string.go b/module/string.go index b756573..6b00d78 100644 --- a/module/string.go +++ b/module/string.go @@ -1,7 +1,9 @@ package module import ( + "regexp" "strings" + "github.com/ekilie/vint-lang/object" "github.com/xrash/smetrics" // A library for string metrics, like Levenshtein ) @@ -20,8 +22,38 @@ func init() { StringFunctions["length"] = length StringFunctions["indexOf"] = indexOf StringFunctions["similarity"] = similarity + StringFunctions["slug"] = slug +} + +// Creates a slug string from a normal string +func slug(args []object.Object, defs map[string]object.Object) object.Object { + // Ensure exactly one argument is passed + if len(args) != 1 { + return &object.Error{Message: "string.slug requires exactly one argument"} + } + + // Inspect the argument and convert it to a string + input := args[0].Inspect() + + // Convert the input to lowercase + input = strings.ToLower(input) + + // Remove all non-alphanumeric characters except spaces and hyphens + re := regexp.MustCompile(`[^a-z0-9\s-]+`) + input = re.ReplaceAllString(input, "") + + // Replace spaces and multiple hyphens with a single hyphen + re = regexp.MustCompile(`[\s-]+`) + input = re.ReplaceAllString(input, "-") + + // Trim leading and trailing hyphens + input = strings.Trim(input, "-") + + // Return the result as a Vint object string + return &object.String{Value: input} } + // similarity computes a similarity score between two strings func similarity(args []object.Object, defs map[string]object.Object) object.Object { if len(args) != 2 { diff --git a/vint.upx b/vint.upx new file mode 100644 index 0000000..e69de29 diff --git a/vintLang/builtins.vint b/vintLang/builtins.vint index ed26292..dddb1d1 100644 --- a/vintLang/builtins.vint +++ b/vintLang/builtins.vint @@ -1 +1,4 @@ -print(eq(2,"")) //Prints False \ No newline at end of file +print(eq(2,"")) //Prints False + +a = print +a("yeee") \ No newline at end of file diff --git a/vintLang/strings.vint b/vintLang/strings.vint index 2b7911d..5d542c5 100644 --- a/vintLang/strings.vint +++ b/vintLang/strings.vint @@ -46,8 +46,12 @@ result = string.substring("Hello, World!", 0, 5) print(result) // Output: "Hello" // Example 12: Invalid indices (start >= end) -result = string.substring("Hello, World!", 7, 3) -print(result) // Output: Error: Invalid start or end index +// result = string.substring("Hello, World!", 7, 3) +// print(result) // Output: Error: Invalid start or end index + +//Example 12: Generating a slug +result = string.slug("Creates a slug string from a normal string") +print(result) //Output: string: creates-a-slug-string-from-a-normal-string /*