Index: src/OFConstantString.m ================================================================== --- src/OFConstantString.m +++ src/OFConstantString.m @@ -604,10 +604,17 @@ { [self finishInitialization]; return [self UTF32StringWithByteOrder: byteOrder]; } + +- (OFData *)dataWithEncoding: (of_string_encoding_t)encoding +{ + [self finishInitialization]; + + return [self dataWithEncoding: encoding]; +} #ifdef OF_HAVE_UNICODE_TABLES - (OFString *)decomposedStringWithCanonicalMapping { [self finishInitialization]; Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -1121,10 +1121,18 @@ * @return The string in UTF-32 encoding with the specified byte order */ - (const char32_t *)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder OF_RETURNS_INNER_POINTER; +/*! + * @brief Returns the string as OFData with the specified encoding. + * + * @param encoding The encoding to use for the returned OFData + * @return The string as OFData with the specified encoding + */ +- (OFData *)dataWithEncoding: (of_string_encoding_t)encoding; + #ifdef OF_HAVE_UNICODE_TABLES /*! * @brief Returns the string in Unicode Normalization Form D (NFD). * * @return The string in Unicode Normalization Form D (NFD) Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -2769,10 +2769,24 @@ for (size_t i = 0; i < length; i++) ret[i] = OF_BSWAP32(ret[i]); return ret; } + +- (OFData *)dataWithEncoding: (of_string_encoding_t)encoding +{ + void *pool = objc_autoreleasePoolPush(); + OFData *data = + [OFData dataWithItems: [self cStringWithEncoding: encoding] + count: [self cStringLengthWithEncoding: encoding]]; + + [data retain]; + + objc_autoreleasePoolPop(pool); + + return [data autorelease]; +} #ifdef OF_HAVE_UNICODE_TABLES - (OFString *)decomposedStringWithCanonicalMapping { return decomposedString(self, of_unicode_decomposition_table,