@@ -34,10 +34,11 @@ #import "OFArray.h" #import "OFDictionary.h" #import "OFFile.h" #import "OFURL.h" #import "OFHTTPRequest.h" +#import "OFXMLElement.h" #import "OFAutoreleasePool.h" #import "OFHTTPRequestFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" @@ -1053,37 +1054,31 @@ - (OFString*)description { return [[self copy] autorelease]; } -- (OFString*)stringBySerializing -{ - OFMutableString *serialization = [[self mutableCopy] autorelease]; - [serialization replaceOccurrencesOfString: @"\\" - withString: @"\\\\"]; - [serialization replaceOccurrencesOfString: @"\"" - withString: @"\\\""]; - [serialization replaceOccurrencesOfString: @"\n" - withString: @"\\n\"\n \""]; - [serialization replaceOccurrencesOfString: @"\r" - withString: @"\\r"]; - [serialization replaceOccurrencesOfString: @"\t" - withString: @"\\t"]; - - if ([self isKindOfClass: [OFMutableString class]]) - [serialization prependString: @"(mutable)\""]; +- (OFXMLElement*)XMLElementBySerializing +{ + OFAutoreleasePool *pool; + OFXMLElement *element; + + element = [OFXMLElement elementWithName: @"object" + namespace: OF_SERIALIZATION_NS + stringValue: self]; + + pool = [[OFAutoreleasePool alloc] init]; + + if ([self isKindOfClass: [OFConstantString class]]) + [element addAttributeWithName: @"class" + stringValue: @"OFString"]; else - [serialization prependString: @"\""]; - [serialization appendString: @"\""]; - - /* - * Class swizzle the string to be immutable. We declared the return type - * to be OFString*, so it can't be modified anyway. But not swizzling it - * would create a real copy each time -[copy] is called. - */ - serialization->isa = [OFString class]; - return serialization; + [element addAttributeWithName: @"class" + stringValue: [self className]]; + + [pool release]; + + return element; } - (of_unichar_t)characterAtIndex: (size_t)index { of_unichar_t c;