Skip to content
This repository was archived by the owner on Apr 25, 2018. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: davedelong/Demos
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: EmbeddedSources/Demos
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 8 commits
  • 11 files changed
  • 1 contributor

Commits on Jun 7, 2012

  1. Fixed spaces encoding

    dodikk committed Jun 7, 2012
    Copy the full SHA
    1309e27 View commit details

Commits on Aug 29, 2012

  1. removed unwanted files

    dodikk committed Aug 29, 2012
    Copy the full SHA
    c7861bb View commit details
  2. Upgraded a compiler

    dodikk committed Aug 29, 2012
    Copy the full SHA
    232f55d View commit details
  3. fixed compiler options

    dodikk committed Aug 29, 2012
    Copy the full SHA
    6f99f01 View commit details

Commits on Sep 10, 2012

  1. vlg - fixed compiler options

    dodikk committed Sep 10, 2012
    Copy the full SHA
    487b506 View commit details
  2. Copy the full SHA
    023264f View commit details
  3. Copy the full SHA
    4bc9ef0 View commit details

Commits on Nov 7, 2013

  1. added arm64 support

    dodikk committed Nov 7, 2013
    Copy the full SHA
    093a6fa View commit details

This file was deleted.

This file was deleted.

35 changes: 15 additions & 20 deletions DDURLBuilder/DDURLBuilder.h
Original file line number Diff line number Diff line change
@@ -9,33 +9,28 @@
#import <Foundation/Foundation.h>


