-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
836ca76
commit 703c497
Showing
2 changed files
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {}"` |