-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[External] [stdlib] Allow
!r
conversion flag in String.format
(#4…
…3914) [External] [stdlib] Allow `!r` conversion flag in `String.format` This addresses #3267. - Implemented parsing and handling of `!s` and `!r` conversion flags in format strings. - Updated the `_FormatCurlyEntry` struct to include a `conversion_flag` field. - Modified the `create_entries` method to correctly parse and store conversion flags. - Updated the string formatting logic to apply the appropriate conversion (`str` or `repr`) based on the flag. Additionally, I was conscious of potential future support of `!a` flag and `format_spec` , which is not currently supported. The additions of this PR should be direct to modify for this support. Hence why `supported_conversion_flags` was added, and a TODO was left in the code for the latter. For reference, see [Python's Format String Syntax](https://docs.python.org/3/library/string.html#format-string-syntax): ``` replacement_field ::= "{" [field_name] ["!" conversion] [":" format_spec] "}" field_name ::= arg_name ("." attribute_name | "[" element_index "]")* arg_name ::= [identifier | digit ] attribute_name ::= identifier element_index ::= digit | index_string index_string ::= <any source character except "]"> conversion ::= "r" | "s" | "a" format_spec ::= <see Python docs for details> ``` ORIGINAL_AUTHOR=Joshua James Venter <67124214 [email protected]> PUBLIC_PR_LINK=#3279 Co-authored-by: Joshua James Venter <67124214 [email protected]> Closes #3279 MODULAR_ORIG_COMMIT_REV_ID: 9ee92a55ac683be22f7b93012f37c6980f7110b6
- Loading branch information
1 parent
29916e1
commit f13ddcf
Showing
3 changed files
with
218 additions
and
24 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
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