Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

able to take in xml from xapi and put it into dictionary

  • Loading branch information...
commit f7e370e24682bc15661e112aced995965e581a26 1 parent f4e250c
@davidchiles authored
View
66 NSDataAdditions.h
@@ -0,0 +1,66 @@
+
+#import <Foundation/Foundation.h>
+
+@interface NSData (NSDataAdditions)
+
+// ================================================================================================
+// Created by Tom Bradley on 21/10/2009.
+// Version 1.4
+//
+// Copyright (c) 2009 Tom Bradley
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+// ================================================================================================
+
++ (NSData *) dataWithUncompressedContentsOfFile:(NSString *)aFile;
+
+
+
+// ================================================================================================
+// base64.h
+// ViewTransitions
+//
+// Created by Neo on 5/11/08.
+// Copyright 2008 Kaliware, LLC. All rights reserved.
+//
+// FOUND HERE http://idevkit.com/forums/tutorials-code-samples-sdk/8-nsdata-base64-extension.html
+// ================================================================================================
++ (NSData *) dataWithBase64EncodedString:(NSString *) string;
+- (id) initWithBase64EncodedString:(NSString *) string;
+
+- (NSString *) base64Encoding;
+- (NSString *) base64EncodingWithLineLength:(unsigned int) lineLength;
+
+
+
+// ================================================================================================
+// NSData+gzip.h
+// Drip
+//
+// Created by Nur Monson on 8/21/07.
+// Copyright 2007 theidiotproject. All rights reserved.
+//
+// FOUND HERE http://code.google.com/p/drop-osx/source/browse/trunk/Source/NSData%2Bgzip.h
+// ================================================================================================
+- (NSData *)gzipDeflate;
+- (NSData *)gzipInflate;
+
+
+
+@end
View
309 NSDataAdditions.m
@@ -0,0 +1,309 @@
+
+#import "NSDataAdditions.h"
+
+#import <zlib.h>
+
+
+@implementation NSData (NSDataAdditions)
+
+// ================================================================================================
+// Created by Tom Bradley on 21/10/2009.
+// Version 1.4
+//
+// Copyright (c) 2009 Tom Bradley
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+// ================================================================================================
+
++ (NSData *) dataWithUncompressedContentsOfFile:(NSString *)aFile {
+
+ NSData * result;
+
+ if ([[aFile pathExtension] isEqualToString:@"gz"]) {
+ NSData * compressedData = [NSData dataWithContentsOfFile:aFile];
+ result = [compressedData gzipInflate];
+ }
+ else
+ result = [NSData dataWithContentsOfFile:aFile];
+
+ return result;
+}
+
+
+
+
+
+// ================================================================================================
+// base64.m
+// ViewTransitions
+//
+// Created by Neo on 5/11/08.
+// Copyright 2008 Kaliware, LLC. All rights reserved.
+//
+// Created by khammond on Mon Oct 29 2001.
+// Formatted by Timothy Hatcher on Sun Jul 4 2004.
+// Copyright (c) 2001 Kyle Hammond. All rights reserved.
+// Original development by Dave Winer.
+//
+// FOUND HERE http://idevkit.com/forums/tutorials-code-samples-sdk/8-nsdata-base64-extension.html
+// ================================================================================================
+
+static char encodingTable[64] = {
+ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
+ 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
+ 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
+ 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/' };
+
+
++ (NSData *) dataWithBase64EncodedString:(NSString *) string {
+ NSData *result = [[NSData alloc] initWithBase64EncodedString:string];
+ return result;
+}
+
+- (id) initWithBase64EncodedString:(NSString *) string {
+ NSMutableData *mutableData = nil;
+
+ if( string ) {
+ unsigned long ixtext = 0;
+ unsigned long lentext = 0;
+ unsigned char ch = 0;
+ unsigned char inbuf[4], outbuf[3];
+ short i = 0, ixinbuf = 0;
+ BOOL flignore = NO;
+ BOOL flendtext = NO;
+ NSData *base64Data = nil;
+ const unsigned char *base64Bytes = nil;
+
+ // Convert the string to ASCII data.
+ base64Data = [string dataUsingEncoding:NSASCIIStringEncoding];
+ base64Bytes = [base64Data bytes];
+ mutableData = [NSMutableData dataWithCapacity:[base64Data length]];
+ lentext = [base64Data length];
+
+ while( YES ) {
+ if( ixtext >= lentext ) break;
+ ch = base64Bytes[ixtext++];
+ flignore = NO;
+
+ if( ( ch >= 'A' ) && ( ch <= 'Z' ) ) ch = ch - 'A';
+ else if( ( ch >= 'a' ) && ( ch <= 'z' ) ) ch = ch - 'a' + 26;
+ else if( ( ch >= '0' ) && ( ch <= '9' ) ) ch = ch - '0' + 52;
+ else if( ch == '+' ) ch = 62;
+ else if( ch == '=' ) flendtext = YES;
+ else if( ch == '/' ) ch = 63;
+ else flignore = YES;
+
+ if( ! flignore ) {
+ short ctcharsinbuf = 3;
+ BOOL flbreak = NO;
+
+ if( flendtext ) {
+ if( ! ixinbuf ) break;
+ if( ( ixinbuf == 1 ) || ( ixinbuf == 2 ) ) ctcharsinbuf = 1;
+ else ctcharsinbuf = 2;
+ ixinbuf = 3;
+ flbreak = YES;
+ }
+
+ inbuf [ixinbuf++] = ch;
+
+ if( ixinbuf == 4 ) {
+ ixinbuf = 0;
+ outbuf [0] = ( inbuf[0] << 2 ) | ( ( inbuf[1] & 0x30) >> 4 );
+ outbuf [1] = ( ( inbuf[1] & 0x0F ) << 4 ) | ( ( inbuf[2] & 0x3C ) >> 2 );
+ outbuf [2] = ( ( inbuf[2] & 0x03 ) << 6 ) | ( inbuf[3] & 0x3F );
+
+ for( i = 0; i < ctcharsinbuf; i++ )
+ [mutableData appendBytes:&outbuf[i] length:1];
+ }
+
+ if( flbreak ) break;
+ }
+ }
+ }
+
+ self = [self initWithData:mutableData];
+ return self;
+}
+
+#pragma mark -
+
+- (NSString *) base64Encoding {
+ return [self base64EncodingWithLineLength:0];
+}
+
+- (NSString *) base64EncodingWithLineLength:(unsigned int) lineLength {
+ const unsigned char *bytes = [self bytes];
+ NSMutableString *result = [NSMutableString stringWithCapacity:[self length]];
+ unsigned long ixtext = 0;
+ unsigned long lentext = [self length];
+ long ctremaining = 0;
+ unsigned char inbuf[3], outbuf[4];
+ short i = 0;
+ short charsonline = 0, ctcopy = 0;
+ unsigned long ix = 0;
+
+ while( YES ) {
+ ctremaining = lentext - ixtext;
+ if( ctremaining <= 0 ) break;
+
+ for( i = 0; i < 3; i++ ) {
+ ix = ixtext + i;
+ if( ix < lentext ) inbuf[i] = bytes[ix];
+ else inbuf [i] = 0;
+ }
+
+ outbuf [0] = (inbuf [0] & 0xFC) >> 2;
+ outbuf [1] = ((inbuf [0] & 0x03) << 4) | ((inbuf [1] & 0xF0) >> 4);
+ outbuf [2] = ((inbuf [1] & 0x0F) << 2) | ((inbuf [2] & 0xC0) >> 6);
+ outbuf [3] = inbuf [2] & 0x3F;
+ ctcopy = 4;
+
+ switch( ctremaining ) {
+ case 1:
+ ctcopy = 2;
+ break;
+ case 2:
+ ctcopy = 3;
+ break;
+ }
+
+ for( i = 0; i < ctcopy; i++ )
+ [result appendFormat:@"%c", encodingTable[outbuf[i]]];
+
+ for( i = ctcopy; i < 4; i++ )
+ [result appendFormat:@"%c",'='];
+
+ ixtext += 3;
+ charsonline += 4;
+
+ if( lineLength > 0 ) {
+ if (charsonline >= lineLength) {
+ charsonline = 0;
+ [result appendString:@"\n"];
+ }
+ }
+ }
+
+ return result;
+}
+
+
+
+// ================================================================================================
+// NSData+gzip.m
+// Drip
+//
+// Created by Nur Monson on 8/21/07.
+// Copyright 2007 theidiotproject. All rights reserved.
+//
+// FOUND HERE http://code.google.com/p/drop-osx/source/browse/trunk/Source/NSData%2Bgzip.m
+//
+// Also Check http://deusty.blogspot.com/2007/07/gzip-compressiondecompression.html
+// ================================================================================================
+
+#pragma mark -
+#pragma mark GZIP
+
+- (NSData *)gzipDeflate
+{
+ if ([self length] == 0) return self;
+
+ z_stream strm;
+
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+ strm.opaque = Z_NULL;
+ strm.total_out = 0;
+ strm.next_in=(Bytef *)[self bytes];
+ strm.avail_in = [self length];
+
+ // Compresssion Levels:
+ // Z_NO_COMPRESSION
+ // Z_BEST_SPEED
+ // Z_BEST_COMPRESSION
+ // Z_DEFAULT_COMPRESSION
+
+ if (deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, (15+16), 8, Z_DEFAULT_STRATEGY) != Z_OK) return nil;
+
+ NSMutableData *compressed = [NSMutableData dataWithLength:16384]; // 16K chunks for expansion
+
+ do {
+
+ if (strm.total_out >= [compressed length])
+ [compressed increaseLengthBy: 16384];
+
+ strm.next_out = [compressed mutableBytes] + strm.total_out;
+ strm.avail_out = [compressed length] - strm.total_out;
+
+ deflate(&strm, Z_FINISH);
+
+ } while (strm.avail_out == 0);
+
+ deflateEnd(&strm);
+
+ [compressed setLength: strm.total_out];
+ return [NSData dataWithData:compressed];
+}
+
+- (NSData *)gzipInflate
+{
+ if ([self length] == 0) return self;
+
+ unsigned full_length = [self length];
+ unsigned half_length = [self length] / 2;
+
+ NSMutableData *decompressed = [NSMutableData dataWithLength: full_length + half_length];
+ BOOL done = NO;
+ int status;
+
+ z_stream strm;
+ strm.next_in = (Bytef *)[self bytes];
+ strm.avail_in = [self length];
+ strm.total_out = 0;
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+
+ if (inflateInit2(&strm, (15+32)) != Z_OK) return nil;
+ while (!done)
+ {
+ // Make sure we have enough room and reset the lengths.
+ if (strm.total_out >= [decompressed length])
+ [decompressed increaseLengthBy: half_length];
+ strm.next_out = [decompressed mutableBytes] + strm.total_out;
+ strm.avail_out = [decompressed length] - strm.total_out;
+
+ // Inflate another chunk.
+ status = inflate (&strm, Z_SYNC_FLUSH);
+ if (status == Z_STREAM_END) done = YES;
+ else if (status != Z_OK) break;
+ }
+ if (inflateEnd (&strm) != Z_OK) return nil;
+
+ // Set real length.
+ if (done)
+ {
+ [decompressed setLength: strm.total_out];
+ return [NSData dataWithData: decompressed];
+ }
+ else return nil;
+}
+
+@end
+
View
38 OSM POI Editor.xcodeproj/project.pbxproj
@@ -7,16 +7,16 @@
objects = {
/* Begin PBXBuildFile section */
- 631539E114DC98D0000236F0 /* OPEOSMData.m in Sources */ = {isa = PBXBuildFile; fileRef = 631539E014DC98D0000236F0 /* OPEOSMData.m */; };
- 631539E514DCA29B000236F0 /* OPENode.m in Sources */ = {isa = PBXBuildFile; fileRef = 631539E414DCA29B000236F0 /* OPENode.m */; };
- 631539E814DCB6D6000236F0 /* OPEParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 631539E714DCB6D6000236F0 /* OPEParser.m */; };
+ 631539E114DC98D0000236F0 /* OPEOSMData.m in Sources */ = {isa = PBXBuildFile; fileRef = 631539E014DC98D0000236F0 /* OPEOSMData.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
+ 631539E514DCA29B000236F0 /* OPENode.m in Sources */ = {isa = PBXBuildFile; fileRef = 631539E414DCA29B000236F0 /* OPENode.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
+ 631539E814DCB6D6000236F0 /* OPEParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 631539E714DCB6D6000236F0 /* OPEParser.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
6330AB6F14DB519A00448852 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6330AB6E14DB519A00448852 /* UIKit.framework */; };
6330AB7114DB519A00448852 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6330AB7014DB519A00448852 /* Foundation.framework */; };
6330AB7314DB519A00448852 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6330AB7214DB519A00448852 /* CoreGraphics.framework */; };
6330AB7914DB519A00448852 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6330AB7714DB519A00448852 /* InfoPlist.strings */; };
- 6330AB7B14DB519A00448852 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 6330AB7A14DB519A00448852 /* main.m */; };
- 6330AB7F14DB519A00448852 /* OPEAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6330AB7E14DB519A00448852 /* OPEAppDelegate.m */; };
- 6330AB8214DB519A00448852 /* OPEViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6330AB8114DB519A00448852 /* OPEViewController.m */; };
+ 6330AB7B14DB519A00448852 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 6330AB7A14DB519A00448852 /* main.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
+ 6330AB7F14DB519A00448852 /* OPEAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6330AB7E14DB519A00448852 /* OPEAppDelegate.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
+ 6330AB8214DB519A00448852 /* OPEViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6330AB8114DB519A00448852 /* OPEViewController.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
6330AB8514DB519A00448852 /* OPEViewController_iPhone.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6330AB8314DB519A00448852 /* OPEViewController_iPhone.xib */; };
6330AB8814DB519A00448852 /* OPEViewController_iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6330AB8614DB519A00448852 /* OPEViewController_iPad.xib */; };
6330ABFD14DB51A800448852 /* libCloudMadeApi.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6330ABF814DB51A800448852 /* libCloudMadeApi.a */; };
@@ -26,6 +26,9 @@
6330AC0314DB547D00448852 /* libstdc++.6.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 6330AC0214DB547D00448852 /* libstdc++.6.dylib */; };
6330AC0514DB54A200448852 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6330AC0414DB54A200448852 /* QuartzCore.framework */; };
6330AC0714DB5E4D00448852 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6330AC0614DB5E4D00448852 /* CoreLocation.framework */; };
+ 63E4BF1A14E068EC00E0BD46 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 63E4BF1914E068EC00E0BD46 /* libz.dylib */; };
+ 63E4BF3114E0728200E0BD46 /* NSDataAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 63E4BF2E14E0728200E0BD46 /* NSDataAdditions.m */; };
+ 63E4BF3214E0728200E0BD46 /* TBXML.m in Sources */ = {isa = PBXBuildFile; fileRef = 63E4BF3014E0728200E0BD46 /* TBXML.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -155,6 +158,11 @@
6330AC0214DB547D00448852 /* libstdc++.6.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libstdc++.6.dylib"; path = "usr/lib/libstdc++.6.dylib"; sourceTree = SDKROOT; };
6330AC0414DB54A200448852 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
6330AC0614DB5E4D00448852 /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
+ 63E4BF1914E068EC00E0BD46 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
+ 63E4BF2D14E0728200E0BD46 /* NSDataAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSDataAdditions.h; sourceTree = "<group>"; };
+ 63E4BF2E14E0728200E0BD46 /* NSDataAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSDataAdditions.m; sourceTree = "<group>"; };
+ 63E4BF2F14E0728200E0BD46 /* TBXML.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TBXML.h; sourceTree = "<group>"; };
+ 63E4BF3014E0728200E0BD46 /* TBXML.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TBXML.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -162,6 +170,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ 63E4BF1A14E068EC00E0BD46 /* libz.dylib in Frameworks */,
6330AC0714DB5E4D00448852 /* CoreLocation.framework in Frameworks */,
6330AC0514DB54A200448852 /* QuartzCore.framework in Frameworks */,
6330AC0314DB547D00448852 /* libstdc++.6.dylib in Frameworks */,
@@ -181,6 +190,7 @@
6330AB5F14DB519A00448852 = {
isa = PBXGroup;
children = (
+ 63E4BF0B14E0677A00E0BD46 /* TBXML */,
6330AC0614DB5E4D00448852 /* CoreLocation.framework */,
6330AB7414DB519A00448852 /* OSM POI Editor */,
6330AB6D14DB519A00448852 /* Frameworks */,
@@ -200,6 +210,7 @@
6330AB6D14DB519A00448852 /* Frameworks */ = {
isa = PBXGroup;
children = (
+ 63E4BF1914E068EC00E0BD46 /* libz.dylib */,
6330AC0214DB547D00448852 /* libstdc++.6.dylib */,
6330AC0014DB544C00448852 /* libsqlite3.0.dylib */,
6330AC0414DB54A200448852 /* QuartzCore.framework */,
@@ -414,6 +425,17 @@
path = "route-me";
sourceTree = "<group>";
};
+ 63E4BF0B14E0677A00E0BD46 /* TBXML */ = {
+ isa = PBXGroup;
+ children = (
+ 63E4BF2D14E0728200E0BD46 /* NSDataAdditions.h */,
+ 63E4BF2E14E0728200E0BD46 /* NSDataAdditions.m */,
+ 63E4BF2F14E0728200E0BD46 /* TBXML.h */,
+ 63E4BF3014E0728200E0BD46 /* TBXML.m */,
+ );
+ name = TBXML;
+ sourceTree = "<group>";
+ };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -483,6 +505,8 @@
631539E114DC98D0000236F0 /* OPEOSMData.m in Sources */,
631539E514DCA29B000236F0 /* OPENode.m in Sources */,
631539E814DCB6D6000236F0 /* OPEParser.m in Sources */,
+ 63E4BF3114E0728200E0BD46 /* NSDataAdditions.m in Sources */,
+ 63E4BF3214E0728200E0BD46 /* TBXML.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -566,6 +590,7 @@
6330AB8C14DB519A00448852 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_ARC = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "OSM POI Editor/OSM POI Editor-Prefix.pch";
INFOPLIST_FILE = "OSM POI Editor/OSM POI Editor-Info.plist";
@@ -583,6 +608,7 @@
6330AB8D14DB519A00448852 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_ARC = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "OSM POI Editor/OSM POI Editor-Prefix.pch";
INFOPLIST_FILE = "OSM POI Editor/OSM POI Editor-Info.plist";
View
BIN  OSM POI Editor.xcodeproj/project.xcworkspace/xcuserdata/David.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown
View
10 OSM POI Editor.xcodeproj/project.xcworkspace/xcuserdata/David.xcuserdatad/WorkspaceSettings.xcsettings
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>IDEWorkspaceUserSettings_HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges</key>
+ <true/>
+ <key>IDEWorkspaceUserSettings_SnapshotAutomaticallyBeforeSignificantChanges</key>
+ <false/>
+</dict>
+</plist>
View
20 OSM POI Editor.xcodeproj/xcuserdata/David.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
@@ -9,13 +9,27 @@
continueAfterRunningActions = "No"
isPathRelative = "1"
filePath = "OSM POI Editor/OPEViewController.m"
- timestampString = "350009834.725844"
+ timestampString = "350252495.824769"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "24"
- endingLineNumber = "24"
+ startingLineNumber = "25"
+ endingLineNumber = "25"
landmarkName = "-viewDidLoad"
landmarkType = "5">
</FileBreakpoint>
+ <FileBreakpoint
+ shouldBeEnabled = "No"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ isPathRelative = "1"
+ filePath = "OSM POI Editor/OPENode.m"
+ timestampString = "350257178.18056"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "15"
+ endingLineNumber = "15"
+ landmarkName = "-initWithId:coordinates:keyValues:"
+ landmarkType = "5">
+ </FileBreakpoint>
</FileBreakpoints>
</Bucket>
View
2  OSM POI Editor/OPEAppDelegate.m
@@ -7,9 +7,9 @@
//
#import "OPEAppDelegate.h"
-
#import "OPEViewController.h"
+
@implementation OPEAppDelegate
@synthesize window = _window;
View
5 OSM POI Editor/OPENode.h
@@ -12,10 +12,11 @@
@interface OPENode : NSObject
@property int ident;
-@property CLLocationCoordinate2D* coordinates;
+@property (retain) CLLocation* coordinates;
@property (retain) NSMutableDictionary* tags;
--(id) initWithId: (int) i coordinates: (CLLocationCoordinate2D *) coordinate keyValues: (NSMutableDictionary *) tag;
+-(id) initWithId: (int) i coordinates: (CLLocation *) coordinate keyValues: (NSMutableDictionary *) tag;
+-(id) initWithId:(int)i latitude:(double) la longitude:(double) lo;
-(void)addKey: (NSString*) key Value: (NSString*) val;
-(BOOL)onlyTagCreatedBy;
View
16 OSM POI Editor/OPENode.m
@@ -12,19 +12,31 @@ @implementation OPENode
@synthesize ident, coordinates, tags;
--(id) initWithId: (int) i coordinates: (CLLocationCoordinate2D *) coordinate keyValues: (NSMutableDictionary *) tag
+-(id) initWithId: (int) i coordinates: (CLLocation *) coordinate keyValues: (NSMutableDictionary *) tag
{
self = [super init];
if(self)
{
ident = i;
coordinates = coordinate;
- tags = tag;
+ tags = [[NSMutableDictionary alloc] initWithDictionary:tag];
}
return self;
}
+-(id) initWithId:(int)i latitude:(double) la longitude:(double) lo
+{
+ self = [super init];
+ if (self)
+ {
+ ident = i;
+ coordinates = [[CLLocation alloc] initWithLatitude:la longitude:lo];
+ tags = [[NSMutableDictionary alloc] init];
+ }
+ return self;
+}
+
-(void)addKey: (NSString*) key Value: (NSString*) val
{
[tags setValue:val forKey:key];
View
1  OSM POI Editor/OPEOSMData.h
@@ -7,6 +7,7 @@
//
#import <Foundation/Foundation.h>
+#import <CoreLocation/CoreLocation.h>
@interface OPEOSMData : NSObject
View
56 OSM POI Editor/OPEOSMData.m
@@ -7,6 +7,8 @@
//
#import "OPEOSMData.h"
+#import "TBXML.h"
+#import "OPENode.h"
@implementation OPEOSMData
@@ -24,13 +26,63 @@ -(id) initWithLeft:(double) lef bottom: (double) bot right: (double) rig top: (d
bboxright = rig;
bboxtop = to;
}
+ allNodes = [[NSMutableDictionary alloc] init];
return self;
}
-(void) getData
{
- NSURL* url = [NSURL URLWithString: [NSString stringWithFormat:@"http://www.overpass-api.de/api/xapi?node[bbox=%d,%d,%d,%d]",bboxleft,bboxbottom,bboxright,bboxtop]];
- NSLog(@"url: %@",[url relativeString]);
+ NSLog(@"box: %f,%f,%f,%f",bboxleft,bboxbottom,bboxright,bboxtop);
+ NSURL* url = [NSURL URLWithString: [NSString stringWithFormat:@"http://www.overpass-api.de/api/xapi?node[amenity=*][bbox=%f,%f,%f,%f]",bboxleft,bboxbottom,bboxright,bboxtop]];
+ NSLog(@"url: %@",[url absoluteString]);
+ TBXML* tbxml = [TBXML tbxmlWithURL:url];
+
+ TBXMLElement * root = tbxml.rootXMLElement;
+ if(root)
+ {
+ NSLog(@"root: %@",[TBXML elementName:root]);
+ NSLog(@"version: %@",[TBXML valueOfAttributeNamed:@"version" forElement:root]);
+ TBXMLElement* node = [TBXML childElementNamed:@"node" parentElement:root];
+ while (node!=nil) {
+
+ //NSLog(@"node: %@",[TBXML textForElement:node]);
+ NSString* identS = [TBXML valueOfAttributeNamed:@"id" forElement:node];
+ //NSLog(@"id %@",identS);
+ NSString* latS = [TBXML valueOfAttributeNamed:@"lat" forElement:node];
+ NSString* lonS = [TBXML valueOfAttributeNamed:@"lon" forElement:node];
+
+ double ident = [identS doubleValue];
+ double lat = [latS doubleValue];
+ double lon = [lonS doubleValue];
+
+ OPENode * newNode = [[OPENode alloc] initWithId:ident latitude:lat longitude:lon];
+ //NSLog(@"lat: %f, lon: %f",lat,lon);
+ TBXMLElement* tag = [TBXML childElementNamed:@"tag" parentElement:node];
+
+ while (tag!=nil) //Takes in tags and adds them to newNode
+ {
+ NSString* key = [TBXML valueOfAttributeNamed:@"k" forElement:tag];
+ NSString* value = [TBXML valueOfAttributeNamed:@"v" forElement:tag];
+ //NSLog(@"key: %@, value: %@",key,value);
+ [newNode.tags setObject:value forKey:key];
+ tag = [TBXML nextSiblingNamed:@"tag" searchFromElement:tag];
+ }
+
+ [self.allNodes setObject:newNode forKey:[NSNumber numberWithInt:newNode.ident]];
+
+ for (id key in newNode.tags) { //Used to Log all keys and values stored
+
+ //NSLog(@"dkey: %@, dvalue: %@", key, [newNode.tags objectForKey:key]);
+ }
+ node = [TBXML nextSiblingNamed:@"node" searchFromElement:node];
+ }
+ NSLog(@"allNodes size: %d",[allNodes count]);
+ for (id key in self.allNodes) {
+
+ //NSLog(@"akey: %@, avalue: %@", key, [self.allNodes objectForKey:key]);
+ }
+
+ }
View
10 OSM POI Editor/OPEViewController.m
@@ -10,6 +10,7 @@
#import "RMCloudMadeMapSource.h"
#import "RMCloudMadeHiResMapSource.h"
#import "OPEParser.h"
+#import "OPEOSMData.h"
@implementation OPEViewController
@@ -48,7 +49,14 @@ - (void)viewDidLoad
[mapView moveToLatLong: initLocation];
[mapView.contents setZoom: 16];
- OPEParser *parser = [[OPEParser alloc] init];
+ //OPEParser *parser = [[OPEParser alloc] init];
+ double bboxleft = -122.26341;
+ double bboxbottom = 37.86981;
+ double bboxright = -122.25421;
+ double bboxtop = 37.87533;
+ OPEOSMData* data = [[OPEOSMData alloc] initWithLeft:bboxleft bottom:bboxbottom right:bboxright top:bboxtop];
+ [data getData];
+
}
- (void)viewDidUnload
View
130 TBXML.h
@@ -0,0 +1,130 @@
+// ================================================================================================
+// TBXML.h
+// Fast processing of XML files
+//
+// ================================================================================================
+// Created by Tom Bradley on 21/10/2009.
+// Version 1.4
+//
+// Copyright (c) 2009 Tom Bradley
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+// ================================================================================================
+
+
+// ================================================================================================
+// Defines
+// ================================================================================================
+#define MAX_ELEMENTS 100
+#define MAX_ATTRIBUTES 100
+
+#define TBXML_ATTRIBUTE_NAME_START 0
+#define TBXML_ATTRIBUTE_NAME_END 1
+#define TBXML_ATTRIBUTE_VALUE_START 2
+#define TBXML_ATTRIBUTE_VALUE_END 3
+#define TBXML_ATTRIBUTE_CDATA_END 4
+
+// ================================================================================================
+// Structures
+// ================================================================================================
+typedef struct _TBXMLAttribute {
+ char * name;
+ char * value;
+ struct _TBXMLAttribute * next;
+} TBXMLAttribute;
+
+typedef struct _TBXMLElement {
+ char * name;
+ char * text;
+
+ TBXMLAttribute * firstAttribute;
+
+ struct _TBXMLElement * parentElement;
+
+ struct _TBXMLElement * firstChild;
+ struct _TBXMLElement * currentChild;
+
+ struct _TBXMLElement * nextSibling;
+ struct _TBXMLElement * previousSibling;
+
+} TBXMLElement;
+
+typedef struct _TBXMLElementBuffer {
+ TBXMLElement * elements;
+ struct _TBXMLElementBuffer * next;
+ struct _TBXMLElementBuffer * previous;
+} TBXMLElementBuffer;
+
+typedef struct _TBXMLAttributeBuffer {
+ TBXMLAttribute * attributes;
+ struct _TBXMLAttributeBuffer * next;
+ struct _TBXMLAttributeBuffer * previous;
+} TBXMLAttributeBuffer;
+
+// ================================================================================================
+// TBXML Public Interface
+// ================================================================================================
+@interface TBXML : NSObject {
+
+@private
+ TBXMLElement * rootXMLElement;
+
+ TBXMLElementBuffer * currentElementBuffer;
+ TBXMLAttributeBuffer * currentAttributeBuffer;
+
+ long currentElement;
+ long currentAttribute;
+
+ char * bytes;
+ long bytesLength;
+}
+
+@property (nonatomic, readonly) TBXMLElement * rootXMLElement;
+
++ (id)tbxmlWithURL:(NSURL*)aURL;
++ (id)tbxmlWithXMLString:(NSString*)aXMLString;
++ (id)tbxmlWithXMLData:(NSData*)aData;
++ (id)tbxmlWithXMLFile:(NSString*)aXMLFile;
++ (id)tbxmlWithXMLFile:(NSString*)aXMLFile fileExtension:(NSString*)aFileExtension;
+
+- (id)initWithURL:(NSURL*)aURL;
+- (id)initWithXMLString:(NSString*)aXMLString;
+- (id)initWithXMLData:(NSData*)aData;
+- (id)initWithXMLFile:(NSString*)aXMLFile;
+- (id)initWithXMLFile:(NSString*)aXMLFile fileExtension:(NSString*)aFileExtension;
+
+@end
+
+// ================================================================================================
+// TBXML Static Functions Interface
+// ================================================================================================
+
+@interface TBXML (StaticFunctions)
+
++ (NSString*) elementName:(TBXMLElement*)aXMLElement;
++ (NSString*) textForElement:(TBXMLElement*)aXMLElement;
++ (NSString*) valueOfAttributeNamed:(NSString *)aName forElement:(TBXMLElement*)aXMLElement;
+
++ (NSString*) attributeName:(TBXMLAttribute*)aXMLAttribute;
++ (NSString*) attributeValue:(TBXMLAttribute*)aXMLAttribute;
+
++ (TBXMLElement*) nextSiblingNamed:(NSString*)aName searchFromElement:(TBXMLElement*)aXMLElement;
++ (TBXMLElement*) childElementNamed:(NSString*)aName parentElement:(TBXMLElement*)aParentXMLElement;
+
+@end
View
594 TBXML.m
@@ -0,0 +1,594 @@
+// ================================================================================================
+// TBXML.m
+// Fast processing of XML files
+//
+// ================================================================================================
+// Created by Tom Bradley on 21/10/2009.
+// Version 1.4
+//
+// Copyright (c) 2009 Tom Bradley
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+// ================================================================================================
+#import "TBXML.h"
+#import "NSDataAdditions.h"
+
+// ================================================================================================
+// Private methods
+// ================================================================================================
+@interface TBXML (Private)
+- (void) decodeData:(NSData*)data;
+- (void) decodeBytes;
+- (TBXMLElement*) nextAvailableElement;
+- (TBXMLAttribute*) nextAvailableAttribute;
+@end
+
+
+
+// ================================================================================================
+// Public Implementation
+// ================================================================================================
+@implementation TBXML
+
+@synthesize rootXMLElement;
+
++ (id)tbxmlWithURL:(NSURL*)aURL {
+ return [[TBXML alloc] initWithURL:aURL];
+}
+
++ (id)tbxmlWithXMLString:(NSString*)aXMLString {
+ return [[TBXML alloc] initWithXMLString:aXMLString];
+}
+
++ (id)tbxmlWithXMLData:(NSData*)aData {
+ return [[TBXML alloc] initWithXMLData:aData];
+}
+
++ (id)tbxmlWithXMLFile:(NSString*)aXMLFile {
+ return [[TBXML alloc] initWithXMLFile:aXMLFile];
+}
+
++ (id)tbxmlWithXMLFile:(NSString*)aXMLFile fileExtension:(NSString*)aFileExtension {
+ return [[TBXML alloc] initWithXMLFile:aXMLFile fileExtension:aFileExtension];
+}
+
+- (id)init {
+ self = [super init];
+ if (self != nil) {
+ rootXMLElement = nil;
+
+ currentElementBuffer = 0;
+ currentAttributeBuffer = 0;
+
+ currentElement = 0;
+ currentAttribute = 0;
+
+ bytes = 0;
+ bytesLength = 0;
+ }
+ return self;
+}
+
+- (id)initWithURL:(NSURL*)aURL {
+ self = [self initWithXMLString:[NSString stringWithContentsOfURL:aURL encoding:NSUTF8StringEncoding error:nil]];
+ if (self != nil) {
+ }
+ return self;
+}
+
+- (id)initWithXMLString:(NSString*)aXMLString {
+ self = [self init];
+ if (self != nil) {
+
+ // copy string to byte array
+ bytesLength = [aXMLString lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+ bytes = malloc(bytesLength+1);
+ [aXMLString getBytes:bytes maxLength:bytesLength usedLength:0 encoding:NSUTF8StringEncoding options:NSStringEncodingConversionAllowLossy range:NSMakeRange(0, bytesLength) remainingRange:nil];
+
+ // set null terminator at end of byte array
+ bytes[bytesLength] = 0;
+
+ // decode xml data
+ [self decodeBytes];
+ }
+ return self;
+}
+
+- (id)initWithXMLData:(NSData*)aData {
+ self = [self init];
+ if (self != nil) {
+ // decode aData
+ [self decodeData:aData];
+ }
+
+ return self;
+}
+
+- (id)initWithXMLFile:(NSString*)aXMLFile fileExtension:(NSString*)aFileExtension {
+ self = [self init];
+ if (self != nil) {
+ // Get uncompressed file contents
+ NSData * data = [NSData dataWithUncompressedContentsOfFile:[[NSBundle mainBundle] pathForResource:aXMLFile ofType:aFileExtension]];
+
+ // decode data
+ [self decodeData:data];
+ }
+ return self;
+}
+
+- (id)initWithXMLFile:(NSString*)aXMLFile {
+ self = [self init];
+ if (self != nil) {
+ NSString * filename = [aXMLFile stringByDeletingPathExtension];
+ NSString * extension = [aXMLFile pathExtension];
+
+ // Get uncompressed file contents
+ NSData * data = [NSData dataWithUncompressedContentsOfFile:[[NSBundle mainBundle] pathForResource:filename ofType:extension]];
+
+ // decode data
+ [self decodeData:data];
+ }
+ return self;
+}
+
+@end
+
+
+// ================================================================================================
+// Static Functions Implementation
+// ================================================================================================
+
+#pragma mark -
+#pragma mark Static Functions implementation
+
+@implementation TBXML (StaticFunctions)
+
++ (NSString*) elementName:(TBXMLElement*)aXMLElement {
+ if (nil == aXMLElement->name) return @"";
+ return [NSString stringWithCString:&aXMLElement->name[0] encoding:NSUTF8StringEncoding];
+}
+
++ (NSString*) attributeName:(TBXMLAttribute*)aXMLAttribute {
+ if (nil == aXMLAttribute->name) return @"";
+ return [NSString stringWithCString:&aXMLAttribute->name[0] encoding:NSUTF8StringEncoding];
+}
+
++ (NSString*) attributeValue:(TBXMLAttribute*)aXMLAttribute {
+ if (nil == aXMLAttribute->value) return @"";
+ return [NSString stringWithCString:&aXMLAttribute->value[0] encoding:NSUTF8StringEncoding];
+}
+
++ (NSString*) textForElement:(TBXMLElement*)aXMLElement {
+ if (nil == aXMLElement->text) return @"";
+ return [NSString stringWithCString:&aXMLElement->text[0] encoding:NSUTF8StringEncoding];
+}
+
++ (NSString*) valueOfAttributeNamed:(NSString *)aName forElement:(TBXMLElement*)aXMLElement {
+ const char * name = [aName cStringUsingEncoding:NSUTF8StringEncoding];
+ NSString * value = nil;
+ TBXMLAttribute * attribute = aXMLElement->firstAttribute;
+ while (attribute) {
+ if (strlen(attribute->name) == strlen(name) && memcmp(attribute->name,name,strlen(name)) == 0) {
+ value = [NSString stringWithCString:&attribute->value[0] encoding:NSUTF8StringEncoding];
+ break;
+ }
+ attribute = attribute->next;
+ }
+ return value;
+}
+
++ (TBXMLElement*) childElementNamed:(NSString*)aName parentElement:(TBXMLElement*)aParentXMLElement{
+ TBXMLElement * xmlElement = aParentXMLElement->firstChild;
+ const char * name = [aName cStringUsingEncoding:NSUTF8StringEncoding];
+ while (xmlElement) {
+ if (strlen(xmlElement->name) == strlen(name) && memcmp(xmlElement->name,name,strlen(name)) == 0) {
+ return xmlElement;
+ }
+ xmlElement = xmlElement->nextSibling;
+ }
+ return nil;
+}
+
++ (TBXMLElement*) nextSiblingNamed:(NSString*)aName searchFromElement:(TBXMLElement*)aXMLElement{
+ TBXMLElement * xmlElement = aXMLElement->nextSibling;
+ const char * name = [aName cStringUsingEncoding:NSUTF8StringEncoding];
+ while (xmlElement) {
+ if (strlen(xmlElement->name) == strlen(name) && memcmp(xmlElement->name,name,strlen(name)) == 0) {
+ return xmlElement;
+ }
+ xmlElement = xmlElement->nextSibling;
+ }
+ return nil;
+}
+
+@end
+
+
+// ================================================================================================
+// Private Implementation
+// ================================================================================================
+
+#pragma mark -
+#pragma mark Private implementation
+
+@implementation TBXML (Private)
+
+- (void)decodeData:(NSData*)data {
+ // copy data to byte array
+ bytesLength = [data length];
+ bytes = malloc(bytesLength+1);
+ [data getBytes:bytes length:bytesLength];
+
+ // set null terminator at end of byte array
+ bytes[bytesLength] = 0;
+
+ // decode xml data
+ [self decodeBytes];
+}
+
+- (void) decodeBytes{
+
+ // -----------------------------------------------------------------------------
+ // Process xml
+ // -----------------------------------------------------------------------------
+
+ // set elementStart pointer to the start of our xml
+ char * elementStart=bytes;
+
+ // set parent element to nil
+ TBXMLElement * parentXMLElement = nil;
+
+ // find next element start
+ while (elementStart = strstr(elementStart,"<")) {
+
+ // detect comment section
+ if (strncmp(elementStart,"<!--",4) == 0) {
+ elementStart = strstr(elementStart,"-->") + 3;
+ continue;
+ }
+
+ // detect cdata section within element text
+ int isCDATA = strncmp(elementStart,"<![CDATA[",9);
+
+ // if cdata section found, skip data within cdata section and remove cdata tags
+ if (isCDATA==0) {
+
+ // find end of cdata section
+ char * CDATAEnd = strstr(elementStart,"]]>");
+
+ // find start of next element skipping any cdata sections within text
+ char * elementEnd = CDATAEnd;
+
+ // find next open tag
+ elementEnd = strstr(elementEnd,"<");
+ // if open tag is a cdata section
+ while (strncmp(elementEnd,"<![CDATA[",9) == 0) {
+ // find end of cdata section
+ elementEnd = strstr(elementEnd,"]]>");
+ // find next open tag
+ elementEnd = strstr(elementEnd,"<");
+ }
+
+ // calculate length of cdata content
+ long CDATALength = CDATAEnd-elementStart;
+
+ // calculate total length of text
+ long textLength = elementEnd-elementStart;
+
+ // remove begining cdata section tag
+ memcpy(elementStart, elementStart+9, CDATAEnd-elementStart-9);
+
+ // remove ending cdata section tag
+ memcpy(CDATAEnd-9, CDATAEnd+3, textLength-CDATALength-3);
+
+ // blank out end of text
+ memset(elementStart+textLength-12,' ',12);
+
+ // set new search start position
+ elementStart = CDATAEnd-9;
+ continue;
+ }
+
+
+ // find element end, skipping any cdata sections within attributes
+ char * elementEnd = elementStart+1;
+ while (elementEnd = strpbrk(elementEnd, "<>")) {
+ if (strncmp(elementEnd,"<![CDATA[",9) == 0) {
+ elementEnd = strstr(elementEnd,"]]>")+3;
+ } else {
+ break;
+ }
+ }
+
+
+ // null terminate element end
+ if (elementEnd) *elementEnd = 0;
+
+ // null terminate element start so previous element text doesnt overrun
+ *elementStart = 0;
+
+ // get element name start
+ char * elementNameStart = elementStart+1;
+
+ // ignore tags that start with ? or ! unless cdata "<![CDATA"
+ if (*elementNameStart == '?' || (*elementNameStart == '!' && isCDATA != 0)) {
+ elementStart = elementEnd+1;
+ continue;
+ }
+
+ // ignore attributes/text if this is a closing element
+ if (*elementNameStart == '/') {
+ elementStart = elementEnd+1;
+ if (parentXMLElement) {
+
+ if (parentXMLElement->text) {
+ // trim whitespace from start of text
+ while (isspace(*parentXMLElement->text))
+ parentXMLElement->text++;
+
+ // trim whitespace from end of text
+ char * end = parentXMLElement->text + strlen(parentXMLElement->text)-1;
+ while (end > parentXMLElement->text && isspace(*end))
+ *end--=0;
+ }
+
+ parentXMLElement = parentXMLElement->parentElement;
+
+ // if parent element has children clear text
+ if (parentXMLElement && parentXMLElement->firstChild)
+ parentXMLElement->text = 0;
+
+ }
+ continue;
+ }
+
+
+ // is this element opening and closing
+ BOOL selfClosingElement = NO;
+ if (*(elementEnd-1) == '/') {
+ selfClosingElement = YES;
+ }
+
+
+ // create new xmlElement struct
+ TBXMLElement * xmlElement = [self nextAvailableElement];
+
+ // set element name
+ xmlElement->name = elementNameStart;
+
+ // if there is a parent element
+ if (parentXMLElement) {
+
+ // if this is first child of parent element
+ if (parentXMLElement->currentChild) {
+ // set next child element in list
+ parentXMLElement->currentChild->nextSibling = xmlElement;
+ xmlElement->previousSibling = parentXMLElement->currentChild;
+
+ parentXMLElement->currentChild = xmlElement;
+
+
+ } else {
+ // set first child element
+ parentXMLElement->currentChild = xmlElement;
+ parentXMLElement->firstChild = xmlElement;
+ }
+
+ xmlElement->parentElement = parentXMLElement;
+ }
+
+
+ // in the following xml the ">" is replaced with \0 by elementEnd.
+ // element may contain no atributes and would return nil while looking for element name end
+ // <tile>
+ // find end of element name
+ char * elementNameEnd = strpbrk(xmlElement->name," /");
+
+
+ // if end was found check for attributes
+ if (elementNameEnd) {
+
+ // null terminate end of elemenet name
+ *elementNameEnd = 0;
+
+ char * chr = elementNameEnd;
+ char * name = nil;
+ char * value = nil;
+ char * CDATAStart = nil;
+ char * CDATAEnd = nil;
+ TBXMLAttribute * lastXMLAttribute = nil;
+ TBXMLAttribute * xmlAttribute = nil;
+ BOOL singleQuote = NO;
+
+ int mode = TBXML_ATTRIBUTE_NAME_START;
+
+ // loop through all characters within element
+ while (chr++ < elementEnd) {
+
+ switch (mode) {
+ // look for start of attribute name
+ case TBXML_ATTRIBUTE_NAME_START:
+ if (isspace(*chr)) continue;
+ name = chr;
+ mode = TBXML_ATTRIBUTE_NAME_END;
+ break;
+ // look for end of attribute name
+ case TBXML_ATTRIBUTE_NAME_END:
+ if (isspace(*chr) || *chr == '=') {
+ *chr = 0;
+ mode = TBXML_ATTRIBUTE_VALUE_START;
+ }
+ break;
+ // look for start of attribute value
+ case TBXML_ATTRIBUTE_VALUE_START:
+ if (isspace(*chr)) continue;
+ if (*chr == '"' || *chr == '\'') {
+ value = chr+1;
+ mode = TBXML_ATTRIBUTE_VALUE_END;
+ if (*chr == '\'')
+ singleQuote = YES;
+ else
+ singleQuote = NO;
+ }
+ break;
+ // look for end of attribute value
+ case TBXML_ATTRIBUTE_VALUE_END:
+ if (*chr == '<' && strncmp(chr, "<![CDATA[", 9) == 0) {
+ mode = TBXML_ATTRIBUTE_CDATA_END;
+ }else if ((*chr == '"' && singleQuote == NO) || (*chr == '\'' && singleQuote == YES)) {
+ *chr = 0;
+
+ // remove cdata section tags
+ while (CDATAStart = strstr(value, "<![CDATA[")) {
+
+ // remove begin cdata tag
+ memcpy(CDATAStart, CDATAStart+9, strlen(CDATAStart)-8);
+
+ // search for end cdata
+ CDATAEnd = strstr(CDATAStart,"]]>");
+
+ // remove end cdata tag
+ memcpy(CDATAEnd, CDATAEnd+3, strlen(CDATAEnd)-2);
+ }
+
+
+ // create new attribute
+ xmlAttribute = [self nextAvailableAttribute];
+
+ // if this is the first attribute found, set pointer to this attribute on element
+ if (!xmlElement->firstAttribute) xmlElement->firstAttribute = xmlAttribute;
+ // if previous attribute found, link this attribute to previous one
+ if (lastXMLAttribute) lastXMLAttribute->next = xmlAttribute;
+ // set last attribute to this attribute
+ lastXMLAttribute = xmlAttribute;
+
+ // set attribute name & value
+ xmlAttribute->name = name;
+ xmlAttribute->value = value;
+
+ // clear name and value pointers
+ name = nil;
+ value = nil;
+
+ // start looking for next attribute
+ mode = TBXML_ATTRIBUTE_NAME_START;
+ }
+ break;
+ // look for end of cdata
+ case TBXML_ATTRIBUTE_CDATA_END:
+ if (*chr == ']') {
+ if (strncmp(chr, "]]>", 3) == 0) {
+ mode = TBXML_ATTRIBUTE_VALUE_END;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ // if tag is not self closing, set parent to current element
+ if (!selfClosingElement) {
+ // set text on element to element end+1
+ if (*(elementEnd+1) != '>')
+ xmlElement->text = elementEnd+1;
+
+ parentXMLElement = xmlElement;
+ }
+
+ // start looking for next element after end of current element
+ elementStart = elementEnd+1;
+ }
+}
+
+// Deallocate used memory
+- (void) dealloc {
+
+ if (bytes) {
+ free(bytes);
+ bytes = nil;
+ }
+
+ while (currentElementBuffer) {
+ if (currentElementBuffer->elements)
+ free(currentElementBuffer->elements);
+
+ if (currentElementBuffer->previous) {
+ currentElementBuffer = currentElementBuffer->previous;
+ free(currentElementBuffer->next);
+ } else {
+ free(currentElementBuffer);
+ currentElementBuffer = 0;
+ }
+ }
+
+ while (currentAttributeBuffer) {
+ if (currentAttributeBuffer->attributes)
+ free(currentAttributeBuffer->attributes);
+
+ if (currentAttributeBuffer->previous) {
+ currentAttributeBuffer = currentAttributeBuffer->previous;
+ free(currentAttributeBuffer->next);
+ } else {
+ free(currentAttributeBuffer);
+ currentAttributeBuffer = 0;
+ }
+ }
+
+}
+
+- (TBXMLElement*) nextAvailableElement {
+ currentElement++;
+
+ if (!currentElementBuffer) {
+ currentElementBuffer = calloc(1, sizeof(TBXMLElementBuffer));
+ currentElementBuffer->elements = (TBXMLElement*)calloc(1,sizeof(TBXMLElement)*MAX_ELEMENTS);
+ currentElement = 0;
+ rootXMLElement = &currentElementBuffer->elements[currentElement];
+ } else if (currentElement >= MAX_ELEMENTS) {
+ currentElementBuffer->next = calloc(1, sizeof(TBXMLElementBuffer));
+ currentElementBuffer->next->previous = currentElementBuffer;
+ currentElementBuffer = currentElementBuffer->next;
+ currentElementBuffer->elements = (TBXMLElement*)calloc(1,sizeof(TBXMLElement)*MAX_ELEMENTS);
+ currentElement = 0;
+ }
+
+ return &currentElementBuffer->elements[currentElement];
+}
+
+- (TBXMLAttribute*) nextAvailableAttribute {
+ currentAttribute++;
+
+ if (!currentAttributeBuffer) {
+ currentAttributeBuffer = calloc(1, sizeof(TBXMLAttributeBuffer));
+ currentAttributeBuffer->attributes = (TBXMLAttribute*)calloc(MAX_ATTRIBUTES,sizeof(TBXMLAttribute));
+ currentAttribute = 0;
+ } else if (currentAttribute >= MAX_ATTRIBUTES) {
+ currentAttributeBuffer->next = calloc(1, sizeof(TBXMLAttributeBuffer));
+ currentAttributeBuffer->next->previous = currentAttributeBuffer;
+ currentAttributeBuffer = currentAttributeBuffer->next;
+ currentAttributeBuffer->attributes = (TBXMLAttribute*)calloc(MAX_ATTRIBUTES,sizeof(TBXMLAttribute));
+ currentAttribute = 0;
+ }
+
+ return &currentAttributeBuffer->attributes[currentAttribute];
+}
+
+@end
Please sign in to comment.
Something went wrong with that request. Please try again.