-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Auto str Method GenerationBugs/feature requests, that are related to the automatic string method generation.Bugs/feature requests, that are related to the automatic string method generation.Feature/Enhancement RequestThis issue is made to request a feature or an enhancement to an existing one.This issue is made to request a feature or an enhancement to an existing one.
Description
Describe the feature
Add a indent() method to the V string type that formats strings containing curly braces {, } with proper indentation. The method should automatically:
- Insert line breaks after opening braces
{and before closing braces} - Apply configurable indentation levels
- Maintain proper nesting for multiple brace levels
- Preserve content outside braces
May related to PR #25857
Use Case
Currently, V's string type lacks built-in support for brace-based formatting. This method would be particularly useful for:
- Generating properly formatted code
- Creating readable JSON/XML-like outputs
- Formatting configuration files
- Pretty-printing nested data structures
- Use for
auto_str(), then we will not need.indent_str()anymore
Proposed Solution
// As a method on the string type
fn (s string) indent(indent_spaces int) stringor
fn (s string) indent(indent int, options ...FormatOption) stringOther Information
a dump can be called as:
dump(output_string.indent(4))Acknowledgements
- I may be able to implement this feature request
- This feature might incur a breaking change
Version used
V 0.4.12 ff6413a.dd066bb
Environment details (OS name and version, etc.)
| V full version | V 0.4.12 ff6413a.dd066bb |
|---|---|
| OS | linux, Ubuntu 24.04.3 LTS |
| Processor | 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz |
| Memory | 12.37GB/15.51GB |
| V executable | /media/HD/github/kbkpbot/v/v |
| V last modified time | 2025-12-07 00:07:42 |
| V home dir | OK, value: /media/HD/github/kbkpbot/v |
| VMODULES | OK, value: /home/mars/.vmodules |
| VTMP | OK, value: /tmp/v_1000 |
| Current working dir | OK, value: /media/HD/github/kbkpbot/v |
| Git version | git version 2.43.0 |
| V git status | weekly.2025.46-151-gdd066bbd-dirty |
| .git/config present | true |
| cc version | cc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 |
| gcc version | gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 |
| clang version | Ubuntu clang version 18.1.3 (1ubuntu1) |
| tcc version | tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 Linux) |
| tcc git status | thirdparty-linux-amd64 696c1d84 |
| emcc version | N/A |
| glibc version | ldd (Ubuntu GLIBC 2.39-0ubuntu8.6) 2.39 |
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
K1ndWha1e
Metadata
Metadata
Assignees
Labels
Auto str Method GenerationBugs/feature requests, that are related to the automatic string method generation.Bugs/feature requests, that are related to the automatic string method generation.Feature/Enhancement RequestThis issue is made to request a feature or an enhancement to an existing one.This issue is made to request a feature or an enhancement to an existing one.