@@ -53,17 +53,39 @@ @class OFArray; @class OFURL; /** * \brief A class for handling strings. + * + * Warning: If you add methods to OFString using a category, you are not + * allowed to access the ivars directly, as these might be still uninitialized + * for a constant string and get initialized on the first message! Therefore, + * you should use the corresponding methods to get the ivars, which ensures the + * constant string is initialized. */ @interface OFString: OFObject { - char *string; - size_t length; - BOOL isUTF8; + /* + * The ivars have to be like this because OFConstantString bases on + * OFString. + * + * The compiler generates an instance with a const char* and a size_t + * for each constant string. We change the const char* to point to our + * struct on the first call to a constant string so we can have more + * than those two ivars. + */ + struct of_string_ivars { + char *string; + size_t length; + BOOL isUTF8; + } *restrict s; + /* + * Unused in OFString, however, OFConstantString sets this to SIZE_MAX + * once it allocated and initialized the struct. + */ + size_t initialized; } /** * \return A new autoreleased OFString */ @@ -507,14 +529,10 @@ /** * \return The length of the string which cString would return */ - (size_t)cStringLength; -/// \cond internal -- (BOOL)isUTF8; -/// \endcond - /** * Compares the OFString to another OFString without caring about the case. * * \param otherString A string to compare with * \return An of_comparison_result_t