This repository was archived by the owner on Sep 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathGDataUtilities.h
112 lines (88 loc) · 3.63 KB
/
GDataUtilities.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* Copyright (c) 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <Foundation/Foundation.h>
#ifndef SKIP_GDATA_DEFINES
#import "GDataDefines.h"
#endif
// helper functions for implementing isEqual:
BOOL AreEqualOrBothNil(id obj1, id obj2);
BOOL AreBoolsEqual(BOOL b1, BOOL b2);
@interface GDataUtilities : NSObject
// utility for removing non-whitespace control characters
+ (NSString *)stringWithControlsFilteredForString:(NSString *)str;
// utility for converting NSNumber to/from string, including inf/-inf
//
// an empty string returns a nil NSNumber
+ (NSNumber *)doubleNumberOrInfForString:(NSString *)str;
//
// copy method helpers
//
// array with copies of the objects in the source array (1-deep)
+ (NSArray *)arrayWithCopiesOfObjectsInArray:(NSArray *)source;
+ (NSMutableArray *)mutableArrayWithCopiesOfObjectsInArray:(NSArray *)source;
// dicionary with copies of the objects in the source dictionary (1-deep)
+ (NSDictionary *)dictionaryWithCopiesOfObjectsInDictionary:(NSDictionary *)source;
+ (NSMutableDictionary *)mutableDictionaryWithCopiesOfObjectsInDictionary:(NSDictionary *)source;
// dictionary with 1-deep copies of the arrays which are the source dictionary's
// values (2-deep)
+ (NSDictionary *)dictionaryWithCopiesOfArraysInDictionary:(NSDictionary *)source;
+ (NSMutableDictionary *)mutableDictionaryWithCopiesOfArraysInDictionary:(NSDictionary *)source;
//
// string encoding
//
// URL encoding, different for parts of URLs and parts of URL parameters
//
// +stringByURLEncodingString just makes a string legal for a URL
//
// +stringByURLEncodingForURI also encodes some characters that are legal in
// URLs but should not be used in URIs,
// per http://bitworking.org/projects/atom/rfc5023.html#rfc.section.9.7
//
// +stringByURLEncodingStringParameter is like +stringByURLEncodingForURI but
// replaces space characters with + characters rather than percent-escaping them
//
+ (NSString *)stringByURLEncodingString:(NSString *)str;
+ (NSString *)stringByURLEncodingForURI:(NSString *)str;
+ (NSString *)stringByURLEncodingStringParameter:(NSString *)str;
// percent-encoded UTF-8
+ (NSString *)stringByPercentEncodingUTF8ForString:(NSString *)str;
//
// key-value coding searches in an array
//
// utilities to get from an array objects having a known value (or nil)
// at a keyPath
+ (NSArray *)objectsFromArray:(NSArray *)sourceArray
withValue:(id)desiredValue
forKeyPath:(NSString *)keyPath;
+ (id)firstObjectFromArray:(NSArray *)sourceArray
withValue:(id)desiredValue
forKeyPath:(NSString *)keyPath;
//
// version helpers
//
+ (NSComparisonResult)compareVersion:(NSString *)ver1 toVersion:(NSString *)ver2;
//
// response string helpers
//
// convert responses of the form "a=foo \n b=bar" to a dictionary
+ (NSDictionary *)dictionaryWithResponseString:(NSString *)str;
+ (NSDictionary *)dictionaryWithResponseData:(NSData *)data;
//
// file type helpers
//
// utility routine to convert a file name to the file's MIME type
+ (NSString *)MIMETypeForFileAtPath:(NSString *)filename
defaultMIMEType:(NSString *)defaultType;
@end