{"id":18990190,"url":"https://github.com/cheesegrinder/templatestr-rust","last_synced_at":"2026-06-23T15:31:54.428Z","repository":{"id":38329902,"uuid":"451224142","full_name":"CheeseGrinder/TemplateStr-Rust","owner":"CheeseGrinder","description":"TemplateStr allows to add variable, function, condition and switch in a string.","archived":false,"fork":false,"pushed_at":"2024-10-10T14:19:24.000Z","size":60,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-01-01T14:26:49.943Z","etag":null,"topics":["parser","rust","strings"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CheeseGrinder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-23T20:35:13.000Z","updated_at":"2024-10-10T14:19:28.000Z","dependencies_parsed_at":"2025-01-01T14:35:14.211Z","dependency_job_id":null,"html_url":"https://github.com/CheeseGrinder/TemplateStr-Rust","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CheeseGrinder%2FTemplateStr-Rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CheeseGrinder%2FTemplateStr-Rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CheeseGrinder%2FTemplateStr-Rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CheeseGrinder%2FTemplateStr-Rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CheeseGrinder","download_url":"https://codeload.github.com/CheeseGrinder/TemplateStr-Rust/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240002227,"owners_count":19732165,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["parser","rust","strings"],"created_at":"2024-11-08T17:09:09.614Z","updated_at":"2026-04-13T21:30:17.203Z","avatar_url":"https://github.com/CheeseGrinder.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \u003ch1\u003eTemplateStr-Go\u003c/h1\u003e\n    \u003ch2\u003eTemplateStr allows to add variable, function, condition and switch in a string.\u003c/h2\u003e\n    \u003cimg src=\"https://img.shields.io/static/v1?label=Rust\u0026message=1.60.0%5E\u0026color=964B00\u0026style=flat-square\u0026logo=Rust\u0026logoColor=964B00\"/\u003e\n    \u003ca href=\"https://github.com/CheeseGrinder/TemplateStr-Rust/actions/workflows/rust.yml\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/actions/workflow/status/CheeseGrinder/TemplateStr-Rust/rust_test.yml?label=Test\u0026style=flat-square\"/\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\n### Install :\n```\n[dependencies]\ntemplate_str = { git=\"https://github.com/CheeseGrinder/TemplateStr-Rust\", tag=\"vX.X.X\" }\n```\n\n### Import :\n\n```rust\nuse template_str::{TemplateStr, t_type::{VariableMap as VMap, TVal, FuncMap}, varmap, list_func, vecTval};\n```\n\n### Construtor :\n\n```rust\nlet parser = TemplateStr::new(map, Some(vec));\n```\n\n\u003cul\u003e\n\u003cli\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003efuncArray\u003c/code\u003e: is an array of functions passed to the constructor that can be called in the parsed text\u003c/summary\u003e\u003cbr\u003e\n\n```rust\nlet vec: FuncMap = list_func![test, test_type];\n```\n\n\u003c/details\u003e\n\u003c/li\u003e\n\n\u003cli\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003evarMap\u003c/code\u003e: is a map of variables passed to the constructor that can be used in the parsed text\u003c/summary\u003e\u003cbr\u003e\n\n```rust\nlet map: VMap = varmap!{\n        \"foo\" =\u003e \"bar\",\n        \"str\" =\u003e \"Jame\",\n        \"int\" =\u003e 32,\n        \"float\" =\u003e 4.2,\n        \"bool\" =\u003e true,\n        \"Vec\" =\u003e vecTval![\"test\", 42],\n        \"Map\" =\u003e varmap!{\n            \"value\" =\u003e \"Map in Map\",\n        },\n        \"Map1\" =\u003e varmap!{\n            \"Map2\" =\u003e varmap!{\n                \"value\" =\u003e \"Map in Map in Map\",\n            },\n        },\n    };\n```\n\n\u003c/details\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\n### Function :\n\n```rust\nlet result = parser.parse(text)\n```\n\n- `parse(text: String) -\u003e Result\u003cString, TmplError\u003e` : parse all (variable, function, condition and switch)\n- `parse_variable(text: String) -\u003e Result\u003cString, TmplError\u003e` : parse Variable ; ${variableName}\n- `parse_function(text: String) -\u003e Result\u003cString, TmplError\u003e` : parse Function and Custom Function ; @{functionName}\n- `parse_condition(text: String) -\u003e Result\u003cString, TmplError\u003e` : parse Condition ; #{value1 == value2; trueValue | falseValue}\n- `parse_switch(text: String) -\u003e Result\u003cString, TmplError\u003e` : parse Switch ; ?{var; value1::#0F0, value2::#00F, ..., _::#000}\n- `has_one(text: String) -\u003e bool` : check if there are one syntaxe\n- `has_variable(text: String) -\u003e bool` : check if there are any Variable\n- `has_function(text: String) -\u003e bool` : check if there are any Function\n- `has_condition(text: String) -\u003e bool` : check if there are any Condition\n- `has_switch(text: String) -\u003e bool` : check if there are any Switch\n\n### Exemple Syntaxe :\n\n\u003cul\u003e\n\u003cli\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eVariable\u003c/strong\u003e\u003c/summary\u003e\n\u003c/br\u003e\n\nThe syntax of the Variables is like :\n- `${variable}`\n- `${Map.value}`\n- `${MasterMap.SecondMap.value. ...}`\n- `${variable[0]}`\u003c/br\u003e\u003c/br\u003e\n\nIf the value does not exist an error is returned\n\n\u003c!-- V Be careful, it's not a \"go\" code, it's just to have some colour in the rendering --\u003e\n```go\n//Example of parsing | is not code\n\nname = \"Jame\"\n\n\"name is ${name}\"\nparse()\n\"name is Jame\"\n```\n\n\u003c/details\u003e\n\u003c/li\u003e\n\n\u003cli\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eFunction\u003c/strong\u003e\u003c/summary\u003e\n\u003c/br\u003e\n\nThe syntax of the Function is like : \n- `@{function; parameter}`\n- `@{function}`\u003c/br\u003e\u003c/br\u003e\n\nHere is a list of the basic functions available  :\n\n- `@{uppercase; variableName}`\n- `@{uppercaseFirst; variableName}`\n- `@{lowercase; variableName}`\n- `@{swapcase; variableName}`\n- `@{time}` HH/mm/ss\n- `@{date}` DD/MM/YYYY\n- `@{dateTime}` DD/MM/YYYY HH/mm/ss\u003c/br\u003e\u003c/br\u003e \n\n\u003c!-- V Be careful, it's not a \"go\" code, it's just to have some colour in the rendering --\u003e\n```go\n//Example of parsing | is not code\n\nname = \"jame\"\n\n\"name is @{uppercase; name}\"\nparse()\n\"name is JAME\"\n//=================================\n\n\"what time is it ? it's @{time}\"\nparse()\n\"what time is it ? it's 15:30:29\"\n```\n\n\u003c/details\u003e\n\u003c/li\u003e\n\n\u003cli\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eCustom Function\u003c/strong\u003e\u003c/summary\u003e\n\u003c/br\u003e\n\nThe syntax of Custom function is the same as the basic functions, they can have 0,1 or more parameters : \n- `@{customFunction; param1 param2 variableName ...}`\n- `@{customFunction}`\u003c/br\u003e\u003c/br\u003e\n\nThe developer who adds his own function will have to document it\n\n`Syntaxe Typing` can be used at the parameter level of custom functions\n\nFor developers :\n- Parameters to be passed in a `list/vec/array`\n- The custom function must necessarily return a `str/string`\u003c/br\u003e\u003c/br\u003e\n\n```rust\nfn test(parameter: Vec\u003cTVal\u003e) -\u003e String {\n\n    // Your code\n\n    return String;\n}\n```\n\n\u003c/details\u003e\n\u003c/li\u003e\n\n\u003cli\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eCondition\u003c/strong\u003e\u003c/summary\u003e\n\u003c/br\u003e\n\nThe syntax of the Condition is like :\n- `#{value1 == value2; trueValue | falseValue}`\u003c/br\u003e\u003c/br\u003e\n  \ncomparator:\n- `==`\n- `!=`\n- `\u003c=` *\n- `\u003c` *\n- `\u003e=` *\n- `\u003e` *\n\u003c/br\u003e\u003c/br\u003e\n\u003cdetails\u003e\n\u003csummary\u003e* \u003ci\u003efor this comparator the type \u003ccode\u003estring\u003c/code\u003e and \u003ccode\u003ebool\u003c/code\u003e are modified\u003c/i\u003e :\u003c/summary\u003e\n\n- `string` it's the number of characters that is compared ('text' = 4)\n- `bool` it's the value in int that is compared (True = 1)\n\n\u003c/details\u003e\n\n`value1` is compared with `value2`\n\n`Syntaxe Typing` can be used at `value1` and `value2` level\n\n\u003c!-- V Be careful, it's not a \"go\" code, it's just to have some colour in the rendering --\u003e\n```go\n//Example of parsing | is not code\n\nname = \"Jame\"\n\n\"Jame is equal to James ? #{name == 'James'; Yes | No}\"\nparse()\n\"Jame is equal to James ? No\"\n```\n\n\u003c/details\u003e\n\u003c/li\u003e\n\n\u003cli\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eSwitch\u003c/strong\u003e\u003c/summary\u003e\n\u003c/br\u003e\n\nThe syntax of the Switch is like :\n- `?{variableName; value1::#0F0, value2::#00F, ..., _::#000}`\n- `?{type/variableName; value1::#0F0, value2::#00F, ..., _::#000}`\u003c/br\u003e\u003c/br\u003e\n\nThe value of `variableName` is compared with all the `values*`,\nif a `values*` is equal to the value of `variableName` then the value after the `::` will be returned.\u003c/br\u003e\nIf no `values*` matches, the value after `_::` is returned\n\nyou can specify the type of `variableName`, but don't use `Syntaxe Typing`.\u003c/br\u003e\nIf the type is specified then all `values*` will be typed with the same type.\n\nsyntax to specify the type of `variableName` :\n- `str/variableName`\n- `int/variableName`\n- `float/variableName`\u003c/br\u003e\u003c/br\u003e\n\n\u003c!-- V Be careful, it's not a \"go\" code, it's just to have some colour in the rendering --\u003e\n```go\n//Example of parsing | is not code\n\nname = \"Jame\"\nyearsOld = 36\n\n\"how old is Jame ? ?{name; Jame::42 years old, William::36 years old, _::I don't know}\"\nparse()\n\"how old is Jame ? 42 years old\"\n//=================================\n\n\"who at 36 years old ? ?{int/yearsOld; 42::Jame !, 36::William !, _::I don't know}\"\nparse()\n\"who at 42 years old ? William !\"\n```\n\n\u003c/details\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\n#### !!! Warning if the syntax is not respected the text will not be parsed\n\n### Syntaxe Typing :\n\nUsable only in the \u003cu\u003e**custom function parameters**\u003c/u\u003e and the two \u003cu\u003e**condition comparison values**\u003c/u\u003e\n\n| Format                       | Type    | Return                 | Note                                                                    |\n|------------------------------|---------|------------------------|-------------------------------------------------------------------------|\n| variableName                 | `*`     | value of `variableName`| Is the key of the value in the dictionary pass to the constructor       |\n| b/True                       | `Bool`  | true                   | Type the string True as `bool`                                          |\n| i/123                        | `Int`   | 123                    | Type the string 123 as type `int`                                       |\n| f/123.4                      | `Float` | 123.4                  | Type the string 123.4 as type `float`                                   |\n| \"text\" or 'text' or \\`text\\` | `Str`   | text                   | It just takes what's in quote, not to be interpreted as a variable name |\n| (\"test\", i/56)               | `Vec`   | [test 56]              | Use typing for typed otherwise text will be used as variable name       |\n\n```diff\n\nThis function takes as parameters a Bool, Int and String\n+ @{MyCustomFunction; b/True i/15 \"foo\"}\n- @{MyCustomFunction; True 15 foo}\n\n\n+ #{\"test\" == \"test\"; Yes | No}\n+ #{\"56\" == i/56; Yes | No}\n- #{foo == 56; Yes | No}\n\n```\n\n### More\nIf you want another example you can look in the test file (`tests/integration_test.rs`)\n\n### TODO\n\n- [ ] : Add exemple\n- [x] : Add test\n\n ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheesegrinder%2Ftemplatestr-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcheesegrinder%2Ftemplatestr-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheesegrinder%2Ftemplatestr-rust/lists"}