summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Schleifer <js@webkeks.org>2015-06-30 21:56:25 +0200
committerJonathan Schleifer <js@webkeks.org>2015-06-30 21:56:25 +0200
commit3b7d9f9e5a7e5320207d949156c1f3b4f7ec7025 (patch)
treed44db10cc2eba1e3f31a252ee19e1268c63166f6
parentf9f3e19ec48a0f145ac880eaaabb04a4a41d7bc3 (diff)
Add -[stringByURLEncodingWithIgnoredCharacters:]
-rw-r--r--src/OFString+URLEncoding.h10
-rw-r--r--src/OFString+URLEncoding.m8
2 files changed, 17 insertions, 1 deletions
diff --git a/src/OFString+URLEncoding.h b/src/OFString+URLEncoding.h
index 64490a00..31338947 100644
--- a/src/OFString+URLEncoding.h
+++ b/src/OFString+URLEncoding.h
@@ -35,6 +35,16 @@ extern int _OFString_URLEncoding_reference;
- (OFString*)stringByURLEncoding;
/*!
+ * @brief Encodes a string for use in a URL, but does not escape the specified
+ * ignored characters.
+ *
+ * @param ignored A C string of characters that should not be escaped
+ *
+ * @return A new autoreleased string
+ */
+- (OFString*)stringByURLEncodingWithIgnoredCharacters: (const char*)ignored;
+
+/*!
* @brief Decodes a string used in a URL.
*
* @return A new autoreleased string
diff --git a/src/OFString+URLEncoding.m b/src/OFString+URLEncoding.m
index c6d149a1..b49693c8 100644
--- a/src/OFString+URLEncoding.m
+++ b/src/OFString+URLEncoding.m
@@ -31,6 +31,11 @@ int _OFString_URLEncoding_reference;
@implementation OFString (URLEncoding)
- (OFString*)stringByURLEncoding
{
+ return [self stringByURLEncodingWithIgnoredCharacters: ""];
+}
+
+- (OFString*)stringByURLEncodingWithIgnoredCharacters: (const char*)ignored
+{
void *pool = objc_autoreleasePoolPush();
const char *string = [self UTF8String];
char *retCString;
@@ -55,7 +60,8 @@ int _OFString_URLEncoding_reference;
if (!(*string & 0x80) && (isalnum((int)*string) ||
*string == '$' || *string == '-' || *string == '_' ||
*string == '.' || *string == '!' || *string == '*' ||
- *string == '(' || *string == ')' || *string == ','))
+ *string == '(' || *string == ')' || *string == ',' ||
+ strchr(ignored, *string) != NULL))
retCString[i++] = *string;
else {
uint8_t high, low;