︙ | | | ︙ | |
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
|
static state_function lookupTable[OF_XMLPARSER_NUM_STATES];
static OF_INLINE void
cache_append(OFDataArray *cache, const char *string,
of_string_encoding_t encoding, size_t length)
{
if (OF_LIKELY(encoding == OF_STRING_ENCODING_UTF_8))
[cache addItemsFromCArray: string
count: length];
else {
void *pool = objc_autoreleasePoolPush();
OFString *tmp = [OFString stringWithCString: string
encoding: encoding
length: length];
[cache addItemsFromCArray: [tmp UTF8String]
count: [tmp UTF8StringLength]];
objc_autoreleasePoolPop(pool);
}
}
static OFString*
transform_string(OFDataArray *cache, size_t cut, BOOL unescape,
id <OFStringXMLUnescapingDelegate> delegate)
{
char *cArray;
size_t i, length;
BOOL hasEntities = NO;
OFMutableString *ret;
cArray = [cache cArray];
length = [cache count] - cut;
for (i = 0; i < length; i++) {
if (cArray[i] == '\r') {
if (i + 1 < length && cArray[i + 1] == '\n') {
[cache removeItemAtIndex: i];
cArray = [cache cArray];
i--;
length--;
} else
cArray[i] = '\n';
} else if (cArray[i] == '&')
hasEntities = YES;
}
ret = [OFMutableString stringWithUTF8String: cArray
length: length];
if (unescape && hasEntities)
return [ret stringByXMLUnescapingWithDelegate: delegate];
[ret makeImmutable];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
static state_function lookupTable[OF_XMLPARSER_NUM_STATES];
static OF_INLINE void
cache_append(OFDataArray *cache, const char *string,
of_string_encoding_t encoding, size_t length)
{
if (OF_LIKELY(encoding == OF_STRING_ENCODING_UTF_8))
[cache addItems: string
count: length];
else {
void *pool = objc_autoreleasePoolPush();
OFString *tmp = [OFString stringWithCString: string
encoding: encoding
length: length];
[cache addItems: [tmp UTF8String]
count: [tmp UTF8StringLength]];
objc_autoreleasePoolPop(pool);
}
}
static OFString*
transform_string(OFDataArray *cache, size_t cut, BOOL unescape,
id <OFStringXMLUnescapingDelegate> delegate)
{
char *items;
size_t i, length;
BOOL hasEntities = NO;
OFMutableString *ret;
items = [cache items];
length = [cache count] - cut;
for (i = 0; i < length; i++) {
if (items[i] == '\r') {
if (i + 1 < length && items[i + 1] == '\n') {
[cache removeItemAtIndex: i];
items = [cache items];
i--;
length--;
} else
items[i] = '\n';
} else if (items[i] == '&')
hasEntities = YES;
}
ret = [OFMutableString stringWithUTF8String: items
length: length];
if (unescape && hasEntities)
return [ret stringByXMLUnescapingWithDelegate: delegate];
[ret makeImmutable];
|
︙ | | | ︙ | |
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
|
return;
if ((length = *i - *last) > 0)
cache_append(cache, buffer + *last, encoding, length);
pool = objc_autoreleasePoolPush();
cacheCString = [cache cArray];
cacheLength = [cache count];
cacheString = [OFString stringWithUTF8String: cacheCString
length: cacheLength];
if ((tmp = memchr(cacheCString, ':', cacheLength)) != NULL) {
name = [[OFString alloc]
initWithUTF8String: tmp + 1
|
|
|
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
|
return;
if ((length = *i - *last) > 0)
cache_append(cache, buffer + *last, encoding, length);
pool = objc_autoreleasePoolPush();
cacheCString = [cache items];
cacheLength = [cache count];
cacheString = [OFString stringWithUTF8String: cacheCString
length: cacheLength];
if ((tmp = memchr(cacheCString, ':', cacheLength)) != NULL) {
name = [[OFString alloc]
initWithUTF8String: tmp + 1
|
︙ | | | ︙ | |
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
|
return;
if ((length = *i - *last) > 0)
cache_append(cache, buffer + *last, encoding, length);
pool = objc_autoreleasePoolPush();
cacheCString = [cache cArray];
cacheLength = [cache count];
cacheString = [OFString stringWithUTF8String: cacheCString
length: cacheLength];
if ((tmp = memchr(cacheCString, ':', cacheLength)) != NULL) {
name = [[OFString alloc]
initWithUTF8String: tmp + 1
|
|
|
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
|
return;
if ((length = *i - *last) > 0)
cache_append(cache, buffer + *last, encoding, length);
pool = objc_autoreleasePoolPush();
cacheCString = [cache items];
cacheLength = [cache count];
cacheString = [OFString stringWithUTF8String: cacheCString
length: cacheLength];
if ((tmp = memchr(cacheCString, ':', cacheLength)) != NULL) {
name = [[OFString alloc]
initWithUTF8String: tmp + 1
|
︙ | | | ︙ | |
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
|
return;
if ((length = *i - *last) > 0)
cache_append(cache, buffer + *last, encoding, length);
pool = objc_autoreleasePoolPush();
cacheString = [OFMutableString stringWithUTF8String: [cache cArray]
length: [cache count]];
[cacheString deleteEnclosingWhitespaces];
/* Prevent a useless copy later */
[cacheString makeImmutable];
cacheCString = [cacheString UTF8String];
cacheLength = [cacheString UTF8StringLength];
|
|
|
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
|
return;
if ((length = *i - *last) > 0)
cache_append(cache, buffer + *last, encoding, length);
pool = objc_autoreleasePoolPush();
cacheString = [OFMutableString stringWithUTF8String: [cache items]
length: [cache count]];
[cacheString deleteEnclosingWhitespaces];
/* Prevent a useless copy later */
[cacheString makeImmutable];
cacheCString = [cacheString UTF8String];
cacheLength = [cacheString UTF8StringLength];
|
︙ | | | ︙ | |