Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Expose utility functions for base64 and url encoding.

  • Loading branch information...
commit 25d7a022fa3808942c46d420bbf1df821cf078a4 1 parent 333d337
@adamjernst authored
View
9 AEURLConnection/AEURLRequestFactory.h
@@ -49,6 +49,15 @@ typedef id (^AEURLParameterProcessor)(NSDictionary *parameters, NSMutableURLRequ
// x-www-form-urlencoded format, like a browser's POST form encoding.
+ (AEURLParameterProcessor)formURLEncodedProcessor;
+// A utility function to url-encode a value.
+NSString * AEURLEncodedStringFromString(NSString *string);
+
+// A utility function to turn a dictionary into a urlencoded string.
+NSString * AEQueryStringFromParameters(NSDictionary *parameters);
+
+// A utility function to base-64 encode a string.
+NSString * AEBase64EncodedStringFromString(NSString *string);
+
// See AEJSONProcessor for a parameter processing block that creates JSON.
@end
View
11 AEURLConnection/AEURLRequestFactory.m
@@ -8,11 +8,6 @@
#import "AEURLRequestFactory.h"
-// Forward declarations:
-static NSString * AEURLEncodedStringFromString(NSString *string);
-static NSString * AEQueryStringFromParameters(NSDictionary *parameters);
-static NSString * AEBase64EncodedStringFromString(NSString *string);
-
@implementation AEURLRequestFactory
+ (AEURLRequestFactory *)defaultFactory {
@@ -109,13 +104,13 @@ + (AEURLParameterProcessor)formURLEncodedProcessor {
// AF in the function prefix to prevent linker conflicts). Thanks AFNetworking!
// (Used with permission.)
-static NSString * AEURLEncodedStringFromString(NSString *string) {
+NSString * AEURLEncodedStringFromString(NSString *string) {
static NSString * const kAFLegalCharactersToBeEscaped = @"?!@#$^&%*+,:;='\"`<>()[]{}/\\|~ ";
return [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, (CFStringRef)kAFLegalCharactersToBeEscaped, CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)) autorelease];
}
-static NSString * AEQueryStringFromParameters(NSDictionary *parameters) {
+NSString * AEQueryStringFromParameters(NSDictionary *parameters) {
NSMutableArray *mutableParameterComponents = [NSMutableArray array];
for (id key in [parameters allKeys]) {
NSString *component = [NSString stringWithFormat:@"%@=%@", AEURLEncodedStringFromString([key description]), AEURLEncodedStringFromString([[parameters valueForKey:key] description])];
@@ -125,7 +120,7 @@ + (AEURLParameterProcessor)formURLEncodedProcessor {
return [mutableParameterComponents componentsJoinedByString:@"&"];
}
-static NSString * AEBase64EncodedStringFromString(NSString *string) {
+NSString * AEBase64EncodedStringFromString(NSString *string) {
NSData *data = [NSData dataWithBytes:[string UTF8String] length:[string length]];
NSUInteger length = [data length];
NSMutableData *mutableData = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
Please sign in to comment.
Something went wrong with that request. Please try again.