Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -56,11 +56,11 @@ ${ATOMIC_H} \ macros.h \ objfw-defs.h \ ${THREADING_H} -SRCS += ${ASPRINTF_M} \ +SRCS += ${ASPRINTF_M} \ ${FOUNDATION_COMPAT_M} \ iso_8859_15.m \ windows_1252.m \ ${OBJC_PROPERTIES_M} \ ${OBJC_SYNC_M} Index: src/OFArray.h ================================================================== --- src/OFArray.h +++ src/OFArray.h @@ -144,11 +144,11 @@ * Returns the index of the first object that is equivalent to the specified * object or OF_INVALID_INDEX if it was not found. * * \param object The object whose index is returned * \return The index of the first object equivalent to the specified object - * or OF_INVALID_INDEX if it was not found + * or OF_INVALID_INDEX if it was not found */ - (size_t)indexOfObject: (id)object; /** * Returns the index of the first object that has the same address as the Index: src/OFNumber.m ================================================================== --- src/OFNumber.m +++ src/OFNumber.m @@ -82,11 +82,11 @@ return (t)value.double_; \ default: \ @throw [OFInvalidFormatException newWithClass: isa]; \ } #define CALCULATE(o, n) \ - switch (type) { \ + switch (type) { \ case OF_NUMBER_BOOL: \ return [OFNumber numberWithBool: \ value.bool_ o [n boolValue]]; \ case OF_NUMBER_CHAR: \ return [OFNumber numberWithChar: \ @@ -165,11 +165,11 @@ value.double_ o [n doubleValue]]; \ default: \ @throw [OFInvalidFormatException newWithClass: isa]; \ } #define CALCULATE2(o, n) \ - switch (type) { \ + switch (type) { \ case OF_NUMBER_BOOL: \ return [OFNumber numberWithBool: \ value.bool_ o [n boolValue]]; \ case OF_NUMBER_CHAR: \ return [OFNumber numberWithChar: \ Index: src/OFStreamObserver.m ================================================================== --- src/OFStreamObserver.m +++ src/OFStreamObserver.m @@ -79,12 +79,12 @@ #ifdef OF_HAVE_POLL FDs = [[OFDataArray alloc] initWithItemSize: sizeof(struct pollfd)]; FDToStream = [[OFMutableDictionary alloc] init]; #else - FD_ZERO(&readfds); - FD_ZERO(&writefds); + FD_ZERO(&readFDs); + FD_ZERO(&writeFDs); #endif #ifndef _WIN32 if (pipe(cancelFD)) @throw [OFInitializationFailedException @@ -226,12 +226,12 @@ int fileDescriptor = [stream fileDescriptor]; FD_SET(fileDescriptor, FDSet); FD_SET(fileDescriptor, &exceptFDs); - if (fd >= nfds) - nfds = fd + 1; + if (fileDescriptor >= nFDs) + nFDs = fileDescriptor + 1; [pool release]; } - (void)_removeStream: (OFStream*)stream @@ -241,11 +241,11 @@ int fileDescriptor = [stream fileDescriptor]; FD_CLR(fileDescriptor, FDSet); if (!FD_ISSET(fileDescriptor, otherFDSet)) - FD_CLR(fileDescriptor, &exceptfds); + FD_CLR(fileDescriptor, &exceptFDs); } #endif - (void)addStreamToObserveForReading: (OFStream*)stream { Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -85,18 +85,18 @@ @throw [OFAlreadyConnectedException newWithClass: isa socket: self]; #ifdef HAVE_THREADSAFE_GETADDRINFO struct addrinfo hints, *res, *res0; - char port_s[7]; + char portCString[7]; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; - snprintf(port_s, 7, "%" PRIu16, port); + snprintf(portCString, 7, "%" PRIu16, port); - if (getaddrinfo([host cString], port_s, &hints, &res0)) + if (getaddrinfo([host cString], portCString, &hints, &res0)) @throw [OFAddressTranslationFailedException newWithClass: isa socket: self host: host]; for (res = res0; res != NULL; res = res->ai_next) { @@ -210,18 +210,18 @@ @throw [OFAlreadyConnectedException newWithClass: isa socket: self]; #ifdef HAVE_THREADSAFE_GETADDRINFO struct addrinfo hints, *res; - char port_s[7]; + char portCString[7]; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; - snprintf(port_s, 7, "%" PRIu16, port); + snprintf(portCString, 7, "%" PRIu16, port); - if (getaddrinfo([host cString], port_s, &hints, &res)) + if (getaddrinfo([host cString], portCString, &hints, &res)) @throw [OFAddressTranslationFailedException newWithClass: isa socket: self host: host]; if ((sock = socket(res->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET) @@ -345,36 +345,36 @@ isListening = YES; } - (OFTCPSocket*)accept { - OFTCPSocket *newsock; + OFTCPSocket *newSocket; struct sockaddr *addr; - socklen_t addrlen; - int s; + socklen_t addrLen; + int newSock; - newsock = [[[isa alloc] init] autorelease]; - addrlen = sizeof(struct sockaddr); + newSocket = [[[isa alloc] init] autorelease]; + addrLen = sizeof(struct sockaddr); @try { - addr = [newsock allocMemoryWithSize: sizeof(struct sockaddr)]; + addr = [newSocket allocMemoryWithSize: sizeof(struct sockaddr)]; } @catch (id e) { - [newsock release]; + [newSocket release]; @throw e; } - if ((s = accept(sock, addr, &addrlen)) == INVALID_SOCKET) { - [newsock release]; + if ((newSock = accept(sock, addr, &addrLen)) == INVALID_SOCKET) { + [newSocket release]; @throw [OFAcceptFailedException newWithClass: isa socket: self]; } - newsock->sock = s; - newsock->sockAddr = addr; - newsock->sockAddrLen = addrlen; + newSocket->sock = newSock; + newSocket->sockAddr = addr; + newSocket->sockAddrLen = addrLen; - return newsock; + return newSocket; } - (void)setKeepAlivesEnabled: (BOOL)enable { int v = enable; @@ -384,16 +384,18 @@ stream: self]; } - (OFString*)remoteAddress { + char *host; + if (sockAddr == NULL || sockAddrLen == 0) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; #ifdef HAVE_THREADSAFE_GETADDRINFO - char *host = [self allocMemoryWithSize: NI_MAXHOST]; + host = [self allocMemoryWithSize: NI_MAXHOST]; @try { if (getnameinfo(sockAddr, sockAddrLen, host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)) @throw [OFAddressTranslationFailedException @@ -402,12 +404,10 @@ return [OFString stringWithCString: host]; } @finally { [self freeMemory: host]; } #else - char *host; - # ifdef OF_THREADS [mutex lock]; @try { # endif Index: src/OFThread.h ================================================================== --- src/OFThread.h +++ src/OFThread.h @@ -32,11 +32,11 @@ #if !defined(__GNUC__) || __GNUC__ != 4 || __GNUC_MINOR__ != 4 || \ __GNUC_PATCHLEVEL__ != 4 @protected #endif void (*destructor)(id); - of_list_object_t *listobj; + of_list_object_t *listObject; BOOL initialized; } /** * \return A new autoreleased Thread Local Storage key @@ -77,11 +77,11 @@ enum { OF_THREAD_NOT_RUNNING, OF_THREAD_RUNNING, OF_THREAD_WAITING_FOR_JOIN } running; - id retval; + id returnValue; } /** * \return A new, autoreleased thread */ @@ -89,11 +89,11 @@ /** * \param obj An object that is passed to the main method as a copy or nil * \return A new, autoreleased thread */ -+ threadWithObject: (id)obj; ++ threadWithObject: (id)object; /** * Sets the Thread Local Storage for the specified key. * * The specified object is first retained and then the object stored before is @@ -101,11 +101,11 @@ * released and don't want any new object for the TLS key. * * \param key The Thread Local Storage key * \param obj The object the Thread Local Storage key will be set to */ -+ (void)setObject: (id)obj ++ (void)setObject: (id)object forTLSKey: (OFTLSKey*)key; /** * Returns the object for the specified Thread Local Storage key. * @@ -122,22 +122,22 @@ + (OFThread*)currentThread; /** * Suspends execution of the current thread for the specified time interval. * - * \param sec The number of seconds to sleep + * \param seconds The number of seconds to sleep */ -+ (void)sleepForTimeInterval: (int64_t)sec; ++ (void)sleepForTimeInterval: (int64_t)seconds; /** * Suspends execution of the current thread for the specified time interval. * - * \param sec The number of seconds to sleep - * \param usec The number of microseconds to sleep + * \param seconds The number of seconds to sleep + * \param microseconds The number of microseconds to sleep */ -+ (void)sleepForTimeInterval: (int64_t)sec - microseconds: (uint32_t)usec; ++ (void)sleepForTimeInterval: (int64_t)seconds + microseconds: (uint32_t)microseconds; /** * Suspends execution of the current thread until the specified date. */ + (void)sleepUntilDate: (OFDate*)date; @@ -156,17 +156,17 @@ /** * Terminates the current thread, letting it return the specified object. * * \param obj The object which the terminated thread will return */ -+ (void)terminateWithObject: (id)obj; ++ (void)terminateWithObject: (id)object; /** * \param obj An object that is passed to the main method as a copy or nil * \return An initialized OFThread. */ -- initWithObject: (id)obj; +- initWithObject: (id)object; /** * The main routine of the thread. You need to reimplement this! * * It can access the object passed to the threadWithObject or initWithObject @@ -232,11 +232,11 @@ * \brief A class implementing a condition variable for thread synchronization. */ @interface OFCondition: OFMutex { of_condition_t condition; - BOOL cond_initialized; + BOOL conditionInitialized; } /** * \return A new, autoreleased OFCondition */ Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -47,38 +47,38 @@ #import "OFThreadStartFailedException.h" #import "OFThreadStillRunningException.h" #import "threading.h" -static OFList *tlskeys; -static of_tlskey_t thread_self; +static OFList *TLSKeys; +static of_tlskey_t threadSelf; static id -call_main(id obj) +call_main(OFThread *thread) { #if defined(OF_GNU_RUNTIME) || defined(OF_OLD_GNU_RUNTIME) objc_thread_add(); #endif - if (!of_tlskey_set(thread_self, obj)) + if (!of_tlskey_set(threadSelf, thread)) @throw [OFInitializationFailedException - newWithClass: [obj class]]; + newWithClass: [thread class]]; /* * Nasty workaround for thread implementations which can't return a * value on join. */ - ((OFThread*)obj)->retval = [[obj main] retain]; + thread->returnValue = [[thread main] retain]; - [obj handleTermination]; + [thread handleTermination]; - ((OFThread*)obj)->running = OF_THREAD_WAITING_FOR_JOIN; + thread->running = OF_THREAD_WAITING_FOR_JOIN; [OFTLSKey callAllDestructors]; [OFAutoreleasePool releaseAll]; - [obj release]; + [thread release]; #if defined(OF_GNU_RUNTIME) || defined(OF_OLD_GNU_RUNTIME) objc_thread_remove(); #endif @@ -89,106 +89,106 @@ + (void)initialize { if (self != [OFThread class]) return; - if (!of_tlskey_new(&thread_self)) + if (!of_tlskey_new(&threadSelf)) @throw [OFInitializationFailedException newWithClass: self]; } + thread { return [[[self alloc] init] autorelease]; } -+ threadWithObject: (id)obj ++ threadWithObject: (id)object { - return [[[self alloc] initWithObject: obj] autorelease]; + return [[[self alloc] initWithObject: object] autorelease]; } -+ (void)setObject: (id)obj ++ (void)setObject: (id)object forTLSKey: (OFTLSKey*)key { - id old = of_tlskey_get(key->key); + id oldObject = of_tlskey_get(key->key); - if (!of_tlskey_set(key->key, [obj retain])) + if (!of_tlskey_set(key->key, [object retain])) @throw [OFInvalidArgumentException newWithClass: self selector: _cmd]; - [old release]; + [oldObject release]; } + (id)objectForTLSKey: (OFTLSKey*)key { return [[of_tlskey_get(key->key) retain] autorelease]; } + (OFThread*)currentThread { - return [[of_tlskey_get(thread_self) retain] autorelease]; + return [[of_tlskey_get(threadSelf) retain] autorelease]; } -+ (void)sleepForTimeInterval: (int64_t)sec ++ (void)sleepForTimeInterval: (int64_t)seconds { - if (sec < 0) + if (seconds < 0) @throw [OFOutOfRangeException newWithClass: self]; #ifndef _WIN32 - if (sec > UINT_MAX) + if (seconds > UINT_MAX) @throw [OFOutOfRangeException newWithClass: self]; - sleep((unsigned int)sec); + sleep((unsigned int)seconds); #else - if (sec * 1000 > UINT_MAX) + if (seconds * 1000 > UINT_MAX) @throw [OFOutOfRangeException newWithClass: self]; - Sleep((unsigned int)sec * 1000); + Sleep((unsigned int)seconds * 1000); #endif } -+ (void)sleepForTimeInterval: (int64_t)sec - microseconds: (uint32_t)usec ++ (void)sleepForTimeInterval: (int64_t)seconds + microseconds: (uint32_t)microseconds { - if (sec < 0) + if (seconds < 0) @throw [OFOutOfRangeException newWithClass: self]; #ifndef _WIN32 - sleep((unsigned int)sec); - usleep(usec); + sleep((unsigned int)seconds); + usleep(microseconds); #else - if (sec * 1000 + usec / 1000 > UINT_MAX) + if (seconds * 1000 + microseconds / 1000 > UINT_MAX) @throw [OFOutOfRangeException newWithClass: self]; - Sleep((unsigned int)sec * 1000 + usec / 1000); + Sleep((unsigned int)seconds * 1000 + microseconds / 1000); #endif } + (void)sleepUntilDate: (OFDate*)date { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFDate *now = [OFDate date]; - int64_t sec; - uint32_t usec; + int64_t seconds; + uint32_t microseconds; - if ((sec = [date timeIntervalSinceDate: now]) < 0) + if ((seconds = [date timeIntervalSinceDate: now]) < 0) @throw [OFOutOfRangeException newWithClass: self]; - usec = [date microsecondsOfTimeIntervalSinceDate: now]; + microseconds = [date microsecondsOfTimeIntervalSinceDate: now]; [pool release]; #ifndef _WIN32 - if (sec > UINT_MAX) + if (seconds > UINT_MAX) @throw [OFOutOfRangeException newWithClass: self]; - sleep((unsigned int)sec); - usleep(usec); + sleep((unsigned int)seconds); + usleep(microseconds); #else - if (sec * 1000 + usec / 1000 > UINT_MAX) + if (seconds * 1000 + microseconds / 1000 > UINT_MAX) @throw [OFOutOfRangeException newWithClass: self]; - Sleep(sec * 1000 + usec / 1000); + Sleep(seconds * 1000 + microseconds / 1000); #endif } + (void)yield { @@ -202,16 +202,16 @@ + (void)terminate { [self terminateWithObject: nil]; } -+ (void)terminateWithObject: (id)obj ++ (void)terminateWithObject: (id)object { - OFThread *thread = of_tlskey_get(thread_self); + OFThread *thread = of_tlskey_get(threadSelf); if (thread != nil) { - thread->retval = [obj retain]; + thread->returnValue = [object retain]; [thread handleTermination]; thread->running = OF_THREAD_WAITING_FOR_JOIN; } @@ -226,16 +226,16 @@ #endif of_thread_exit(); } -- initWithObject: (id)obj +- initWithObject: (id)object_ { self = [super init]; @try { - object = [obj retain]; + object = [object_ retain]; } @catch (id e) { [self release]; @throw e; } @@ -260,11 +260,11 @@ @throw [OFThreadStillRunningException newWithClass: isa thread: self]; if (running == OF_THREAD_WAITING_FOR_JOIN) { of_thread_detach(thread); - [retval release]; + [returnValue release]; } [self retain]; if (!of_thread_new(&thread, call_main, self)) { @@ -282,11 +282,11 @@ @throw [OFThreadJoinFailedException newWithClass: isa thread: self]; running = OF_THREAD_NOT_RUNNING; - return retval; + return returnValue; } - (void)dealloc { if (running == OF_THREAD_RUNNING) @@ -299,21 +299,21 @@ */ if (running == OF_THREAD_WAITING_FOR_JOIN) of_thread_detach(thread); [object release]; - [retval release]; + [returnValue release]; [super dealloc]; } @end @implementation OFTLSKey + (void)initialize { if (self == [OFTLSKey class]) - tlskeys = [[OFList alloc] init]; + TLSKeys = [[OFList alloc] init]; } + TLSKey { return [[[self alloc] init] autorelease]; @@ -326,12 +326,12 @@ + (void)callAllDestructors { of_list_object_t *iter; - @synchronized (tlskeys) { - for (iter = [tlskeys firstListObject]; iter != NULL; + @synchronized (TLSKeys) { + for (iter = [TLSKeys firstListObject]; iter != NULL; iter = iter->next) { OFTLSKey *key = (OFTLSKey*)iter->object; if (key->destructor != NULL) key->destructor(iter->object); @@ -348,12 +348,12 @@ @throw [OFInitializationFailedException newWithClass: isa]; initialized = YES; - @synchronized (tlskeys) { - listobj = [tlskeys appendObject: self]; + @synchronized (TLSKeys) { + listObject = [TLSKeys appendObject: self]; } } @catch (id e) { [self release]; @throw e; } @@ -377,13 +377,13 @@ if (initialized) of_tlskey_free(key); /* In case we called [self release] in init */ - if (listobj != NULL) { - @synchronized (tlskeys) { - [tlskeys removeListObject: listobj]; + if (listObject != NULL) { + @synchronized (TLSKeys) { + [TLSKeys removeListObject: listObject]; } } [super dealloc]; } @@ -454,11 +454,11 @@ Class c = isa; [self release]; @throw [OFInitializationFailedException newWithClass: c]; } - cond_initialized = YES; + conditionInitialized = YES; return self; } - (void)wait @@ -482,14 +482,14 @@ condition: self]; } - (void)dealloc { - if (cond_initialized) + if (conditionInitialized) if (!of_condition_free(&condition)) @throw [OFConditionStillWaitingException newWithClass: isa condition: self]; [super dealloc]; } @end Index: src/OFURL.h ================================================================== --- src/OFURL.h +++ src/OFURL.h @@ -45,39 +45,39 @@ @property (copy) OFString *query; @property (copy) OFString *fragment; #endif /** - * \param str A string describing a URL - * \return A new, autoreleased OFURL - */ -+ URLWithString: (OFString*)str; - -/** - * \param str A string describing a URL - * \param url An URL to which the string is relative - * \return A new, autoreleased OFURL - */ -+ URLWithString: (OFString*)str - relativeToURL: (OFURL*)url; - -/** - * Initializes an already allocated OFURL. - * - * \param str A string describing a URL - * \return An initialized OFURL - */ -- initWithString: (OFString*)str; - -/** - * Initializes an already allocated OFURL. - * - * \param str A string describing a URL - * \param url A URL to which the string is relative - * \return An initialized OFURL - */ -- initWithString: (OFString*)str + * \param string A string describing a URL + * \return A new, autoreleased OFURL + */ ++ URLWithString: (OFString*)string; + +/** + * \param string A string describing a URL + * \param URL An URL to which the string is relative + * \return A new, autoreleased OFURL + */ ++ URLWithString: (OFString*)string + relativeToURL: (OFURL*)URL; + +/** + * Initializes an already allocated OFURL. + * + * \param string A string describing a URL + * \return An initialized OFURL + */ +- initWithString: (OFString*)string; + +/** + * Initializes an already allocated OFURL. + * + * \param string A string describing a URL + * \param URL A URL to which the string is relative + * \return An initialized OFURL + */ +- initWithString: (OFString*)string relativeToURL: (OFURL*)url; /** * \return The scheme part of the URL */ Index: src/OFURL.m ================================================================== --- src/OFURL.m +++ src/OFURL.m @@ -30,15 +30,15 @@ #import "OFOutOfMemoryException.h" #import "macros.h" #define ADD_STR_HASH(str) \ - h = [str hash]; \ - OF_HASH_ADD(hash, h >> 24); \ - OF_HASH_ADD(hash, (h >> 16) & 0xFF); \ - OF_HASH_ADD(hash, (h >> 8) & 0xFF); \ - OF_HASH_ADD(hash, h & 0xFF); + tmp = [str hash]; \ + OF_HASH_ADD(hash, tmp >> 24); \ + OF_HASH_ADD(hash, (tmp >> 16) & 0xFF); \ + OF_HASH_ADD(hash, (tmp >> 8) & 0xFF); \ + OF_HASH_ADD(hash, tmp & 0xFF); static OF_INLINE OFString* resolve_relative_path(OFString *path) { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; @@ -48,24 +48,24 @@ array = [[[path componentsSeparatedByString: @"/"] mutableCopy] autorelease]; while (!done) { - id *array_c = [array cArray]; - size_t i, array_len = [array count]; + id *cArray = [array cArray]; + size_t i, length = [array count]; done = YES; - for (i = 0; i < array_len; i++) { - if ([array_c[i] isEqual: @"."]) { + for (i = 0; i < length; i++) { + if ([cArray[i] isEqual: @"."]) { [array removeObjectAtIndex: i]; done = NO; break; } - if ([array_c[i] isEqual: @".."]) { + if ([cArray[i] isEqual: @".."]) { [array removeObjectAtIndex: i]; if (i > 0) [array removeObjectAtIndex: i - 1]; @@ -82,210 +82,211 @@ return [ret autorelease]; } @implementation OFURL -+ URLWithString: (OFString*)str -{ - return [[[self alloc] initWithString: str] autorelease]; -} - -+ URLWithString: (OFString*)str - relativeToURL: (OFURL*)url -{ - return [[[self alloc] initWithString: str - relativeToURL: url] autorelease]; -} - -- initWithString: (OFString*)str -{ - char *str_c, *str_c2 = NULL; ++ URLWithString: (OFString*)string +{ + return [[[self alloc] initWithString: string] autorelease]; +} + ++ URLWithString: (OFString*)string + relativeToURL: (OFURL*)URL +{ + return [[[self alloc] initWithString: string + relativeToURL: URL] autorelease]; +} + +- initWithString: (OFString*)string +{ + char *cString, *cString2 = NULL; self = [super init]; @try { char *tmp, *tmp2; - if ((str_c2 = strdup([str cString])) == NULL) + if ((cString2 = strdup([string cString])) == NULL) @throw [OFOutOfMemoryException newWithClass: isa - requestedSize: [str cStringLength]]; + requestedSize: [string cStringLength]]; - str_c = str_c2; + cString = cString2; - if (!strncmp(str_c, "file://", 7)) { + if (!strncmp(cString, "file://", 7)) { scheme = @"file"; - path = [[OFString alloc] initWithCString: str_c + 7]; + path = [[OFString alloc] initWithCString: cString + 7]; return self; - } else if (!strncmp(str_c, "http://", 7)) { + } else if (!strncmp(cString, "http://", 7)) { scheme = @"http"; - str_c += 7; - } else if (!strncmp(str_c, "https://", 8)) { + cString += 7; + } else if (!strncmp(cString, "https://", 8)) { scheme = @"https"; - str_c += 8; + cString += 8; } else @throw [OFInvalidFormatException newWithClass: isa]; - if ((tmp = strchr(str_c, '/')) != NULL) { + if ((tmp = strchr(cString, '/')) != NULL) { *tmp = '\0'; tmp++; } - if ((tmp2 = strchr(str_c, '@')) != NULL) { + if ((tmp2 = strchr(cString, '@')) != NULL) { char *tmp3; *tmp2 = '\0'; tmp2++; - if ((tmp3 = strchr(str_c, ':')) != NULL) { + if ((tmp3 = strchr(cString, ':')) != NULL) { *tmp3 = '\0'; tmp3++; user = [[OFString alloc] - initWithCString: str_c]; + initWithCString: cString]; password = [[OFString alloc] initWithCString: tmp3]; } else user = [[OFString alloc] - initWithCString: str_c]; + initWithCString: cString]; - str_c = tmp2; + cString = tmp2; } - if ((tmp2 = strchr(str_c, ':')) != NULL) { + if ((tmp2 = strchr(cString, ':')) != NULL) { OFAutoreleasePool *pool; - OFString *port_str; + OFString *portString; *tmp2 = '\0'; tmp2++; - host = [[OFString alloc] initWithCString: str_c]; + host = [[OFString alloc] initWithCString: cString]; pool = [[OFAutoreleasePool alloc] init]; - port_str = [[OFString alloc] initWithCString: tmp2]; + portString = [[OFString alloc] initWithCString: tmp2]; - if ([port_str decimalValue] > 65535) + if ([portString decimalValue] > 65535) @throw [OFInvalidFormatException newWithClass: isa]; - port = [port_str decimalValue]; + port = [portString decimalValue]; [pool release]; } else { - host = [[OFString alloc] initWithCString: str_c]; + host = [[OFString alloc] initWithCString: cString]; if ([scheme isEqual: @"http"]) port = 80; else if ([scheme isEqual: @"https"]) port = 443; else assert(0); } - if ((str_c = tmp) != NULL) { - if ((tmp = strchr(str_c, '#')) != NULL) { + if ((cString = tmp) != NULL) { + if ((tmp = strchr(cString, '#')) != NULL) { *tmp = '\0'; fragment = [[OFString alloc] initWithCString: tmp + 1]; } - if ((tmp = strchr(str_c, '?')) != NULL) { + if ((tmp = strchr(cString, '?')) != NULL) { *tmp = '\0'; query = [[OFString alloc] initWithCString: tmp + 1]; } - if ((tmp = strchr(str_c, ';')) != NULL) { + if ((tmp = strchr(cString, ';')) != NULL) { *tmp = '\0'; parameters = [[OFString alloc] initWithCString: tmp + 1]; } - path = [[OFString alloc] initWithFormat: @"/%s", str_c]; + path = [[OFString alloc] initWithFormat: @"/%s", + cString]; } else path = @""; } @catch (id e) { [self release]; @throw e; } @finally { - free(str_c2); + free(cString2); } return self; } -- initWithString: (OFString*)str - relativeToURL: (OFURL*)url +- initWithString: (OFString*)string + relativeToURL: (OFURL*)URL { - char *str_c, *str_c2 = NULL; + char *cString, *cString2 = NULL; - if ([str containsString: @"://"]) - return [self initWithString: str]; + if ([string containsString: @"://"]) + return [self initWithString: string]; self = [super init]; @try { char *tmp; - scheme = [url->scheme copy]; - host = [url->host copy]; - port = url->port; - user = [url->user copy]; - password = [url->password copy]; + scheme = [URL->scheme copy]; + host = [URL->host copy]; + port = URL->port; + user = [URL->user copy]; + password = [URL->password copy]; - if ((str_c2 = strdup([str cString])) == NULL) + if ((cString2 = strdup([string cString])) == NULL) @throw [OFOutOfMemoryException newWithClass: isa - requestedSize: [str cStringLength]]; + requestedSize: [string cStringLength]]; - str_c = str_c2; + cString = cString2; - if ((tmp = strchr(str_c, '#')) != NULL) { + if ((tmp = strchr(cString, '#')) != NULL) { *tmp = '\0'; fragment = [[OFString alloc] initWithCString: tmp + 1]; } - if ((tmp = strchr(str_c, '?')) != NULL) { + if ((tmp = strchr(cString, '?')) != NULL) { *tmp = '\0'; query = [[OFString alloc] initWithCString: tmp + 1]; } - if ((tmp = strchr(str_c, ';')) != NULL) { + if ((tmp = strchr(cString, ';')) != NULL) { *tmp = '\0'; parameters = [[OFString alloc] initWithCString: tmp + 1]; } - if (*str_c == '/') - path = [[OFString alloc] initWithCString: str_c]; + if (*cString == '/') + path = [[OFString alloc] initWithCString: cString]; else { OFAutoreleasePool *pool; OFString *s; pool = [[OFAutoreleasePool alloc] init]; - if ([url->path hasSuffix: @"/"]) + if ([URL->path hasSuffix: @"/"]) s = [OFString stringWithFormat: @"%@%s", - url->path, - str_c]; + URL->path, + cString]; else s = [OFString stringWithFormat: @"%@/../%s", - url->path, - str_c]; + URL->path, + cString]; path = [resolve_relative_path(s) copy]; [pool release]; } } @catch (id e) { [self release]; @throw e; } @finally { - free(str_c2); + free(cString2); } return self; } @@ -301,44 +302,44 @@ [fragment release]; [super dealloc]; } -- (BOOL)isEqual: (id)obj -{ - OFURL *url; - - if (![obj isKindOfClass: [OFURL class]]) - return NO; - - url = obj; - - if (![url->scheme isEqual: scheme]) - return NO; - if (![url->host isEqual: host]) - return NO; - if (url->port != port) - return NO; - if (![url->user isEqual: user]) - return NO; - if (![url->password isEqual: password]) - return NO; - if (![url->path isEqual: path]) - return NO; - if (![url->parameters isEqual: parameters]) - return NO; - if (![url->query isEqual: query]) - return NO; - if (![url->fragment isEqual: fragment]) +- (BOOL)isEqual: (id)object +{ + OFURL *otherURL; + + if (![object isKindOfClass: [OFURL class]]) + return NO; + + otherURL = (OFURL*)object; + + if (![otherURL->scheme isEqual: scheme]) + return NO; + if (![otherURL->host isEqual: host]) + return NO; + if (otherURL->port != port) + return NO; + if (![otherURL->user isEqual: user]) + return NO; + if (![otherURL->password isEqual: password]) + return NO; + if (![otherURL->path isEqual: path]) + return NO; + if (![otherURL->parameters isEqual: parameters]) + return NO; + if (![otherURL->query isEqual: query]) + return NO; + if (![otherURL->fragment isEqual: fragment]) return NO; return YES; } - (uint32_t)hash { - uint32_t hash, h; + uint32_t hash, tmp; OF_HASH_INIT(hash); ADD_STR_HASH(scheme); ADD_STR_HASH(host); @@ -358,28 +359,28 @@ return hash; } - copy { - OFURL *new = [[OFURL alloc] init]; + OFURL *copy = [[OFURL alloc] init]; @try { - new->scheme = [scheme copy]; - new->host = [host copy]; - new->port = port; - new->user = [user copy]; - new->password = [password copy]; - new->path = [path copy]; - new->parameters = [parameters copy]; - new->query = [query copy]; - new->fragment = [fragment copy]; + copy->scheme = [scheme copy]; + copy->host = [host copy]; + copy->port = port; + copy->user = [user copy]; + copy->password = [password copy]; + copy->path = [path copy]; + copy->parameters = [parameters copy]; + copy->query = [query copy]; + copy->fragment = [fragment copy]; } @catch (id e) { - [new release]; + [copy release]; @throw e; } - return new; + return copy; } - (OFString*)scheme { OF_GETTER(scheme, YES) @@ -389,13 +390,11 @@ { if (![scheme_ isEqual: @"http"] && ![scheme_ isEqual: @"https"]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; - OFString *old = scheme; - scheme = [scheme_ copy]; - [old release]; + OF_SETTER(scheme, scheme_, YES, YES) } - (OFString*)host { OF_GETTER(host, YES) @@ -441,20 +440,16 @@ OF_GETTER(path, YES) } - (void)setPath: (OFString*)path_ { - OFString *old; - if (([scheme isEqual: @"http"] || [scheme isEqual: @"https"]) && ![path_ hasPrefix: @"/"]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; - old = path; - path = [path_ copy]; - [old release]; + OF_SETTER(path, path_, YES, YES) } - (OFString*)parameters { OF_GETTER(parameters, YES) @@ -485,48 +480,48 @@ OF_SETTER(fragment, fragment_, YES, YES) } - (OFString*)description { - OFMutableString *desc = [OFMutableString stringWithFormat: @"%@://", - scheme]; + OFMutableString *ret = [OFMutableString stringWithFormat: @"%@://", + scheme]; BOOL needPort = YES; if ([scheme isEqual: @"file"]) { - [desc appendString: path]; - return desc; + [ret appendString: path]; + return ret; } if (user != nil && password != nil) - [desc appendFormat: @"%@:%@@", user, password]; + [ret appendFormat: @"%@:%@@", user, password]; else if (user != nil) - [desc appendFormat: @"%@@", user]; + [ret appendFormat: @"%@@", user]; - [desc appendString: host]; + [ret appendString: host]; if (([scheme isEqual: @"http"] && port == 80) || ([scheme isEqual: @"https"] && port == 443)) needPort = NO; if (needPort) - [desc appendFormat: @":%d", port]; + [ret appendFormat: @":%d", port]; - [desc appendString: path]; + [ret appendString: path]; if (parameters != nil) - [desc appendFormat: @";%@", parameters]; + [ret appendFormat: @";%@", parameters]; if (query != nil) - [desc appendFormat: @"?%@", query]; + [ret appendFormat: @"?%@", query]; if (fragment != nil) - [desc appendFormat: @"#%@", fragment]; + [ret appendFormat: @"#%@", fragment]; /* * Class swizzle the string to be immutable. We declared the return type * to be OFString*, so it can't be modified anyway. But not swizzling it * would create a real copy each time -[copy] is called. */ - desc->isa = [OFString class]; - return desc; + ret->isa = [OFString class]; + return ret; } @end Index: src/OFXMLElement.h ================================================================== --- src/OFXMLElement.h +++ src/OFXMLElement.h @@ -33,11 +33,11 @@ OFString *defaultNamespace; OFMutableArray *attributes; OFMutableDictionary *namespaces; OFMutableArray *children; OFString *characters; - OFString *cdata; + OFString *CDATA; OFMutableString *comment; } #ifdef OF_HAVE_PROPERTIES @property (readonly, copy) OFString *name; @@ -53,16 +53,16 @@ */ + elementWithName: (OFString*)name; /** * \param name The name for the element - * \param stringval The value for the element + * \param stringValue The value for the element * \return A new autoreleased OFXMLElement with the specified element name and * value */ + elementWithName: (OFString*)name - stringValue: (OFString*)stringval; + stringValue: (OFString*)stringValue; /** * \param name The name for the element * \param ns The namespace for the element * \return A new autoreleased OFXMLElement with the specified element name and @@ -72,34 +72,34 @@ namespace: (OFString*)ns; /** * \param name The name for the element * \param ns The namespace for the element - * \param stringval The value for the element + * \param stringValue The value for the element * \return A new autoreleased OFXMLElement with the specified element name, * namespace and value */ + elementWithName: (OFString*)name namespace: (OFString*)ns - stringValue: (OFString*)stringval; + stringValue: (OFString*)stringValue; /** * Creates a new element, only consisting of the specified characters. * - * \param chars The characters the element represents + * \param characters The characters the element represents * \return A new autoreleased OFXMLElement consisting of the specified * characters */ -+ elementWithCharacters: (OFString*)chars; ++ elementWithCharacters: (OFString*)characters; /** * Creates a new element, only consisting of the specified CDATA. * - * \param cdata The CDATA the element represents + * \param CDATA The CDATA the element represents * \return A new autoreleased OFXMLElement consisting of the specified CDATA */ -+ elementWithCDATA: (OFString*)cdata; ++ elementWithCDATA: (OFString*)CDATA; /** * Creates a new element, only consisting of the specified comment. * * \param comment The comment the element represents @@ -108,14 +108,14 @@ + elementWithComment: (OFString*)comment; /** * Parses the string and returns an OFXMLElement for it. * - * \param str The string to parse + * \param string The string to parse * \return A new autoreleased OFXMLElement with the contents of the string */ -+ elementWithXMLString: (OFString*)str; ++ elementWithXMLString: (OFString*)string; /** * Initializes an already allocated OFXMLElement with the specified element * name. * @@ -127,16 +127,16 @@ /** * Initializes an already allocated OFXMLElement with the specified element * name and value. * * \param name The name for the element - * \param stringval The value for the element + * \param stringValue The value for the element * \return An initialized OFXMLElement with the specified element name and * value */ - initWithName: (OFString*)name - stringValue: (OFString*)stringval; + stringValue: (OFString*)stringValue; /** * Initializes an already allocated OFXMLElement with the specified element * name and namespace. * @@ -152,35 +152,35 @@ * Initializes an already allocated OFXMLElement with the specified element * name, namespace and value. * * \param name The name for the element * \param ns The namespace for the element - * \param stringval The value for the element + * \param stringValue The value for the element * \return An initialized OFXMLElement with the specified element name, * namespace and value */ - initWithName: (OFString*)name namespace: (OFString*)ns - stringValue: (OFString*)stringval; + stringValue: (OFString*)stringValue; /** * Initializes an already allocated OFXMLElement so that it only consists of the * specified characters. * - * \param chars The characters the element represents + * \param characters The characters the element represents * \return An initialized OFXMLElement consisting of the specified characters */ -- initWithCharacters: (OFString*)chars; +- initWithCharacters: (OFString*)characters; /** * Initializes an already allocated OFXMLElement so that it only consists of the * specified CDATA. * - * \param cdata The CDATA the element represents + * \param CDATA The CDATA the element represents * \return An initialized OFXMLElement consisting of the specified CDATA */ -- initWithCDATA: (OFString*)cdata; +- initWithCDATA: (OFString*)CDATA; /** * Initializes an already allocated OFXMLElement so that it only consists of the * specified comment. * @@ -190,14 +190,14 @@ - initWithComment: (OFString*)comment; /** * Parses the string and initializes an already allocated OFXMLElement with it. * - * \param str The string to parse + * \param string The string to parse * \return An initialized OFXMLElement with the contents of the string */ -- initWithXMLString: (OFString*)str; +- initWithXMLString: (OFString*)string; /** * \return The name of the element */ - (OFString*)name; @@ -225,13 +225,13 @@ - (OFArray*)children; /** * Removes all children and sets the string value to the specified string. * - * \param value The new string value for the element + * \param stringValue The new string value for the element */ -- (void)setStringValue: (OFString*)value; +- (void)setStringValue: (OFString*)stringValue; /** * \return A string with the string value of all children concatenated */ - (OFString*)stringValue; @@ -246,69 +246,69 @@ * Adds the specified attribute. * * If an attribute with the same name and namespace already exists, it is not * added. * - * \param attr The attribute to add + * \param attribute The attribute to add */ -- (void)addAttribute: (OFXMLAttribute*)attr; +- (void)addAttribute: (OFXMLAttribute*)attribute; /** * Adds the specified attribute with the specified value. * * If an attribute with the same name and namespace already exists, it is not * added. * * \param name The name of the attribute - * \param value The value of the attribute + * \param stringValue The value of the attribute */ - (void)addAttributeWithName: (OFString*)name - stringValue: (OFString*)value; + stringValue: (OFString*)stringValue; /** * Adds the specified attribute with the specified namespace and value. * * If an attribute with the same name and namespace already exists, it is not * added. * * \param name The name of the attribute * \param ns The namespace of the attribute - * \param value The value of the attribute + * \param stringValue The value of the attribute */ - (void)addAttributeWithName: (OFString*)name namespace: (OFString*)ns - stringValue: (OFString*)value; + stringValue: (OFString*)stringValue; /** - * \param attrname The name of the attribute + * \param attributeName The name of the attribute * \return The attribute with the specified name */ -- (OFXMLAttribute*)attributeForName: (OFString*)attrname; +- (OFXMLAttribute*)attributeForName: (OFString*)attributeName; /** - * \param attrname The name of the attribute - * \param attrns The namespace of the attribute + * \param attributeName The name of the attribute + * \param attributeNS The namespace of the attribute * \return The attribute with the specified name and namespace */ -- (OFXMLAttribute*)attributeForName: (OFString*)attrname - namespace: (OFString*)attrns; +- (OFXMLAttribute*)attributeForName: (OFString*)attributeName + namespace: (OFString*)attributeNS; /** * Removes the attribute with the specified name. * - * \param attrname The name of the attribute + * \param attribteName The name of the attribute */ -- (void)removeAttributeForName: (OFString*)attrname; +- (void)removeAttributeForName: (OFString*)attributeName; /** * Removes the attribute with the specified name and namespace. * - * \param attrname The name of the attribute - * \param attrns The namespace of the attribute + * \param attributeName The name of the attribute + * \param attributeNS The namespace of the attribute */ -- (void)removeAttributeForName: (OFString*)attrname - namespace: (OFString*)attrns; +- (void)removeAttributeForName: (OFString*)attributeName + namespace: (OFString*)attributeNS; /** * Sets a prefix for a namespace. * * \param prefix The prefix for the namespace @@ -339,32 +339,32 @@ * \param child Another OFXMLElement which is added as a child */ - (void)addChild: (OFXMLElement*)child; /** - * \param elemname The name of the element + * \param elementName The name of the element * \return The first child element with the specified name */ -- (OFXMLElement*)elementForName: (OFString*)elemname; +- (OFXMLElement*)elementForName: (OFString*)elementName; /** - * \param elemname The name of the elements + * \param elementName The name of the elements * \return The child elements with the specified name */ -- (OFArray*)elementsForName: (OFString*)elemname; +- (OFArray*)elementsForName: (OFString*)elementName; /** - * \param elemname The name of the element - * \param elemns The namespace of the element + * \param elementName The name of the element + * \param elementNS The namespace of the element * \return The first child element with the specified name and namespace */ -- (OFXMLElement*)elementForName: (OFString*)elemname - namespace: (OFString*)elemns; +- (OFXMLElement*)elementForName: (OFString*)elementName + namespace: (OFString*)elementNS; /** - * \param elemname The name of the elements - * \param elemns The namespace of the elements + * \param elementName The name of the elements + * \param elementNS The namespace of the elements * \return The child elements with the specified name and namespace */ -- (OFArray*)elementsForName: (OFString*)elemname - namespace: (OFString*)elemns; +- (OFArray*)elementsForName: (OFString*)elementName + namespace: (OFString*)elementNS; @end Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -40,13 +40,13 @@ } @end @implementation OFXMLElement_OFXMLElementBuilderDelegate - (void)elementBuilder: (OFXMLElementBuilder*)builder - didBuildElement: (OFXMLElement*)elem + didBuildElement: (OFXMLElement*)element_ { - element = [elem retain]; + element = [element_ retain]; } - (void)dealloc { [element release]; @@ -54,20 +54,20 @@ [super dealloc]; } @end @implementation OFXMLElement -+ elementWithName: (OFString*)name_ ++ elementWithName: (OFString*)name { - return [[[self alloc] initWithName: name_] autorelease]; + return [[[self alloc] initWithName: name] autorelease]; } + elementWithName: (OFString*)name - stringValue: (OFString*)stringval + stringValue: (OFString*)stringValue { return [[[self alloc] initWithName: name - stringValue: stringval] autorelease]; + stringValue: stringValue] autorelease]; } + elementWithName: (OFString*)name namespace: (OFString*)ns { @@ -75,35 +75,35 @@ namespace: ns] autorelease]; } + elementWithName: (OFString*)name namespace: (OFString*)ns - stringValue: (OFString*)stringval + stringValue: (OFString*)stringValue { return [[[self alloc] initWithName: name namespace: ns - stringValue: stringval] autorelease]; + stringValue: stringValue] autorelease]; } -+ elementWithCharacters: (OFString*)chars ++ elementWithCharacters: (OFString*)characters { - return [[[self alloc] initWithCharacters: chars] autorelease]; + return [[[self alloc] initWithCharacters: characters] autorelease]; } -+ elementWithCDATA: (OFString*)cdata ++ elementWithCDATA: (OFString*)CDATA { - return [[[self alloc] initWithCDATA: cdata] autorelease]; + return [[[self alloc] initWithCDATA: CDATA] autorelease]; } + elementWithComment: (OFString*)comment { return [[[self alloc] initWithComment: comment] autorelease]; } -+ elementWithXMLString: (OFString*)str ++ elementWithXMLString: (OFString*)string { - return [[[self alloc] initWithXMLString: str] autorelease]; + return [[[self alloc] initWithXMLString: string] autorelease]; } - init { Class c = isa; @@ -118,15 +118,15 @@ namespace: nil stringValue: nil]; } - initWithName: (OFString*)name_ - stringValue: (OFString*)stringval + stringValue: (OFString*)stringValue { return [self initWithName: name_ namespace: nil - stringValue: stringval]; + stringValue: stringValue]; } - initWithName: (OFString*)name_ namespace: (OFString*)ns_ { @@ -135,24 +135,24 @@ stringValue: nil]; } - initWithName: (OFString*)name_ namespace: (OFString*)ns_ - stringValue: (OFString*)stringval + stringValue: (OFString*)stringValue { self = [super init]; @try { name = [name_ copy]; ns = [ns_ copy]; - if (stringval != nil) { + if (stringValue != nil) { OFAutoreleasePool *pool; pool = [[OFAutoreleasePool alloc] init]; [self addChild: - [OFXMLElement elementWithCharacters: stringval]]; + [OFXMLElement elementWithCharacters: stringValue]]; [pool release]; } namespaces = [[OFMutableDictionary alloc] initWithKeysAndObjects: @@ -164,30 +164,30 @@ } return self; } -- initWithCharacters: (OFString*)chars +- initWithCharacters: (OFString*)characters_ { self = [super init]; @try { - characters = [chars copy]; + characters = [characters_ copy]; } @catch (id e) { [self release]; @throw e; } return self; } -- initWithCDATA: (OFString*)cdata_ +- initWithCDATA: (OFString*)CDATA_ { self = [super init]; @try { - cdata = [cdata_ copy]; + CDATA = [CDATA_ copy]; } @catch (id e) { [self release]; @throw e; } @@ -206,11 +206,11 @@ } return self; } -- initWithXMLString: (OFString*)str +- initWithXMLString: (OFString*)string { OFAutoreleasePool *pool; OFXMLParser *parser; OFXMLElementBuilder *builder; OFXMLElement_OFXMLElementBuilderDelegate *delegate; @@ -225,11 +225,11 @@ autorelease]; [parser setDelegate: builder]; [builder setDelegate: delegate]; - [parser parseString: str]; + [parser parseString: string]; if (![parser finishedParsing]) @throw [OFMalformedXMLException newWithClass: isa parser: parser]; @@ -277,41 +277,41 @@ - (OFArray*)children { return [[children copy] autorelease]; } -- (void)setStringValue: (OFString*)value +- (void)setStringValue: (OFString*)stringValue { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; [self setChildren: [OFArray arrayWithObject: - [OFXMLElement elementWithCharacters: value]]]; + [OFXMLElement elementWithCharacters: stringValue]]]; [pool release]; } - (OFString*)stringValue { OFAutoreleasePool *pool; OFMutableString *ret; - OFXMLElement **children_c; + OFXMLElement **cArray; size_t i, count = [children count]; if (count == 0) return @""; ret = [OFMutableString string]; - children_c = [children cArray]; + cArray = [children cArray]; pool = [[OFAutoreleasePool alloc] init]; for (i = 0; i < count; i++) { - if (children_c[i]->characters != nil) - [ret appendString: children_c[i]->characters]; - else if (children_c[i]->cdata != nil) - [ret appendString: children_c[i]->cdata]; - else if (children_c[i]->comment == nil) { - [ret appendString: [children_c[i] stringValue]]; + if (cArray[i]->characters != nil) + [ret appendString: cArray[i]->characters]; + else if (cArray[i]->CDATA != nil) + [ret appendString: cArray[i]->CDATA]; + else if (cArray[i]->comment == nil) { + [ret appendString: [cArray[i] stringValue]]; [pool releaseObjects]; } } [pool release]; @@ -326,224 +326,208 @@ } - (OFString*)_XMLStringWithParent: (OFXMLElement*)parent { OFAutoreleasePool *pool, *pool2; - char *str_c; - size_t len, i, j, attrs_count; - OFString *prefix, *parent_prefix; - OFXMLAttribute **attrs_carray; + char *cString; + size_t length, i, j, attributesCount; + OFString *prefix, *parentPrefix; + OFXMLAttribute **attributesCArray; OFString *ret, *tmp; - OFMutableDictionary *all_namespaces; - OFString *def_ns; + OFMutableDictionary *allNamespaces; + OFString *defaultNS; if (characters != nil) return [characters stringByXMLEscaping]; - if (cdata != nil) - return [OFString stringWithFormat: @"", cdata]; - - if (comment != nil) { - OFMutableString *str; - - str = [OFMutableString stringWithString: @""]; - - /* - * Class swizzle the string to be immutable. We declared the - * return type to be OFString*, so it can't be modified anyway. - * But not swizzling it would create a real copy each time - * -[copy] is called. - */ - str->isa = [OFString class]; - return str; - } + if (CDATA != nil) + return [OFString stringWithFormat: @"", CDATA]; + + if (comment != nil) + return [OFString stringWithFormat: @"", comment]; pool = [[OFAutoreleasePool alloc] init]; - def_ns = (defaultNamespace != nil + defaultNS = (defaultNamespace != nil ? defaultNamespace : (parent != nil ? parent->defaultNamespace : (OFString*)nil)); if (parent != nil && parent->namespaces != nil) { - OFEnumerator *key_enum = [namespaces keyEnumerator]; - OFEnumerator *obj_enum = [namespaces objectEnumerator]; - id key, obj; - - all_namespaces = [[parent->namespaces mutableCopy] autorelease]; - - while ((key = [key_enum nextObject]) != nil && - (obj = [obj_enum nextObject]) != nil) - [all_namespaces setObject: obj - forKey: key]; + OFEnumerator *keyEnumerator = [namespaces keyEnumerator]; + OFEnumerator *objectEnumerator = [namespaces objectEnumerator]; + id key, object; + + allNamespaces = [[parent->namespaces mutableCopy] autorelease]; + + while ((key = [keyEnumerator nextObject]) != nil && + (object = [objectEnumerator nextObject]) != nil) + [allNamespaces setObject: object + forKey: key]; } else - all_namespaces = namespaces; + allNamespaces = namespaces; - prefix = [all_namespaces objectForKey: + prefix = [allNamespaces objectForKey: (ns != nil ? ns : (OFString*)@"")]; - parent_prefix = [all_namespaces objectForKey: + parentPrefix = [allNamespaces objectForKey: (parent != nil && parent->ns != nil ? parent->ns : (OFString*)@"")]; i = 0; - len = [name cStringLength] + 3; - str_c = [self allocMemoryWithSize: len]; + length = [name cStringLength] + 3; + cString = [self allocMemoryWithSize: length]; /* Start of tag */ - str_c[i++] = '<'; + cString[i++] = '<'; - if (prefix != nil && ![ns isEqual: def_ns] && + if (prefix != nil && ![ns isEqual: defaultNS] && (![ns isEqual: (parent != nil ? parent->ns : (OFString*)nil)] || - parent_prefix != nil)) { - len += [prefix cStringLength] + 1; + parentPrefix != nil)) { + length += [prefix cStringLength] + 1; @try { - str_c = [self resizeMemory: str_c - toSize: len]; + cString = [self resizeMemory: cString + toSize: length]; } @catch (id e) { - [self freeMemory: str_c]; + [self freeMemory: cString]; @throw e; } - memcpy(str_c + i, [prefix cString], - [prefix cStringLength]); + memcpy(cString + i, [prefix cString], [prefix cStringLength]); i += [prefix cStringLength]; - str_c[i++] = ':'; + cString[i++] = ':'; } - memcpy(str_c + i, [name cString], [name cStringLength]); + memcpy(cString + i, [name cString], [name cStringLength]); i += [name cStringLength]; /* xmlns if necessary */ - if (ns != nil && prefix == nil && ![ns isEqual: def_ns] && + if (ns != nil && prefix == nil && ![ns isEqual: defaultNS] && (![ns isEqual: (parent != nil ? parent->ns : (OFString*)nil)] || - parent_prefix != nil)) { - len += [ns cStringLength] + 9; - + parentPrefix != nil)) { + length += [ns cStringLength] + 9; @try { - str_c = [self resizeMemory: str_c - toSize: len]; + cString = [self resizeMemory: cString + toSize: length]; } @catch (id e) { - [self freeMemory: str_c]; + [self freeMemory: cString]; @throw e; } - memcpy(str_c + i, " xmlns='", 8); + memcpy(cString + i, " xmlns='", 8); i += 8; - memcpy(str_c + i, [ns cString], [ns cStringLength]); + memcpy(cString + i, [ns cString], [ns cStringLength]); i += [ns cStringLength]; - str_c[i++] = '\''; + cString[i++] = '\''; - def_ns = ns; + defaultNS = ns; } /* Attributes */ - attrs_carray = [attributes cArray]; - attrs_count = [attributes count]; + attributesCArray = [attributes cArray]; + attributesCount = [attributes count]; pool2 = [[OFAutoreleasePool alloc] init]; - for (j = 0; j < attrs_count; j++) { - OFString *attr_name = [attrs_carray[j] name]; - OFString *attr_prefix = nil; - tmp = [[attrs_carray[j] stringValue] stringByXMLEscaping]; - - if ([attrs_carray[j] namespace] != nil && - (attr_prefix = [all_namespaces objectForKey: - [attrs_carray[j] namespace]]) == nil) + for (j = 0; j < attributesCount; j++) { + OFString *attributeName = [attributesCArray[j] name]; + OFString *attributePrefix = nil; + tmp = [[attributesCArray[j] stringValue] stringByXMLEscaping]; + + if ([attributesCArray[j] namespace] != nil && + (attributePrefix = [allNamespaces objectForKey: + [attributesCArray[j] namespace]]) == nil) @throw [OFUnboundNamespaceException newWithClass: isa - namespace: [attrs_carray[j] namespace]]; + namespace: [attributesCArray[j] namespace]]; - len += [attr_name cStringLength] + - (attr_prefix != nil ? [attr_prefix cStringLength] + 1 : 0) + + length += [attributeName cStringLength] + + (attributePrefix != nil ? + [attributePrefix cStringLength] + 1 : 0) + [tmp cStringLength] + 4; @try { - str_c = [self resizeMemory: str_c - toSize: len]; + cString = [self resizeMemory: cString + toSize: length]; } @catch (id e) { - [self freeMemory: str_c]; + [self freeMemory: cString]; @throw e; } - str_c[i++] = ' '; - if (attr_prefix != nil) { - memcpy(str_c + i, [attr_prefix cString], - [attr_prefix cStringLength]); - i += [attr_prefix cStringLength]; - str_c[i++] = ':'; - } - memcpy(str_c + i, [attr_name cString], - [attr_name cStringLength]); - i += [attr_name cStringLength]; - str_c[i++] = '='; - str_c[i++] = '\''; - memcpy(str_c + i, [tmp cString], [tmp cStringLength]); - i += [tmp cStringLength]; - str_c[i++] = '\''; + cString[i++] = ' '; + if (attributePrefix != nil) { + memcpy(cString + i, [attributePrefix cString], + [attributePrefix cStringLength]); + i += [attributePrefix cStringLength]; + cString[i++] = ':'; + } + memcpy(cString + i, [attributeName cString], + [attributeName cStringLength]); + i += [attributeName cStringLength]; + cString[i++] = '='; + cString[i++] = '\''; + memcpy(cString + i, [tmp cString], [tmp cStringLength]); + i += [tmp cStringLength]; + cString[i++] = '\''; [pool2 releaseObjects]; } /* Childen */ if (children != nil) { - OFXMLElement **children_carray = [children cArray]; - size_t children_count = [children count]; - IMP append; - - tmp = [OFMutableString string]; - 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]; - @throw e; - } - - str_c[i++] = '>'; - memcpy(str_c + i, [tmp cString], [tmp cStringLength]); - i += [tmp cStringLength]; - str_c[i++] = '<'; - str_c[i++] = '/'; - if (prefix != nil) { - len += [prefix cStringLength] + 1; - @try { - str_c = [self resizeMemory: str_c - toSize: len]; - } @catch (id e) { - [self freeMemory: str_c]; - @throw e; - } - - memcpy(str_c + i, [prefix cString], - [prefix cStringLength]); - i += [prefix cStringLength]; - str_c[i++] = ':'; - } - memcpy(str_c + i, [name cString], [name cStringLength]); - i += [name cStringLength]; - } else - str_c[i++] = '/'; - - str_c[i++] = '>'; - assert(i == len); + OFXMLElement **childrenCArray = [children cArray]; + size_t childrenCount = [children count]; + IMP append; + SEL appendSel = @selector(appendCStringWithoutUTF8Checking:); + + tmp = [OFMutableString string]; + append = [tmp methodForSelector: appendSel]; + + for (j = 0; j < childrenCount; j++) + append(tmp, appendSel, + [[childrenCArray[j] _XMLStringWithParent: self] + cString]); + + length += [tmp cStringLength] + [name cStringLength] + 2; + @try { + cString = [self resizeMemory: cString + toSize: length]; + } @catch (id e) { + [self freeMemory: cString]; + @throw e; + } + + cString[i++] = '>'; + memcpy(cString + i, [tmp cString], [tmp cStringLength]); + i += [tmp cStringLength]; + cString[i++] = '<'; + cString[i++] = '/'; + if (prefix != nil) { + length += [prefix cStringLength] + 1; + @try { + cString = [self resizeMemory: cString + toSize: length]; + } @catch (id e) { + [self freeMemory: cString]; + @throw e; + } + + memcpy(cString + i, [prefix cString], + [prefix cStringLength]); + i += [prefix cStringLength]; + cString[i++] = ':'; + } + memcpy(cString + i, [name cString], [name cStringLength]); + i += [name cStringLength]; + } else + cString[i++] = '/'; + + cString[i++] = '>'; + assert(i == length); [pool release]; @try { - ret = [OFString stringWithCString: str_c - length: len]; + ret = [OFString stringWithCString: cString + length: length]; } @finally { - [self freeMemory: str_c]; + [self freeMemory: cString]; } return ret; } - (OFString*)XMLString @@ -554,35 +538,35 @@ - (OFString*)description { return [self XMLString]; } -- (void)addAttribute: (OFXMLAttribute*)attr +- (void)addAttribute: (OFXMLAttribute*)attribute { if (name == nil) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; if (attributes == nil) attributes = [[OFMutableArray alloc] init]; - if ([self attributeForName: attr->name - namespace: attr->ns] == nil) - [attributes addObject: attr]; + if ([self attributeForName: attribute->name + namespace: attribute->ns] == nil) + [attributes addObject: attribute]; } - (void)addAttributeWithName: (OFString*)name_ - stringValue: (OFString*)value + stringValue: (OFString*)stringValue { [self addAttributeWithName: name_ namespace: nil - stringValue: value]; + stringValue: stringValue]; } - (void)addAttributeWithName: (OFString*)name_ namespace: (OFString*)ns_ - stringValue: (OFString*)value + stringValue: (OFString*)stringValue { OFAutoreleasePool *pool; if (name == nil) @throw [OFInvalidArgumentException newWithClass: isa @@ -589,70 +573,79 @@ selector: _cmd]; pool = [[OFAutoreleasePool alloc] init]; [self addAttribute: [OFXMLAttribute attributeWithName: name_ namespace: ns_ - stringValue: value]]; + stringValue: stringValue]]; [pool release]; } -- (OFXMLAttribute*)attributeForName: (OFString*)attrname -{ - return [self attributeForName: attrname - namespace: nil]; -} - -- (OFXMLAttribute*)attributeForName: (OFString*)attrname - namespace: (OFString*)attrns -{ - OFXMLAttribute **attrs_c = [attributes cArray]; - size_t i, attrs_count = [attributes count]; - - if (attrns != nil) { - for (i = 0; i < attrs_count; i++) - if ([attrs_c[i]->ns isEqual: attrns] && - [attrs_c[i]->name isEqual: attrname]) - return attrs_c[i]; - } else { - for (i = 0; i < attrs_count; i++) - if (attrs_c[i]->ns == nil && - [attrs_c[i]->name isEqual: attrname]) - return attrs_c[i]; - } +- (OFXMLAttribute*)attributeForName: (OFString*)attributeName +{ + OFXMLAttribute **cArray = [attributes cArray]; + size_t i, count = [attributes count]; + + for (i = 0; i < count; i++) + if (cArray[i]->ns == nil && + [cArray[i]->name isEqual: attributeName]) + return cArray[i]; + + return nil; +} + +- (OFXMLAttribute*)attributeForName: (OFString*)attributeName + namespace: (OFString*)attributeNS +{ + OFXMLAttribute **cArray; + size_t i, count; + + if (attributeNS == nil) + return [self attributeForName: attributeName]; + + cArray = [attributes cArray]; + count = [attributes count]; + + for (i = 0; i < count; i++) + if ([cArray[i]->ns isEqual: attributeNS] && + [cArray[i]->name isEqual: attributeName]) + return cArray[i]; return nil; } -- (void)removeAttributeForName: (OFString*)attrname -{ - [self removeAttributeForName: attrname - namespace: nil]; -} - -- (void)removeAttributeForName: (OFString*)attrname - namespace: (OFString*)attrns -{ - OFXMLAttribute **attrs_c = [attributes cArray]; - size_t i, attrs_count = [attributes count]; - - if (attrns != nil) { - for (i = 0; i < attrs_count; i++) { - if ([attrs_c[i]->ns isEqual: attrns] && - [attrs_c[i]->name isEqual: attrname]) { - [attributes removeObjectAtIndex: i]; - - return; - } - } - } else { - for (i = 0; i < attrs_count; i++) { - if (attrs_c[i]->ns == nil && - [attrs_c[i]->name isEqual: attrname]) { - [attributes removeObjectAtIndex: i]; - - return; - } +- (void)removeAttributeForName: (OFString*)attributeName +{ + OFXMLAttribute **cArray = [attributes cArray]; + size_t i, count = [attributes count]; + + for (i = 0; i < count; i++) { + if (cArray[i]->ns == nil && + [cArray[i]->name isEqual: attributeName]) { + [attributes removeObjectAtIndex: i]; + + return; + } + } +} + +- (void)removeAttributeForName: (OFString*)attributeName + namespace: (OFString*)attributeNS +{ + OFXMLAttribute **cArray; + size_t i, count; + + if (attributeNS == nil) + return [self removeAttributeForName: attributeName]; + + cArray = [attributes cArray]; + count = [attributes count]; + + for (i = 0; i < count; i++) { + if ([cArray[i]->ns isEqual: attributeNS] && + [cArray[i]->name isEqual: attributeName]) { + [attributes removeObjectAtIndex: i]; + return; } } } - (void)setPrefix: (OFString*)prefix @@ -708,47 +701,54 @@ children = [[OFMutableArray alloc] init]; [children addObject: child]; } -- (OFXMLElement*)elementForName: (OFString*)elemname -{ - return [self elementForName: elemname - namespace: nil]; -} - -- (OFArray*)elementsForName: (OFString*)elemname -{ - return [self elementsForName: elemname - namespace: nil]; -} - -- (OFXMLElement*)elementForName: (OFString*)elemname - namespace: (OFString*)elemns -{ - return [[self elementsForName: elemname - namespace: elemns] firstObject]; -} - -- (OFArray*)elementsForName: (OFString*)elemname - namespace: (OFString*)elemns -{ - OFMutableArray *ret = [OFMutableArray array]; - OFXMLElement **children_c = [children cArray]; - size_t i, children_count = [children count]; - - if (elemns != nil) { - for (i = 0; i < children_count; i++) - if ([children_c[i]->ns isEqual: elemns] && - [children_c[i]->name isEqual: elemname]) - [ret addObject: children_c[i]]; - } else { - for (i = 0; i < children_count; i++) - if (children_c[i]->ns == nil && - [children_c[i]->name isEqual: elemname]) - [ret addObject: children_c[i]]; - } +- (OFXMLElement*)elementForName: (OFString*)elementName +{ + return [[self elementsForName: elementName] firstObject]; +} + +- (OFXMLElement*)elementForName: (OFString*)elementName + namespace: (OFString*)elementNS +{ + return [[self elementsForName: elementName + namespace: elementNS] firstObject]; +} + +- (OFArray*)elementsForName: (OFString*)elementName +{ + OFMutableArray *ret = [OFMutableArray array]; + OFXMLElement **cArray = [children cArray]; + size_t i, count = [children count]; + + for (i = 0; i < count; i++) + if (cArray[i]->ns == nil && + [cArray[i]->name isEqual: elementName]) + [ret addObject: cArray[i]]; + + return ret; +} + +- (OFArray*)elementsForName: (OFString*)elementName + namespace: (OFString*)elementNS +{ + OFMutableArray *ret; + OFXMLElement **cArray; + size_t i, count; + + if (elementNS == nil) + return [self elementsForName: elementName]; + + ret = [OFMutableArray array]; + cArray = [children cArray]; + count = [children count]; + + for (i = 0; i < count; i++) + if ([cArray[i]->ns isEqual: elementNS] && + [cArray[i]->name isEqual: elementName]) + [ret addObject: cArray[i]]; return ret; } - (void)dealloc @@ -757,11 +757,11 @@ [ns release]; [attributes release]; [namespaces release]; [children release]; [characters release]; - [cdata release]; + [CDATA release]; [comment release]; [super dealloc]; } @end