ObjFW  Check-in [0db281bf03]

Overview
Comment:Improve -[OFNumber description].

The %f conversion specifier does not include a decimal point if none is
required. In such cases, append ".0" to indicate that the number is of a
floating point type.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0db281bf03fed793611e9594f52709aa849fc65d00b93292ce63bde58d0439dc
User & Date: js on 2012-06-11 11:08:47
Other Links: manifest | tags
Context
2012-06-11
23:08
Add OF_PATH_PARENT_DIR. check-in: bfd8f4cfec user: js tags: trunk
20:50
Merge branch 'master' into runtime check-in: 19a677b596 user: js tags: runtime
11:08
Improve -[OFNumber description]. check-in: 0db281bf03 user: js tags: trunk
2012-06-10
16:07
JSON: Make it possible to get the invalid line. check-in: 72c71c4eb2 user: js tags: trunk
Changes

Modified src/OFNumber.m from [f581497f4f] to [3bd254e0cf].

1136
1137
1138
1139
1140
1141
1142


1143
1144
1145
1146
1147
1148
1149
- copy
{
	return [self retain];
}

- (OFString*)description
{


	switch (type) {
	case OF_NUMBER_BOOL:
		return (value.bool_ ? @"YES" : @"NO");
	case OF_NUMBER_UCHAR:
	case OF_NUMBER_USHORT:
	case OF_NUMBER_UINT:
	case OF_NUMBER_ULONG:







>
>







1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
- copy
{
	return [self retain];
}

- (OFString*)description
{
	OFMutableString *ret;

	switch (type) {
	case OF_NUMBER_BOOL:
		return (value.bool_ ? @"YES" : @"NO");
	case OF_NUMBER_UCHAR:
	case OF_NUMBER_USHORT:
	case OF_NUMBER_UINT:
	case OF_NUMBER_ULONG:
1165
1166
1167
1168
1169
1170
1171
1172







1173
1174







1175
1176
1177
1178
1179
1180
1181
	case OF_NUMBER_INT64:
	case OF_NUMBER_SSIZE:
	case OF_NUMBER_INTMAX:
	case OF_NUMBER_PTRDIFF:
	case OF_NUMBER_INTPTR:
		return [OFString stringWithFormat: @"%jd", [self intMaxValue]];
	case OF_NUMBER_FLOAT:
		return [OFString stringWithFormat: @"%g", value.float_];







	case OF_NUMBER_DOUBLE:
		return [OFString stringWithFormat: @"%lg", value.double_];







	default:
		@throw [OFInvalidFormatException exceptionWithClass: isa];
	}
}

- (OFXMLElement*)XMLElementBySerializing
{







|
>
>
>
>
>
>
>

|
>
>
>
>
>
>
>







1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
	case OF_NUMBER_INT64:
	case OF_NUMBER_SSIZE:
	case OF_NUMBER_INTMAX:
	case OF_NUMBER_PTRDIFF:
	case OF_NUMBER_INTPTR:
		return [OFString stringWithFormat: @"%jd", [self intMaxValue]];
	case OF_NUMBER_FLOAT:
		ret = [OFMutableString stringWithFormat: @"%g", value.float_];

		if (![ret containsString: @"."])
			[ret appendString: @".0"];

		[ret makeImmutable];

		return ret;
	case OF_NUMBER_DOUBLE:
		ret = [OFMutableString stringWithFormat: @"%lg", value.double_];

		if (![ret containsString: @"."])
			[ret appendString: @".0"];

		[ret makeImmutable];

		return ret;
	default:
		@throw [OFInvalidFormatException exceptionWithClass: isa];
	}
}

- (OFXMLElement*)XMLElementBySerializing
{

Modified src/exceptions/OFInvalidJSONException.m from [cae65c6e83] to [ca1d0c629a].

24
25
26
27
28
29
30








31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
@implementation OFInvalidJSONException
+ exceptionWithClass: (Class)class_
		line: (size_t)line
{
	return [[[self alloc] initWithClass: class_
				       line: line] autorelease];
}









- initWithClass: (Class)class_
	   line: (size_t)line_
{
	self = [super initWithClass: class_];

	line = line_;

	return self;
}

- init
{
	Class c = isa;
	[self release];
	@throw [OFNotImplementedException exceptionWithClass: c
						    selector: _cmd];
}

- (OFString*)description
{
	if (description != nil)
		return description;

	description = [[OFString alloc] initWithFormat:
	    @"The JSON representation class %@ tried to parse is invalid in "







>
>
>
>
>
>
>
>











<
<
<
<
<
<
<
<







24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49








50
51
52
53
54
55
56
@implementation OFInvalidJSONException
+ exceptionWithClass: (Class)class_
		line: (size_t)line
{
	return [[[self alloc] initWithClass: class_
				       line: line] autorelease];
}

- init
{
	Class c = isa;
	[self release];
	@throw [OFNotImplementedException exceptionWithClass: c
						    selector: _cmd];
}

- initWithClass: (Class)class_
	   line: (size_t)line_
{
	self = [super initWithClass: class_];

	line = line_;

	return self;
}









- (OFString*)description
{
	if (description != nil)
		return description;

	description = [[OFString alloc] initWithFormat:
	    @"The JSON representation class %@ tried to parse is invalid in "