Skip to content
Newer
Older
100755 63 lines (56 sloc) 2.06 KB
4d4563c @JanX2 Objective C port of “diff-match-patch” as released in sub-folder “obj…
authored
1 /*
2 * Diff Match and Patch
3 *
4 * Copyright 2010 geheimwerk.de.
5 * http://code.google.com/p/google-diff-match-patch/
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * Author: fraser@google.com (Neil Fraser)
20 * ObjC port: jan@geheimwerk.de (Jan Weiß)
21 */
22
23 #import "NSString+UriCompatibility.h"
fda8aa4 @JanX2 Preparing for ARC using JXArcCompatibilityMacros.
authored
24 #import "JXArcCompatibilityMacros.h"
4d4563c @JanX2 Objective C port of “diff-match-patch” as released in sub-folder “obj…
authored
25
26
27 @implementation NSString (UriCompatibility)
28
29 /**
30 * Escape excluding selected chars for compatability with JavaScript's encodeURI.
31 * This method produces uppercase hex.
32 *
33 * @param str The CFStringRef to escape.
34 * @return The escaped CFStringRef.
35 */
36 - (NSString *)diff_stringByAddingPercentEscapesForEncodeUriCompatibility;
37 {
38 CFStringRef urlString = CFURLCreateStringByAddingPercentEscapes(NULL,
fda8aa4 @JanX2 Preparing for ARC using JXArcCompatibilityMacros.
authored
39 JX_BRIDGED_CAST(CFStringRef, self),
4d4563c @JanX2 Objective C port of “diff-match-patch” as released in sub-folder “obj…
authored
40 CFSTR(" !~*'();/?:@&=+$,#"),
41 NULL,
42 kCFStringEncodingUTF8);
fda8aa4 @JanX2 Preparing for ARC using JXArcCompatibilityMacros.
authored
43 return JX_TRANSFER_CF_TO_OBJC(NSString *, urlString);
4d4563c @JanX2 Objective C port of “diff-match-patch” as released in sub-folder “obj…
authored
44 }
45
46 /**
47 * Unescape all percent escapes.
48 *
49 * Example: "%3f" -> "?", "%24" -> "$", etc.
50 *
51 * @return The unescaped NSString.
52 */
53 - (NSString *)diff_stringByReplacingPercentEscapesForEncodeUriCompatibility;
54 {
55 CFStringRef decodedString = CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL,
fda8aa4 @JanX2 Preparing for ARC using JXArcCompatibilityMacros.
authored
56 JX_BRIDGED_CAST(CFStringRef, self),
4d4563c @JanX2 Objective C port of “diff-match-patch” as released in sub-folder “obj…
authored
57 CFSTR(""),
58 kCFStringEncodingUTF8);
fda8aa4 @JanX2 Preparing for ARC using JXArcCompatibilityMacros.
authored
59 return JX_TRANSFER_CF_TO_OBJC(NSString *, decodedString);
4d4563c @JanX2 Objective C port of “diff-match-patch” as released in sub-folder “obj…
authored
60 }
61
62 @end
Something went wrong with that request. Please try again.