Enhanced StringBuilder with Advanced String Building Operations
This release significantly expands the StringBuilder API with powerful new functions for efficient string construction.
New StringBuilder Functions
Formatting Functions:
ds_builder_append_format()- Printf-style formatting directly into StringBuilderds_builder_append_format_v()- Va_list version for wrapper functions
Numeric Append Functions:
ds_builder_append_int()- Append integer valuesds_builder_append_uint()- Append unsigned integer valuesds_builder_append_long()- Append long valuesds_builder_append_double()- Append double values with precision control
Buffer Operations:
ds_builder_append_length()- Append specific number of bytesds_builder_prepend()- Prepend text to beginningds_builder_replace_range()- Replace substring within builder
Content Manipulation:
ds_builder_remove_range()- Remove characters from builder
Key Features
- Efficient Construction: Build complex strings without intermediate allocations
- Printf Integration: Format directly into StringBuilder without temporary strings
- Precision Control: Full control over numeric formatting and precision
- Advanced Editing: In-place text manipulation and replacement
- Complete Documentation: Full Doxygen documentation for all new functions
- Comprehensive Testing: 77 unit tests covering all functionality
Example Usage
ds_builder sb = ds_builder_create();
ds_builder_append_format(sb, "Processing %d items:\n", 1000);
for (int i = 0; i < 1000; i++) {
ds_builder_append_format(sb, "Item %d: ", i);
ds_builder_append_double(sb, i * 3.14, 2);
ds_builder_append(sb, "\n");
}
ds_string result = ds_builder_to_string(sb);
ds_builder_release(&sb);Compatibility
All existing code continues to work unchanged. The new functions extend the StringBuilder API without breaking changes.
Assets
dynamic_string.h- Complete single-header library (download and include in your project)