phobos-text-stringbuilder 0.2.0
A mutable string builder class, similar to .NET's StringBuilder, that provides efficient methods for building and modifying strings.
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
StringBuilder for D
A high-performance, @safe mutable string builder class for the D programming language. Modeled directly after .NET's System.Text.StringBuilder, it provides efficient methods for appending, inserting, removing, and replacing strings, with support for numeric types, interpolated expressions, and fluent chaining.
The purpose of this project is to experiment with various text handling issues that will be encountered during the Phobos 3 development process.
Installation via DUB
Add phobos.text.stringbuilder as a dependency in your dub.sdl file:
dependency "phobos.text.stringbuilder" version="~>0.2.0"
Or for dub.json:
"dependencies": {
"phobos.text.stringbuilder": "~>0.2.0"
}
You can also add it via the command line:
dub add phobos.text.stringbuilder
Features & Capabilities
- .NET API Compatibility: Includes equivalents to
Append,AppendLine,AppendFormat,AppendJoin,Insert,Remove,Replace,Clear, andCopyTo. - Property Management: Controls for
Capacity,MaxCapacity, andLength(which pads with\0when expanded or truncates when shortened). - Fluent Interface: Mutating methods return
thisto allow method chaining. - Interpolated Strings: Natively supports D's
i"..."interpolated expression syntax (sb.append(i"Hello $(name)")). - Value Types: Automatic stringification for string types, characters, booleans, floating point, and integers without intermediate allocations where possible.
- UTF-8 Native: Internal storage uses an amortized-growth UTF-8
char[]buffer. - Safe & Pure: Heavily annotated with
@safe,pure,nothrow(and@nogcwhere no allocations occur).
Usage Examples
Basic Usage and Chaining
import phobos.text.stringbuilder;
auto sb = new StringBuilder();
sb.append("Hello")
.append(" ")
.append("World");
assert(sb.toString() == "Hello World");
Interpolation and AppendLine
auto sb = new StringBuilder();
string name = "Ada";
int age = 36;
sb.appendLine(i"$(name) is $(age) years old");
assert(sb.toString() == "Ada is 36 years old\n");
Insert, Remove, and Replace
auto sb = new StringBuilder("0000");
// Insert
sb.insert(2, 42);
assert(sb.toString() == "004200");
// Replace
sb.replace('0', '-');
assert(sb.toString() == "--42--");
// Remove
sb.remove(0, 2);
assert(sb.toString() == "42--");
AppendFormat and AppendJoin
auto sb = new StringBuilder();
sb.appendFormat("GHI{0}{1}", 'J', 'k');
assert(sb.toString() == "GHIJk");
sb.clear();
sb.appendJoin(", ", 1, 2, 3);
assert(sb.toString() == "1, 2, 3");
Contributing
Contributions are welcome! If you find a bug or have a feature request, please open an issue or submit a pull request.
LLM-Assisted Contributions:
We welcome code generated by Large Language Models (LLMs) such as GitHub Copilot, ChatGPT, or Claude. However, any LLM-based contributions must include the exact prompt(s) used to generate the contribution. Please append your prompts to the PROMPTS.txt file in the root of the repository as part of your pull request.
License
This project is licensed under the BSL-1.0 License. See the LICENSE file for details.
- 0.2.0 released a day ago
- ellipticbit/phobos.text.stringbuilder
- BSL-1.0
- Copyright © 2026, Adam Wilson
- Authors:
- Dependencies:
- none
- Versions:
-
Show all 2 versions0.2.0 2026-May-31 ~master 2026-May-31 - Download Stats:
-
-
0 downloads today
-
1 downloads this week
-
1 downloads this month
-
1 downloads total
-
- Score:
- 0.0
- Short URL:
- phobos-text-stringbuilder.dub.pm