Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 77 lines (59 sloc) 3.383 kb
08c3984 @mikeabdullah KSURLFormatter.
mikeabdullah authored
1 //
2 // KSURLFormatter.h
3 //
5e343ed @danwood update copyrights to 2012
danwood authored
4 // Copyright (c) 2008-2012 Mike Abdullah and Karelia Software
08c3984 @mikeabdullah KSURLFormatter.
mikeabdullah authored
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 // DISCLAIMED. IN NO EVENT SHALL MIKE ABDULLAH OR KARELIA SOFTWARE BE LIABLE FOR ANY
19 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 //
26
27
28 #import <Foundation/Foundation.h>
29
30
31 @interface KSURLFormatter : NSFormatter
32 {
33 @private
34 BOOL _useDisplayNameForFileURLs;
e2d8176 @mikeabdullah Expose .defaultScheme
mikeabdullah authored
35 NSString *_defaultScheme;
a32a6a0 @mikeabdullah .allowedSchemes feature, where anything outside the list will be convert...
mikeabdullah authored
36 NSArray *_allowedSchemes;
08c3984 @mikeabdullah KSURLFormatter.
mikeabdullah authored
37 NSString *_fallbackTopLevelDomain;
32ba7f4 @mikeabdullah .generatesURLStrings property. Defaults to NO.
mikeabdullah authored
38 BOOL _generateStrings;
08c3984 @mikeabdullah KSURLFormatter.
mikeabdullah authored
39 }
40
41 #pragma mark Class Methods
42
43 // Uses the really basic settings to build a URL from the string.
44 /*" Fix a URL-encoded string that may have some characters that makes NSURL barf.
45 It basically re-encodes the string, but ignores escape characters + and %, and also #.
46 Example bad characters: smart quotes. If you try to create NSURL URLWithString: and your string
47 has smart quotes, the NSURL is nil!
48 "*/
49 + (NSURL *)URLFromString:(NSString *)string;
50
83c7536 @mikeabdullah +isValidEmailAddress:
mikeabdullah authored
51 + (BOOL)isValidEmailAddress:(NSString *)address;
f3ba44b @mikeabdullah Add +isLikelyEmailAddress as better suited for vague user input.
mikeabdullah authored
52 + (BOOL)isLikelyEmailAddress:(NSString *)address; // much the same as above, but ignores some rarities
83c7536 @mikeabdullah +isValidEmailAddress:
mikeabdullah authored
53
08c3984 @mikeabdullah KSURLFormatter.
mikeabdullah authored
54
55 #pragma mark Managing Behavior
56
57 // Default is NO. If YES, -stringForObjectValue: will return -[NSFileManager displayName…] for file URLs
58 @property(nonatomic) BOOL useDisplayNameForFileURLs;
59
e2d8176 @mikeabdullah Expose .defaultScheme
mikeabdullah authored
60 // If no scheme is recognisable from the string, this will be substituted. Default is http
61 @property(nonatomic, copy) NSString *defaultScheme;
62
a32a6a0 @mikeabdullah .allowedSchemes feature, where anything outside the list will be convert...
mikeabdullah authored
63 // Default value is nil, which means any scheme is allowed. If a URL is entered that isn't in this list, the formatter substitutes in whatever it considers to be the best match, generally favouring those nearer the start of the array
64 // An empty array is not permitted
65 @property(nonatomic, copy) NSArray *allowedSchemes;
66
3eec08d @mikeabdullah typo
mikeabdullah authored
67 // If the URL's host does not have a top-level domain specified, and this is non-nil, it is substituted in. Default is "com"
08c3984 @mikeabdullah KSURLFormatter.
mikeabdullah authored
68 @property(nonatomic, copy) NSString *fallbackTopLevelDomain;
69
70
71 #pragma mark Conversion
72 - (NSURL *)URLFromString:(NSString *)string; // convenience
32ba7f4 @mikeabdullah .generatesURLStrings property. Defaults to NO.
mikeabdullah authored
73 @property(nonatomic) BOOL generatesURLStrings; // defaults to NO, so that NSURL objects are generated
74
08c3984 @mikeabdullah KSURLFormatter.
mikeabdullah authored
75
76 @end
Something went wrong with that request. Please try again.