A class for managing and manipulating string objects. More...
#import <Foundation/Foundation.h>
Instance Methods | |
(id) | - initWithString: |
Initializes a new string by referencing another string. More... | |
(id) | - initWithCapacity: |
Initializes a new empty mutable string with pre-allocated capacity. More... | |
(id) | - initWithCString: |
Initializes a new string by referencing a constant c-string. More... | |
(id) | - initWithFormat: |
Initializes a new string with a formatted string. More... | |
(id) | - initWithFormat:arguments: |
Initializes a new string with a formatted string and arguments. More... | |
(const char *) | - cStr |
Returns the C-string representation of the string. More... | |
(unsigned int) | - length |
Returns the length of the string. More... | |
(void *) | - bytes |
Returns the mutable C-string representation of the string. More... | |
(size_t) | - capacity |
Returns the capacity of the string. More... | |
(BOOL) | - append: |
Appends another string to this string. More... | |
(BOOL) | - appendCString: |
Appends a null-terminated C-string to this string. More... | |
(BOOL) | - appendStringWithFormat: |
Appends a string with format and arguments to this string. More... | |
(BOOL) | - trimWhitespace |
Trims leading and trailing whitespace from the string. More... | |
(BOOL) | - trimPrefix:suffix: |
Trims leading and trailing string values from the string. More... | |
(BOOL) | - hasPrefix: |
Checks if the string starts with a given prefix. More... | |
(BOOL) | - hasSuffix: |
Checks if the string ends with a given suffix. More... | |
(unsigned int) | - countOccurrencesOfByte: |
Counts the number of occurrences of a byte character. More... | |
(NXString *) | - JSONString |
Returns a quoted version of the string. More... | |
(BOOL) | - containsString: |
Checks if the string contains a given substring. More... | |
(NXComparisonResult) | - compare: |
Compares this string with another string. More... | |
(BOOL) | - toUppercase |
Converts the string to uppercase. More... | |
(BOOL) | - toLowercase |
Converts the string to lowercase. More... | |
![]() | |
(id) | - retain |
Increases the retain count of the receiver. More... | |
(void) | - release |
Decreases the retain count of the receiver. More... | |
(id) | - autorelease |
Adds the receiver to the autorelease pool. | |
![]() | |
(void) | - dealloc |
Free resources for an existing instance. | |
(id) | - init |
Initialize the instance, after allocation. More... | |
(Class) | - class |
Returns the class of the instance. More... | |
(Class) | - superclass |
Returns the superclass of the instance. More... | |
(BOOL) | - isEqual: |
Compares the receiver to another object for equality. More... | |
(BOOL) | - isKindOfClass: |
Returns a Boolean value that indicates whether the receiver is an instance of a given class. More... | |
(BOOL) | - conformsTo: |
Checks if the receiver's class conforms to a protocol. More... | |
(NXString *) | - description |
Returns a string that represents the instance. More... | |
![]() | |
(BOOL) | - respondsToSelector: |
Checks if the receiver responds to a selector. More... | |
![]() | |
(size_t) | - JSONBytes |
Returns the appropriate capacity for the JSON representation of the instance. More... | |
Class Methods | |
(NXString *) | + new |
Return a new empty string. | |
(NXString *) | + stringWithCapacity: |
Create a new empty string with pre-allocated capacity. More... | |
(NXString *) | + stringWithString: |
Return a string by referencing another string. | |
(NXString *) | + stringWithCString: |
Return a string by referencing a c-string. | |
(NXString *) | + stringWithFormat: |
Return a string from format string and arguments. | |
![]() | |
(id) | + allocWithZone: |
Allocates a new instance of an object in a specific memory zone. More... | |
![]() | |
(void) | + initialize |
Performs one-time initialization for the class. More... | |
(id) | + alloc |
Allocate a new class instance. More... | |
(Class) | + class |
Returns the class object. More... | |
(Class) | + superclass |
Returns the superclass of the class. More... | |
(const char *) | + name |
Returns the name of the class. More... | |
(BOOL) | + conformsTo: |
Checks if the class conforms to a protocol. More... | |
(NXString *) | + description |
Returns a string that represents the class. More... | |
Additional Inherited Members | |
![]() | |
id | _zone |
The memory zone where the object is allocated. | |
unsigned short | _retain |
The retain count of the object. | |
id | _next |
The next object in an autorelease pool. | |
![]() | |
Class | isa |
A pointer to the object's class structure. More... | |
A class for managing and manipulating string objects.
NXString provides functionality for creating and working with text strings. It supports both mutable and immutable string representations.
Definition at line 20 of file NXString.h.
- (BOOL) append: | (id< NXConstantStringProtocol >) | other |
Appends another string to this string.
other | The string to append. |
- (BOOL) appendCString: | (const char *) | other |
Appends a null-terminated C-string to this string.
other | The C-string to append. |
- (BOOL) appendStringWithFormat: | (NXConstantString *) | format | |
, | ... | ||
Appends a string with format and arguments to this string.
format | The format string to use for appending. |
... | Variable arguments for the format string. |
- (void *) bytes |
Returns the mutable C-string representation of the string.
If the string is immutable, this method makes the string mutable and returns a pointer to the internal buffer. If the string is already mutable, it simply returns the pointer to the internal buffer.
- (size_t) capacity |
Returns the capacity of the string.
This method returns the current capacity of the string's internal buffer, which may be larger than the actual length of the string. This is useful for understanding how much space is available for appending or modifying the string without requiring reallocation. If zero is returned, it indicates that the string is currently immutable.
- (NXComparisonResult) compare: | (id< NXConstantStringProtocol >) | other |
Compares this string with another string.
other | The string to compare against. |
- (BOOL) containsString: | (id< NXConstantStringProtocol >) | other |
Checks if the string contains a given substring.
other | The NXConstantString or NXString instance to check for containment. |
- (unsigned int) countOccurrencesOfByte: | (uint8_t) | ch |
Counts the number of occurrences of a byte character.
ch | The character to count occurrences of. |
- (const char *) cStr |
Returns the C-string representation of the string.
This method retrieves the C-string representation of the string, which can be used in C-style string operations.
Reimplemented from <NXConstantStringProtocol>.
- (BOOL) hasPrefix: | (id< NXConstantStringProtocol >) | prefix |
Checks if the string starts with a given prefix.
prefix | The NXConstantString or NXString instance to check as a prefix. |
- (BOOL) hasSuffix: | (id< NXConstantStringProtocol >) | suffix |
Checks if the string ends with a given suffix.
suffix | The NXConstantString or NXString instance to check as a suffix. |
- (id) initWithCapacity: | (size_t) | capacity |
Initializes a new empty mutable string with pre-allocated capacity.
capacity | The initial capacity (in bytes) to allocate for the string buffer. This should include space for the null terminator. If 0 is passed, no memory is allocated and the string starts empty. |
- (id) initWithCString: | (const char *) | cStr |
Initializes a new string by referencing a constant c-string.
cStr | A null-terminated C-string to create the string from. |
- (id) initWithFormat: | (NXConstantString *) | format | |
, | ... | ||
Initializes a new string with a formatted string.
format | The format string to use for initialization. |
... | Variable arguments for the format string. |
- (id) initWithFormat: | (NXConstantString *) | format | |
arguments: | (va_list) | args | |
Initializes a new string with a formatted string and arguments.
format | The format string to use for initialization. |
args | A va_list containing the arguments for the format string. |
This initializer is used internally to initialize the string with a format and variable arguments. It is not intended to be called directly.
- (id) initWithString: | (id< NXConstantStringProtocol, ObjectProtocol >) | other |
Initializes a new string by referencing another string.
This method retains the source string, and if modified, it will create a mutable copy of the modified string whilst releasing the original reference.
other | The source string (either NXConstantString or NXString) to retain. |
- (NXString *) JSONString |
Returns a quoted version of the string.
This method creates a new string that contains the original string enclosed in double quotes. Special characters within the string are escaped according to JSON string escaping rules.
Reimplemented from <JSONProtocol>.
- (unsigned int) length |
Returns the length of the string.
This method returns the length of the string, in bytes, excluding the null terminator.
Reimplemented from <NXConstantStringProtocol>.
+ (NXString *) stringWithCapacity: | (size_t) | capacity |
Create a new empty string with pre-allocated capacity.
capacity | The initial capacity (in bytes) to allocate for the string buffer. This should include space for the null terminator. |
This method creates a mutable string with internal storage pre-allocated to the specified capacity. This is useful when you plan to modify the string (e.g., with append operations) and want to avoid multiple reallocations. The string starts empty but has the capacity to grow up to the specified size without requiring memory reallocation.
- (BOOL) toLowercase |
Converts the string to lowercase.
This method modifies the string in place, converting all alphabetic characters to their lowercase equivalents.
- (BOOL) toUppercase |
Converts the string to uppercase.
This method modifies the string in place, converting all alphabetic characters to their uppercase equivalents.
- (BOOL) trimPrefix: | (id< NXConstantStringProtocol >) | prefix | |
suffix: | (id< NXConstantStringProtocol >) | suffix | |
Trims leading and trailing string values from the string.
prefix | The NXConstantString or NXString instance to trim from the start, or NULL to skip. |
suffix | The NXConstantString or NXString instance to trim from the end, or NULL to skip. |
- (BOOL) trimWhitespace |
Trims leading and trailing whitespace from the string.