Next:
Contents
Contents
Str Class Documentation
Matthew Wachowski
Contents
Motivation: What Is Str And Why Should I Use It?
Efficient
Easy to use
Minimal dependencies
Support for your coding style and coding needs
Simple, compact data structure
Tight integration with char*
Avoid major performance problems of char*
Automated memory management in the default case
Flexible allocation options (i.e. Str memory can initially reside on the stack)
Ability to optimize for time or space
About this Documentation
Benchmarks
Allocation Benchmark
String Length Benchmark
String Equality Benchmark
String Append Benchmark
String Search Benchmark
Conclusion
Str Internals
Flags in size_and_flags
STR_ALLOCATED
STR_TIME_EFFICIENT
STR_EXTRA_BUFFER
Design Trade-offs
A Quick Introduction
Standard 'Hello World' Program
Stack-based allocation
Stack Macro
Basic Str Overview
Allocation Options
Heap-based string data
Initialize with char* data
Construct from another string
Construct an empty string of a specified size
Stack-based string data
Statically-Allocated string data
Other options
Resizing and Compacting Strings
char* Conversions
Str Indexing
Constant char*
Non-Constant char*: attach() and detach()
attach() constructor
char* Methods
Handling I/O
Parsing and Formatting
Parsing Groups
Simple Tests
length
equals
startsWith, endsWith
Adding And Removing Data
append
insert
replaceRange
Extracting Substrings
cut
copyRange
Whitespace Functions
lstrip, rstrip, strip
countTokens
copyToken
getAllTokens
Find & Replace
count
findNext
replace
Formatting
format
lower, upper
Performance Tuning
Algorithm
Heap Allocation
Avoid compact()
Pre-allocate
Set Time Efficient
Use The Stack
Extending Str
Resize
Design Templates
String that may grow in size
String that can only get smaller
String that does not change in size
Making Changes While Getting Updates
Design Trade-offs
Embedding Flags in Length
Embedding buff_size in data
Moving size_and_flags inside data
C vs C++ interface
Mutable vs Immutable Strings
Operator Overload Choices
Pre-padding
About this document ...
2007-05-05