@interface DDURLBuilder : NSObject {
@private

NSString *scheme;
NSString *user;
NSString *password;
NSString *host;
NSNumber *port;
NSString *path;
NSMutableDictionary *queryValues;
NSString *fragment;
@interface DDURLBuilder : NSObject
{
@private
NSMutableDictionary* _queryValues;
}

+ (id) URLBuilderWithURL:(NSURL *)url;
- (id) initWithURL:(NSURL *)url;

@property (nonatomic, retain) NSURL *URL;

@property (nonatomic, retain) NSString *scheme;
@property (nonatomic, retain) NSString *user;
@property (nonatomic, retain) NSString *password;
@property (nonatomic, retain) NSString *host;
@property (nonatomic, retain) NSNumber *port;
@property (nonatomic, retain) NSString *path;
@property (nonatomic, retain) NSString *fragment;

@property (nonatomic, assign) BOOL usesSchemeSeparators;
@property ( nonatomic, retain ) NSString *scheme;
@property ( nonatomic, retain ) NSString *user;
@property ( nonatomic, retain ) NSString *password;
@property ( nonatomic, retain ) NSString *host;
@property ( nonatomic, retain ) NSNumber *port;
@property ( nonatomic, retain ) NSString *path;
@property ( nonatomic, retain ) NSString *fragment;

@property ( nonatomic, assign ) BOOL shouldSkipPathPercentEncoding;
@property ( nonatomic, assign ) BOOL usesSchemeSeparators;
@property ( nonatomic, assign ) BOOL shouldEncodeSpaceAsHex;

- (NSArray *) queryValuesForKey:(NSString *)key;
- (void) addQueryValue:(NSString *)value forKey:(NSString *)key;
128 changes: 70 additions & 58 deletions DDURLBuilder/DDURLBuilder.m
Original file line number Diff line number Diff line change
@@ -8,46 +8,43 @@

#import "DDURLBuilder.h"

NSString *ddurlbuilder_percentEncode(NSString *string) {
@implementation DDURLBuilder

-(NSString*)ddurlbuilder_percentEncode:(NSString*)string
{
NSMutableString * output = [NSMutableString string];
const unsigned char * source = (const unsigned char *)[string UTF8String];
size_t sourceLen = strlen((const char *)source);
for (size_t i = 0; i < sourceLen; ++i) {
for (size_t i = 0; i < sourceLen; ++i)
{
const unsigned char thisChar = source[i];
if (thisChar == ' '){
if ( thisChar == ' ' && !self.shouldEncodeSpaceAsHex )
{
[output appendString:@"+"];
} else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' ||
(thisChar >= 'a' && thisChar <= 'z') ||
(thisChar >= 'A' && thisChar <= 'Z') ||
(thisChar >= '0' && thisChar <= '9')) {
}
else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' ||
(thisChar >= 'a' && thisChar <= 'z') ||
(thisChar >= 'A' && thisChar <= 'Z') ||
(thisChar >= '0' && thisChar <= '9'))
{
[output appendFormat:@"%c", thisChar];
} else {
}
else
{
[output appendFormat:@"%%%02X", thisChar];
}
}
return output;
}

@implementation DDURLBuilder

@synthesize scheme;
@synthesize user;
@synthesize password;
@synthesize host;
@synthesize path;
@synthesize fragment;
@synthesize port;

@synthesize usesSchemeSeparators;

+ (id) URLBuilderWithURL:(NSURL *)url {
return [[[self alloc] initWithURL:url] autorelease];
}

- (id) initWithURL:(NSURL *)url {
self = [super init];
if (self) {
queryValues = [[NSMutableDictionary alloc] init];
self->_queryValues = [[NSMutableDictionary alloc] init];
[self setUsesSchemeSeparators:YES];
if (url) {
[self setURL:url];
@@ -57,14 +54,14 @@ - (id) initWithURL:(NSURL *)url {
}

- (void)dealloc {
[scheme release];
[user release];
[password release];
[host release];
[port release];
[path release];
[queryValues release];
[fragment release];
[ self->_scheme release];
[ self->_user release];
[ self->_password release];
[ self->_host release];
[ self->_port release];
[ self->_path release];
[ self->_queryValues release];
[ self->_fragment release];
[super dealloc];
}

@@ -80,7 +77,7 @@ - (void) setURL:(NSURL *)URL {
NSString *absolute = [URL absoluteString];
[self setUsesSchemeSeparators:([absolute hasPrefix:[NSString stringWithFormat:@"%@://", [self scheme]]])];

[queryValues removeAllObjects];
[self->_queryValues removeAllObjects];
NSString *query = [URL query];
NSArray *components = [query componentsSeparatedByString:@"&"];
for (NSString *component in components) {
@@ -89,7 +86,7 @@ - (void) setURL:(NSURL *)URL {
NSLog(@"illegal query string component: %@", component);
continue;
}

NSString *key = [[bits objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *value = [[bits objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[self addQueryValue:value forKey:key];
@@ -99,82 +96,97 @@ - (void) setURL:(NSURL *)URL {
- (NSURL *)URL {
if ([self scheme] == nil || [self host] == nil) { return nil; }

NSMutableString *url = [NSMutableString string];
NSMutableString *urlString = [NSMutableString string];

[url appendFormat:@"%@:", [self scheme]];
[urlString appendFormat:@"%@:", [self scheme]];
if ([self usesSchemeSeparators]) {
[url appendString:@"//"];
[urlString appendString:@"//"];
}
if ([self user]) {
[url appendString:ddurlbuilder_percentEncode([self user])];
[urlString appendString: [ self ddurlbuilder_percentEncode: [self user] ]];
if ([self password]) {
[url appendFormat:@":%@", ddurlbuilder_percentEncode([self password])];
[urlString appendFormat:@":%@", [ self ddurlbuilder_percentEncode: [self password] ] ];
}
[url appendString:@"@"];
[urlString appendString:@"@"];
}

[url appendString:ddurlbuilder_percentEncode([self host])];
[urlString appendString: [ self ddurlbuilder_percentEncode: [self host] ] ];
if ([self port]) {
[url appendFormat:@":%@", [self port]];
[urlString appendFormat:@":%@", [self port]];
}


if ([self path]) {
NSArray *pathComponents = [[self path] pathComponents];
for (NSString *component in pathComponents) {
if ([component isEqualToString:@"/"]) { continue; }
[url appendFormat:@"/%@", ddurlbuilder_percentEncode(component)];
if ( [self path] )
{
if ( self.shouldSkipPathPercentEncoding )
{
[ urlString appendString: [ self path ] ];
}
else
{
NSArray *pathComponents = [[self path] pathComponents];
for (NSString *component in pathComponents)
{
if ([component isEqualToString:@"/"])
{
continue;
}
[urlString appendFormat:@"/%@", [ self ddurlbuilder_percentEncode: component ] ];
}
}
}

if ([queryValues count] > 0) {
if ([ self->_queryValues count] > 0)
{
NSMutableArray *components = [NSMutableArray array];
for (NSString *key in queryValues) {
NSArray *values = [queryValues objectForKey:key];
key = ddurlbuilder_percentEncode(key);
for (NSString *value in values) {
value = ddurlbuilder_percentEncode(value);
for (NSString *key in self->_queryValues )
{
NSArray *values = [ self->_queryValues objectForKey:key];
key = [ self ddurlbuilder_percentEncode: key ];
for (NSString *value in values)
{
value = [ self ddurlbuilder_percentEncode: value ];
NSString *component = [NSString stringWithFormat:@"%@=%@", key, value];
[components addObject:component];
}
}
NSString *queryString = [components componentsJoinedByString:@"&"];
[url appendFormat:@"?%@", queryString];
[urlString appendFormat:@"?%@", queryString];
}

if ([self fragment]) {
[url appendFormat:@"#%@", [self fragment]];
[urlString appendFormat:@"#%@", [self fragment]];
}

return [NSURL URLWithString:url];
return [NSURL URLWithString:urlString];
}

- (NSArray *) queryValuesForKey:(NSString *)key {
if (key == nil) { return nil; }
return [[[queryValues objectForKey:key] copy] autorelease];
return [[[ self->_queryValues objectForKey:key] copy] autorelease];
}

- (void) addQueryValue:(NSString *)value forKey:(NSString *)key {
if (value == nil || key == nil) { return; }
NSMutableArray *values = [queryValues objectForKey:key];
NSMutableArray *values = [ self->_queryValues objectForKey:key];
if (values == nil) {
values = [NSMutableArray array];
[queryValues setObject:values forKey:key];
[ self->_queryValues setObject:values forKey:key];
}
[values addObject:value];
}

- (void) removeQueryValue:(NSString *)value forKey:(NSString *)key {
if (value == nil || key == nil) { return; }
NSMutableArray *values = [queryValues objectForKey:key];
NSMutableArray *values = [ self->_queryValues objectForKey:key];
if (values) {
[values removeObject:value];
}
}

- (void) removeQueryValuesForKey:(NSString *)key {
if (key == nil) { return; }
[queryValues removeObjectForKey:key];
[ self->_queryValues removeObjectForKey:key];
}

@end
12 changes: 6 additions & 6 deletions DDURLBuilder/DDUrlBuilder/DDUrlBuilder.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -281,7 +281,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
@@ -295,15 +295,14 @@
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_PEDANTIC = NO;
GCC_WARN_SIGN_COMPARE = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
SDKROOT = iphoneos;
};
name = Debug;
@@ -312,22 +311,21 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
COPY_PHASE_STRIP = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_PEDANTIC = NO;
GCC_WARN_SIGN_COMPARE = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
};
@@ -408,6 +406,7 @@
7E54C1E7157F8687007D89F1 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
7E54C201157F889A007D89F1 /* Build configuration list for PBXNativeTarget "DDUrlBuilderTest" */ = {
isa = XCConfigurationList;
@@ -416,6 +415,7 @@
7E54C203157F889A007D89F1 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
33 changes: 33 additions & 0 deletions DDURLBuilder/DDUrlBuilder/DDUrlBuilderTest/DDUrlBuilderTest.m
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@

@implementation DDUrlBuilderTest


// non-deterministic due to NSDictionary usage
-(void)testAuthorExample
{

@@ -20,7 +22,38 @@ -(void)testAuthorExample

NSURL* received_ = [ builder URL ];

// non-deterministic due to NSDictionary usage
STAssertTrue( [ expected_ isEqual: received_ ], @"result URL mismatch" );
}

-(void)testSkipEncodingFlagAppendsPathAsIs
{
DDURLBuilder* builder_ = [ DDURLBuilder URLBuilderWithURL: [ NSURL URLWithString: @"http://10.38.10.244/sitecore/login" ] ];
builder_.shouldSkipPathPercentEncoding = YES;
builder_.path = @"/sitecore/shell/Applications/Login/Users/Users.aspx?su=%2fsitecore%2fshell%2fapplications%2fclientusesoswindows.aspx%3fsc_lang%3den";

NSURL* receivedUrl_ = [ builder_ URL ];
NSString* received_ = [ receivedUrl_ absoluteString ];

STAssertEqualObjects(
received_,
@"http://10.38.10.244/sitecore/shell/Applications/Login/Users/Users.aspx?su=%2fsitecore%2fshell%2fapplications%2fclientusesoswindows.aspx%3fsc_lang%3den",
@"URL mismatch");
}

-(void)testDisabledSkipEncodingFlagSplitsPath
{
DDURLBuilder* builder_ = [ DDURLBuilder URLBuilderWithURL: [ NSURL URLWithString: @"http://10.38.10.244/sitecore/login" ] ];
builder_.shouldSkipPathPercentEncoding = NO;
builder_.path = @"/sitecore/shell/Applications/Login/Users/Users.aspx?su=%2fsitecore%2fshell%2fapplications%2fclientusesoswindows.aspx%3fsc_lang%3den";

NSURL* receivedUrl_ = [ builder_ URL ];
NSString* received_ = [ receivedUrl_ absoluteString ];

STAssertEqualObjects(
received_,
@"http://10.38.10.244/sitecore/shell/Applications/Login/Users/Users.aspx%3Fsu%3D%252fsitecore%252fshell%252fapplications%252fclientusesoswindows.aspx%253fsc_lang%253den",
@"URL mismatch");
}

@end

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.