Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Rename -[stringValue] to -[XMLString] in OFXMLElement. |
|---|---|
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
5c80b8838fb169afedb881c962609fa3 |
| User & Date: | js 2011-03-31 11:45:30.000 |
Context
|
2011-03-31
| ||
| 11:55 | Rename +[elementWithString:] to +[elementWithXMLString:] for clarity. check-in: 253fe5d154 user: js tags: trunk | |
| 11:45 | Rename -[stringValue] to -[XMLString] in OFXMLElement. check-in: 5c80b8838f user: js tags: trunk | |
| 11:44 | Get rid of useless -[bindDefaultNamespace:] in OFXMLElement. check-in: 1824567235 user: js tags: trunk | |
Changes
Changes to src/OFXMLElement.h.
| ︙ | ︙ | |||
217 218 219 220 221 222 223 | */ - (OFArray*)children; /** * \return A new autoreleased OFString representing the OFXMLElement as an * XML string */ | | | 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | */ - (OFArray*)children; /** * \return A new autoreleased OFString representing the OFXMLElement as an * XML string */ - (OFString*)XMLString; /** * Adds the specified attribute. * * If an attribute with the same name and namespace already exists, it is not * added. * |
| ︙ | ︙ |
Changes to src/OFXMLElement.m.
| ︙ | ︙ | |||
261 262 263 264 265 266 267 |
}
- (OFArray*)children
{
return [[children copy] autorelease];
}
| | | 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
}
- (OFArray*)children
{
return [[children copy] autorelease];
}
- (OFString*)_XMLStringWithParent: (OFXMLElement*)parent
{
OFAutoreleasePool *pool, *pool2;
char *str_c;
size_t len, i, j, attrs_count;
OFString *prefix, *parent_prefix;
OFXMLAttribute **attrs_carray;
OFString *ret, *tmp;
|
| ︙ | ︙ | |||
432 433 434 435 436 437 438 | append = [tmp methodForSelector: @selector(appendCStringWithoutUTF8Checking:)]; for (j = 0; j < children_count; j++) append(tmp, @selector( appendCStringWithoutUTF8Checking:), [[children_carray[j] | | | 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
append = [tmp methodForSelector:
@selector(appendCStringWithoutUTF8Checking:)];
for (j = 0; j < children_count; j++)
append(tmp, @selector(
appendCStringWithoutUTF8Checking:),
[[children_carray[j]
_XMLStringWithParent: self] cString]);
len += [tmp cStringLength] + [name cStringLength] + 2;
@try {
str_c = [self resizeMemory: str_c
toSize: len];
} @catch (id e) {
[self freeMemory: str_c];
|
| ︙ | ︙ | |||
482 483 484 485 486 487 488 |
length: len];
} @finally {
[self freeMemory: str_c];
}
return ret;
}
| | | | | 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
length: len];
} @finally {
[self freeMemory: str_c];
}
return ret;
}
- (OFString*)XMLString
{
return [self _XMLStringWithParent: nil];
}
- (OFString*)description
{
return [self XMLString];
}
- (void)addAttribute: (OFXMLAttribute*)attr
{
if (name == nil)
@throw [OFInvalidArgumentException newWithClass: isa
selector: _cmd];
|
| ︙ | ︙ |
Changes to tests/OFXMLElementBuilderTests.m.
| ︙ | ︙ | |||
47 48 49 50 51 52 53 | "</foo>"; [p setDelegate: builder]; [builder setDelegate: self]; TEST(@"Building elements from parsed XML", R([p parseString: str]) && | | | | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | "</foo>"; [p setDelegate: builder]; [builder setDelegate: self]; TEST(@"Building elements from parsed XML", R([p parseString: str]) && elem[0] != nil && [[elem[0] XMLString] isEqual: str] && R([p parseString: @"<!--foo-->"]) && elem[1] != nil && [[elem[1] XMLString] isEqual: @"<!--foo-->"]) [elem[0] release]; [elem[1] release]; [pool drain]; } @end |
Changes to tests/OFXMLElementTests.m.
| ︙ | ︙ | |||
30 31 32 33 34 35 36 |
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
OFXMLElement *elem[4];
OFArray *a;
TEST(@"+[elementWithName:]",
(elem[0] = [OFXMLElement elementWithName: @"foo"]) &&
| | | | | | | | | | | | | | | | | | 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
OFXMLElement *elem[4];
OFArray *a;
TEST(@"+[elementWithName:]",
(elem[0] = [OFXMLElement elementWithName: @"foo"]) &&
[[elem[0] XMLString] isEqual: @"<foo/>"])
TEST(@"+[elementWithName:stringValue:]",
(elem[1] = [OFXMLElement elementWithName: @"foo"
stringValue: @"b&ar"]) &&
[[elem[1] XMLString] isEqual: @"<foo>b&ar</foo>"])
TEST(@"+[elementWithName:namespace:]",
(elem[2] = [OFXMLElement elementWithName: @"foo"
namespace: @"urn:objfw:test"]) &&
R([elem[2] addAttributeWithName: @"test"
stringValue: @"test"]) &&
R([elem[2] setPrefix: @"objfw-test"
forNamespace: @"urn:objfw:test"]) &&
[[elem[2] XMLString] isEqual: @"<objfw-test:foo test='test'/>"] &&
(elem[3] = [OFXMLElement elementWithName: @"foo"
namespace: @"urn:objfw:test"]) &&
R([elem[3] addAttributeWithName: @"test"
stringValue: @"test"]) &&
[[elem[3] XMLString] isEqual:
@"<foo xmlns='urn:objfw:test' test='test'/>"])
TEST(@"+[elementWithName:namespace:stringValue:]",
(elem[3] = [OFXMLElement elementWithName: @"foo"
namespace: @"urn:objfw:test"
stringValue: @"x"]) &&
R([elem[3] setPrefix: @"objfw-test"
forNamespace: @"urn:objfw:test"]) &&
[[elem[3] XMLString] isEqual:
@"<objfw-test:foo>x</objfw-test:foo>"])
TEST(@"+[elementWithCharacters:]",
(elem[3] = [OFXMLElement elementWithCharacters: @"<foo>"]) &&
[[elem[3] XMLString] isEqual: @"<foo>"])
TEST(@"+[elementWithCDATA:]",
(elem[3] = [OFXMLElement elementWithCDATA: @"<foo>"]) &&
[[elem[3] XMLString] isEqual: @"<![CDATA[<foo>]]>"]);
TEST(@"+[elementWithComment:]",
(elem[3] = [OFXMLElement elementWithComment: @" comment "]) &&
[[elem[3] XMLString] isEqual: @"<!-- comment -->"])
TEST(@"-[addAttributeWithName:stringValue:]",
R([elem[0] addAttributeWithName: @"foo"
stringValue: @"b&ar"]) &&
[[elem[0] XMLString] isEqual: @"<foo foo='b&ar'/>"] &&
R([elem[1] addAttributeWithName: @"foo"
stringValue: @"b&ar"]) &&
[[elem[1] XMLString] isEqual:
@"<foo foo='b&ar'>b&ar</foo>"])
TEST(@"-[setPrefix:forNamespace:]",
R([elem[1] setPrefix: @"objfw-test"
forNamespace: @"urn:objfw:test"]))
TEST(@"-[addAttributeWithName:namespace:stringValue:]",
R([elem[1] addAttributeWithName: @"foo"
namespace: @"urn:objfw:test"
stringValue: @"bar"]) &&
R([elem[1] addAttributeWithName: @"foo"
namespace: @"urn:objfw:test"
stringValue: @"ignored"]) &&
[[elem[1] XMLString] isEqual:
@"<foo foo='b&ar' objfw-test:foo='bar'>b&ar</foo>"])
TEST(@"-[removeAttributeForName:namespace:]",
R([elem[1] removeAttributeForName: @"foo"]) &&
[[elem[1] XMLString] isEqual:
@"<foo objfw-test:foo='bar'>b&ar</foo>"] &&
R([elem[1] removeAttributeForName: @"foo"
namespace: @"urn:objfw:test"]) &&
[[elem[1] XMLString] isEqual: @"<foo>b&ar</foo>"])
TEST(@"-[addChild:]",
R([elem[0] addChild: [OFXMLElement elementWithName: @"bar"]]) &&
[[elem[0] XMLString] isEqual:
@"<foo foo='b&ar'><bar/></foo>"] &&
R([elem[2] addChild: [OFXMLElement elementWithName: @"bar"
namespace: @"urn:objfw:test"]]) &&
[[elem[2] XMLString] isEqual:
@"<objfw-test:foo test='test'><objfw-test:bar/></objfw-test:foo>"])
TEST(@"-[elementsForName:namespace:]",
(a = [elem[2] elementsForName: @"bar"
namespace: @"urn:objfw:test"]) &&
[a count] == 1 && [[[a firstObject] XMLString] isEqual:
@"<bar xmlns='urn:objfw:test'/>"])
[pool drain];
}
@end
|