@@ -18,10 +18,12 @@ #include #import "OFNumber.h" #import "OFString.h" +#import "OFXMLElement.h" +#import "OFAutoreleasePool.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "macros.h" @@ -1088,90 +1090,70 @@ default: @throw [OFInvalidFormatException newWithClass: isa]; } } -- (OFString*)stringBySerializing +- (OFXMLElement*)XMLElementBySerializing { + OFAutoreleasePool *pool; + OFXMLElement *element; + + element = [OFXMLElement elementWithName: @"object" + namespace: OF_SERIALIZATION_NS]; + + pool = [[OFAutoreleasePool alloc] init]; + + [element addAttributeWithName: @"class" + stringValue: [self className]]; + [element setStringValue: [self description]]; + switch (type) { case OF_NUMBER_BOOL: - return (value.bool_ ? @"1" : @"0"); + [element addAttributeWithName: @"type" + stringValue: @"boolean"]; + break; case OF_NUMBER_UCHAR: - return [OFString stringWithFormat: @"%hhu", - value.uchar]; case OF_NUMBER_USHORT: - return [OFString stringWithFormat: @"%hu", - value.ushort]; case OF_NUMBER_UINT: - return [OFString stringWithFormat: @"%u", - value.uint]; case OF_NUMBER_ULONG: - return [OFString stringWithFormat: @"%lu", - value.ulong]; case OF_NUMBER_UINT8: - return [OFString stringWithFormat: @"%" @PRIu8, - value.uint8]; case OF_NUMBER_UINT16: - return [OFString stringWithFormat: @"%" @PRIu16, - value.uint16]; case OF_NUMBER_UINT32: - return [OFString stringWithFormat: @"%" @PRIu32, - value.uint32]; case OF_NUMBER_UINT64: - return [OFString stringWithFormat: @"%" @PRIu64, - value.uint64]; case OF_NUMBER_SIZE: - return [OFString stringWithFormat: @"%ju", - (uintmax_t)value.size]; case OF_NUMBER_UINTMAX: - return [OFString stringWithFormat: @"%ju", - value.uintmax]; case OF_NUMBER_UINTPTR: - return [OFString stringWithFormat: @"%" @PRIuPTR, - value.uintptr]; + [element addAttributeWithName: @"type" + stringValue: @"unsigned"]; + break; case OF_NUMBER_CHAR: - return [OFString stringWithFormat: @"%hhd", - value.char_]; case OF_NUMBER_SHORT: - return [OFString stringWithFormat: @"%hd", - value.short_]; case OF_NUMBER_INT: - return [OFString stringWithFormat: @"%d", - value.int_]; case OF_NUMBER_LONG: - return [OFString stringWithFormat: @"%ld", - value.long_]; case OF_NUMBER_INT8: - return [OFString stringWithFormat: @"%" @PRId8, - value.int8]; case OF_NUMBER_INT16: - return [OFString stringWithFormat: @"%" @PRId16, - value.int16]; case OF_NUMBER_INT32: - return [OFString stringWithFormat: @"%" @PRId32, - value.int32]; case OF_NUMBER_INT64: - return [OFString stringWithFormat: @"%" @PRId64, - value.int64]; case OF_NUMBER_SSIZE: - return [OFString stringWithFormat: @"%jd", - (intmax_t)value.ssize]; case OF_NUMBER_INTMAX: - return [OFString stringWithFormat: @"%jd", - value.intmax]; case OF_NUMBER_PTRDIFF: - return [OFString stringWithFormat: @"%td" @PRIdPTR, - value.ptrdiff]; case OF_NUMBER_INTPTR: - return [OFString stringWithFormat: @"%" @PRIdPTR, - value.intptr]; + [element addAttributeWithName: @"type" + stringValue: @"signed"]; + break; case OF_NUMBER_FLOAT: - return [OFString stringWithFormat: @"%f", - value.float_]; + [element addAttributeWithName: @"type" + stringValue: @"float"]; + break; case OF_NUMBER_DOUBLE: - return [OFString stringWithFormat: @"%lf", - value.double_]; + [element addAttributeWithName: @"type" + stringValue: @"double"]; + break; default: @throw [OFInvalidFormatException newWithClass: isa]; } + + [pool release]; + + return element; } @end