34#define _Class _MutableString
48#pragma mark - MutableString
58 const size_t len = strlen(chars);
61 const size_t newSize = self->
string.
length + strlen(chars) + 1;
64 if (newCapacity > self->capacity) {
73 self->capacity = newCapacity;
77 memmove(ptr, chars, len);
117 const int len = vasprintf(&chars, fmt, args);
137 memmove(ptr, ptr + range.
length, length);
159 self->
string.
chars = calloc(capacity,
sizeof(
char));
162 self->capacity = capacity;
175 self = $(self,
init);
212 if (self->capacity == 0) {
247 Range search = range;
258 search.
length -= strlen(replacement);
259 search.
length += ((int) strlen(replacement) - (int) strlen(chars));
325#pragma mark - Class lifecycle
365 .name =
"MutableString",
369 .interfaceSize =
sizeof(MutableStringInterface),
ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
Class * _initialize(const ClassDef *def)
Initializes the given Class.
#define alloc(type)
Allocate and initialize and instance of type.
#define super(type, obj, method,...)
static void initialize(Class *clazz)
void * ident
The identity type, similar to Objective-C id.
#define do_once(once, block)
Executes the given block at most one time.
ClassDefs are passed to _initialize via an archetype to initialize a Class.
The runtime representation of a Class.
ident interface
The interface of the Class.
Condition * init(Condition *self)
Initializes this Condition.
Data * initWithMemory(Data *self, ident mem, size_t length)
Initializes this Data, taking ownership of the specified memory.
MutableArray * initWithCapacity(MutableArray *self, size_t capacity)
Initializes this MutableArray with the specified capacity.
String string
The superclass.
void replaceOccurrencesOfCharacters(MutableString *self, const char *chars, const char *replacement)
Replaces all occurrences of chars with the given replacement.
void replaceStringInRange(MutableString *self, const Range range, const String *string)
Replaces the characters in range with the contents of string.
void trim(MutableString *self)
Trims leading and trailing whitespace from this MutableString.
void insertCharactersAtIndex(MutableString *self, const char *chars, size_t index)
Inserts the specified String at the given index.
void appendString(MutableString *self, const String *string)
Appends the specified String to this MutableString.
void appendVaList(MutableString *self, const char *fmt, va_list args)
Appends the specified format string.
MutableString * initWithString(MutableString *self, const String *string)
Initializes this MutableString with the contents of string.
void replaceCharactersInRange(MutableString *self, const Range range, const char *chars)
Replaces the characters in range with the given characters.
MutableString * stringWithCapacity(size_t capacity)
Returns a new MutableString with the given capacity.
Class * _MutableString(void)
The MutableString archetype.
void replaceOccurrencesOfCharactersInRange(MutableString *self, const char *chars, const Range range, const char *replacement)
Replaces occurrences of chars in range with the given replacement.
void appendFormat(MutableString *self, const char *fmt,...)
Appends the specified formatted string.
void replaceOccurrencesOfString(MutableString *self, const String *string, const String *replacement)
Replaces all occurrences of string with the given replacement.
void replaceOccurrencesOfStringInRange(MutableString *self, const String *string, const Range range, const String *replacement)
Replaces occurrences of string in range with the given replacement.
MutableString * string(void)
Returns a new MutableString.
void deleteCharactersInRange(MutableString *self, const Range range)
Deletes the characters within range from this MutableString.
void appendCharacters(MutableString *self, const char *chars)
Appends the specified UTF-8 encoded C string.
void insertStringAtIndex(MutableString *self, const String *string, size_t index)
Inserts the specified String at the given index.
Object is the root Class of The Objectively Class hierarchy.
Object * copy(const Object *self)
Creates a shallow copy of this Object.
A location and length into contiguous collections.
ssize_t location
The location.
char * chars
The backing null-terminated UTF-8 encoded character array.
size_t length
The length of the String in bytes.
String * trimmedString(const String *self)
Creates a copy of this String with leading and trailing whitespace removed.
OBJECTIVELY_EXPORT MutableString * mstr(const char *fmt,...)
A convenience function for instantiating MutableStrings.
Range rangeOfCharacters(const String *self, const char *chars, const Range range)
Finds and returns the first occurrence of chars in this String.
Class * _String(void)
The String archetype.