Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.

Commit f2d7fd7

Browse files
committed
localize use of CFStringCreate function
1 parent fdf53c5 commit f2d7fd7

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

GNUmakefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
include $(GNUSTEP_MAKEFILES)/common.make
44

55
LIBRARY_NAME = libMPWXmlKit
6+
GNUSTEP_BUILD_DIR = ~/Build
67

78
OBJCFLAGS += -Wno-import -fobjc-runtime=gnustep
89

@@ -48,7 +49,8 @@ libMPWXmlKit_OBJC_FILES = \
4849
MPWXmlAppleProplistGenerator.m\
4950
MPWXmlArchiver.m MPWXmlAttributes.m\
5051
MPWXmlGeneratorStream.m\
51-
MPWXmlParser.m \
52+
MPWXmlParser.m \
53+
MPWMAXParser.m \
5254
MPWXmlProplistGenerator.m MPWXmlSaxScanner.m\
5355
MPWXmlScanner.m \
5456
MPWXmlUnarchiver.m MPWXmlWrapperArchiver.m\
@@ -66,3 +68,9 @@ libMPWXmlKit_CFLAGS += -Wno-import
6668
include $(GNUSTEP_MAKEFILES)/library.make
6769
-include GNUmakefile.postamble
6870

71+
72+
test : libMPWXmlKit tester
73+
LD_LIBRARY_PATH=/home/gnustep/GNUstep/Library/Libraries:/usr/local/lib:/home/gnustep/Build/obj/ ./GNUstep/testobjectivexml
74+
75+
tester :
76+
clang -fobjc-runtime=gnustep-1.9 -I../MPWFoundation/.headers/ -I.headers -o GNUstep/testobjectivexml GNUstep/testobjectivexml.m -L/home/gnustep/Build/obj -lMPWXmlKit -lMPWFoundation -lgnustep-base -L/usr/local/lib/ -lobjc

MPWMAXParser.m

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,11 @@ -(BOOL)attributeName:(const char*)nameStart length:(int)nameLen value:(const cha
271271
return YES;
272272
}
273273
if ( highBit ) {
274-
int i;
275-
for (i=0;i< valueLen;i++ ) {
276-
if ( valueStart[i] & 128 ) {
277-
value = (id)CFStringCreateWithBytes(NULL, (unsigned char*)valueStart, valueLen, (CFStringEncoding)cfDataEncoding, NO);
278-
valueToRelease=value;
279-
break;
280-
}
281-
}
274+
valueToRelease=createNSStringIfAnyHighBitSet(valueStart, valueLen,cfDataEncoding);
282275
}
276+
if ( valueToRelease) {
277+
value=valueToRelease;
278+
}
283279
if ( !value ) {
284280
value = MAKEDATA( valueStart, valueLen );
285281
}
@@ -966,6 +962,17 @@ -(void)clearAttributes
966962
[self _setAttributes:nil];
967963
}
968964

965+
static inline NSString* createNSStringIfAnyHighBitSet( const char *start, long len, long cfDataEncoding ) {
966+
for (int i=0;i< len;i++ ) {
967+
if ( start[i] & 128 ) {
968+
return (id)CFStringCreateWithBytes(NULL, (const unsigned char*)start, len, (CFStringEncoding)cfDataEncoding, NO);
969+
// if (!str ) { return YES; }
970+
break;
971+
}
972+
}
973+
return nil;
974+
}
975+
969976
-(BOOL)makeText:(const char*)start length:(long)len firstEntityOffset:(long)entityOffset
970977
{
971978
idstringToRelease=nil;
@@ -976,19 +983,13 @@ -(BOOL)makeText:(const char*)start length:(long)len firstEntityOffset:(long)enti
976983

977984
}
978985
if ( CHARACTERDATAALLOWED ) {
979-
int i;
980-
//NSLog(@"allowing characters, tagStackLen: %d and sending to %@",tagStackLen,characterHandler);
981-
if ( autotranslateUTF8 ) {
982-
for (i=0;i< len;i++ ) {
983-
if ( start[i] & 128 ) {
984-
str = (id)CFStringCreateWithBytes(NULL, (const unsigned char*)start, len, (CFStringEncoding)cfDataEncoding, NO);
985-
stringToRelease=str;
986-
//if (!str ) { return YES; }
987-
break;
988-
}
989-
}
986+
//NSLog(@"allowing characters, tagStackLen: %d and sending to %@",tagStackLen,characterHandler);
987+
if ( autotranslateUTF8 ) {
988+
stringToRelease=createNSStringIfAnyHighBitSet(start, len,cfDataEncoding);
990989
}
991-
if ( !str ) {
990+
if ( stringToRelease) {
991+
str = stringToRelease;
992+
} else {
992993
str= MAKEDATA( start, len );
993994
}
994995
if ( str ) {

0 commit comments

Comments
 (0)