@@ -43,10 +43,11 @@ #import "OFHTTPRequestFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" +#import "OFNotImplementedException.h" #import "OFOpenFileFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "macros.h" @@ -1131,10 +1132,26 @@ - (const char*)cString { return s->cString; } + +- (const char*)cStringWithEncoding: (of_string_encoding_t)encoding +{ + switch (encoding) { + case OF_STRING_ENCODING_UTF_8: + return s->cString; + case OF_STRING_ENCODING_ASCII: + if (s->isUTF8) + @throw [OFInvalidEncodingException newWithClass: isa]; + + return s->cString; + default: + @throw [OFNotImplementedException newWithClass: isa + selector: _cmd]; + } +} - (size_t)length { return s->length; } @@ -1141,10 +1158,26 @@ - (size_t)cStringLength { return s->cStringLength; } + +- (size_t)cStringLengthWithEncoding: (of_string_encoding_t)encoding +{ + switch (encoding) { + case OF_STRING_ENCODING_UTF_8: + return s->cStringLength; + case OF_STRING_ENCODING_ASCII: + if (s->isUTF8) + @throw [OFInvalidEncodingException newWithClass: isa]; + + return s->cStringLength; + default: + @throw [OFNotImplementedException newWithClass: isa + selector: _cmd]; + } +} - (BOOL)isEqual: (id)object { OFString *otherString;