Skip to content

Commit

Permalink
add std::fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Sep 7, 2023
1 parent 836ca76 commit 703c497
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ export default defineConfig({
},
{ text: 'std::env', link: '/standard-library/std-env' },
{ text: 'std::errors', link: '/standard-library/std-errors' },
{ text: 'std::fmt', link: '/standard-library/std-fmt' },
{
text: 'std::fs',
link: '/standard-library/std-fs',
Expand Down
19 changes: 19 additions & 0 deletions src/standard-library/std-fmt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# std::fmt

## Functions
```jule
fn format(fmt: str, args: ...any): str
```
It places the passes arguments in the string relative to the corresponding format string. The to_str function provided by the API is used for string conversion. Returns format string if `args.len == 0`. If the arguments have ended, the remaining part of format string is not processed and is returned as is.

**Formatting:**

Arguments are processed sequentially. That is, when an argument encounters a format string parameter, it will be processed according to how many parameters it is. The 5th parameter uses the 5th argument as the value.

Each format parameter is represented as `{}` in the format string. These parameters will then be deleted according to the processing algorithm and replaced with arguments.

**Examples:**

- `format("{} {}!", "Hello", "World")` = `"Hello World!"`
- `format("{} {}")` = `"{} {}"`
- `format("{} is the {}", "PI Number")` = `"PI Number is the {}"`

0 comments on commit 703c497

Please sign in to comment.