Title: [169018] trunk/Source/WebKit/mac
- Revision
- 169018
- Author
- [email protected]
- Date
- 2014-05-18 14:36:49 -0700 (Sun, 18 May 2014)
Log Message
Bring back two NSString category methods on iOS
https://bugs.webkit.org/show_bug.cgi?id=133055
<rdar://problem/16951983>
Reviewed by Adele Peterson.
* Misc/WebNSURLExtras.h:
* Misc/WebNSURLExtras.mm:
(-[NSString _webkit_unescapedQueryValue]):
(-[NSString _webkit_queryKeysAndValues]):
Modified Paths
Diff
Modified: trunk/Source/WebKit/mac/ChangeLog (169017 => 169018)
--- trunk/Source/WebKit/mac/ChangeLog 2014-05-18 20:36:43 UTC (rev 169017)
+++ trunk/Source/WebKit/mac/ChangeLog 2014-05-18 21:36:49 UTC (rev 169018)
@@ -1,3 +1,16 @@
+2014-05-18 Anders Carlsson <[email protected]>
+
+ Bring back two NSString category methods on iOS
+ https://bugs.webkit.org/show_bug.cgi?id=133055
+ <rdar://problem/16951983>
+
+ Reviewed by Adele Peterson.
+
+ * Misc/WebNSURLExtras.h:
+ * Misc/WebNSURLExtras.mm:
+ (-[NSString _webkit_unescapedQueryValue]):
+ (-[NSString _webkit_queryKeysAndValues]):
+
2014-05-18 Rik Cabanier <[email protected]>
support for navigator.hardwareConcurrency
Modified: trunk/Source/WebKit/mac/Misc/WebNSURLExtras.h (169017 => 169018)
--- trunk/Source/WebKit/mac/Misc/WebNSURLExtras.h 2014-05-18 20:36:43 UTC (rev 169017)
+++ trunk/Source/WebKit/mac/Misc/WebNSURLExtras.h 2014-05-18 21:36:49 UTC (rev 169018)
@@ -97,4 +97,9 @@
- (NSString *)_webkit_URLFragment;
- (NSString *)_webkit_scriptIfJavaScriptURL;
+#if TARGET_OS_IPHONE
+- (NSString *)_webkit_unescapedQueryValue;
+- (NSDictionary *)_webkit_queryKeysAndValues;
+#endif
+
@end
Modified: trunk/Source/WebKit/mac/Misc/WebNSURLExtras.mm (169017 => 169018)
--- trunk/Source/WebKit/mac/Misc/WebNSURLExtras.mm 2014-05-18 20:36:43 UTC (rev 169017)
+++ trunk/Source/WebKit/mac/Misc/WebNSURLExtras.mm 2014-05-18 21:36:49 UTC (rev 169018)
@@ -396,4 +396,73 @@
return [self substringFromIndex:fragmentRange.location + 1];
}
+#if PLATFORM(IOS)
+
+- (NSString *)_webkit_unescapedQueryValue
+{
+ NSMutableString *string = [[[self stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] mutableCopy] autorelease];
+ if (!string) // If we failed to decode the URL as UTF8, fall back to Latin1
+ string = [[[self stringByReplacingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding] mutableCopy] autorelease];
+ [string replaceOccurrencesOfString:@"+" withString:@" " options:NSLiteralSearch range:NSMakeRange(0, [string length])];
+ return string;
+}
+
+- (NSDictionary *)_webkit_queryKeysAndValues
+{
+ unsigned queryLength = [self length];
+ if (!queryLength)
+ return nil;
+
+ NSMutableDictionary *queryKeysAndValues = nil;
+ NSRange equalSearchRange = NSMakeRange(0, queryLength);
+
+ while (equalSearchRange.location < queryLength - 1 && equalSearchRange.length) {
+
+ // Search for "=".
+ NSRange equalRange = [self rangeOfString:@"=" options:NSLiteralSearch range:equalSearchRange];
+ if (equalRange.location == NSNotFound)
+ break;
+
+ unsigned indexAfterEqual = equalRange.location + 1;
+ if (indexAfterEqual > queryLength - 1)
+ break;
+
+ // Get the key before the "=".
+ NSRange keyRange = NSMakeRange(equalSearchRange.location, equalRange.location - equalSearchRange.location);
+
+ // Seach for the ampersand.
+ NSRange ampersandSearchRange = NSMakeRange(indexAfterEqual, queryLength - indexAfterEqual);
+ NSRange ampersandRange = [self rangeOfString:@"&" options:NSLiteralSearch range:ampersandSearchRange];
+
+ // Get the value after the "=", before the ampersand.
+ NSRange valueRange;
+ if (ampersandRange.location != NSNotFound)
+ valueRange = NSMakeRange(indexAfterEqual, ampersandRange.location - indexAfterEqual);
+ else
+ valueRange = NSMakeRange(indexAfterEqual, queryLength - indexAfterEqual);
+
+ // Save the key and the value.
+ if (keyRange.length && valueRange.length) {
+ if (queryKeysAndValues == nil)
+ queryKeysAndValues = [NSMutableDictionary dictionary];
+ NSString *key = [[self substringWithRange:keyRange] lowercaseString];
+ NSString *value = [[self substringWithRange:valueRange] _webkit_unescapedQueryValue];
+ if ([key length] && [value length])
+ [queryKeysAndValues setObject:value forKey:key];
+ }
+
+ // At the end.
+ if (ampersandRange.location == NSNotFound)
+ break;
+
+ // Continue searching after the ampersand.
+ unsigned indexAfterAmpersand = ampersandRange.location + 1;
+ equalSearchRange = NSMakeRange(indexAfterAmpersand, queryLength - indexAfterAmpersand);
+ }
+
+ return queryKeysAndValues;
+}
+
+#endif // PLATFORM(IOS)
+
@end
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes