Skip to content

Commit

Permalink
Merge pull request #6 from leverdeterre/master
Browse files Browse the repository at this point in the history
Fixing bitmasking values
  • Loading branch information
nicklockwood committed May 25, 2014
2 parents 9de114e + 6abf1af commit 26b3339
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
20 changes: 15 additions & 5 deletions RequestUtils/RequestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,23 @@ static NSString *const URLFragmentComponent = @"fragment";
typedef NS_OPTIONS(NSUInteger, URLQueryOptions)
{
URLQueryOptionDefault = 0,
URLQueryOptionKeepLastValue = 1,
URLQueryOptionKeepFirstValue = 2,
URLQueryOptionUseArrays = 3,
URLQueryOptionAlwaysUseArrays = 4,
URLQueryOptionUseArraySyntax = 8
URLQueryOptionKeepLastValue = 1 << 0,
URLQueryOptionKeepFirstValue = 1 << 1,
URLQueryOptionUseArrays = 1 << 2,
URLQueryOptionAlwaysUseArrays = 1 << 3,
URLQueryOptionUseArraySyntax = 1 << 4
};

/*
0000 = 0 URLQueryOptionDefault
0001 = 1 URLQueryOptionKeepLastValue
0010 = 2 URLQueryOptionKeepFirstValue
0011 = 4 URLQueryOptionUseArrays
0100 = 8 URLQueryOptionAlwaysUseArrays
1000 = 16 URLQueryOptionUseArraySyntax
*/



@interface NSString (RequestUtils)

Expand Down
8 changes: 4 additions & 4 deletions RequestUtils/RequestUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ + (NSString *)URLQueryWithParameters:(NSDictionary *)parameters

+ (NSString *)URLQueryWithParameters:(NSDictionary *)parameters options:(URLQueryOptions)options
{
BOOL useArraySyntax = options & 8;
URLQueryOptions arrayHandling = (options & 7) ?: URLQueryOptionUseArrays;
BOOL useArraySyntax = options & URLQueryOptionUseArraySyntax;
URLQueryOptions arrayHandling = (options & (URLQueryOptionUseArrays | URLQueryOptionAlwaysUseArrays)) ?: URLQueryOptionUseArrays;

NSMutableString *result = [NSMutableString string];
for (NSString *key in parameters)
Expand Down Expand Up @@ -333,7 +333,7 @@ - (NSString *)stringByMergingURLQuery:(NSString *)query

- (NSString *)stringByMergingURLQuery:(NSString *)query options:(URLQueryOptions)options
{
URLQueryOptions arrayHandling = (options & 7) ?: URLQueryOptionKeepLastValue;
URLQueryOptions arrayHandling = (options & (URLQueryOptionUseArrays | URLQueryOptionAlwaysUseArrays)) ?: URLQueryOptionKeepLastValue;

//check for empty input
query = [query URLQuery];
Expand Down Expand Up @@ -399,7 +399,7 @@ - (NSDictionary *)URLQueryParameters

- (NSDictionary *)URLQueryParametersWithOptions:(URLQueryOptions)options
{
URLQueryOptions arrayHandling = (options & 7) ?: URLQueryOptionKeepLastValue;
URLQueryOptions arrayHandling = (options & (URLQueryOptionUseArrays | URLQueryOptionAlwaysUseArrays)) ?: URLQueryOptionKeepLastValue;

NSString *queryString = [self URLQuery];

Expand Down

0 comments on commit 26b3339

Please sign in to comment.