Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
NSStringOOExtensions.h
Go to the documentation of this file.
1/*
2
3NSStringOOExtensions.h
4
5Convenience extensions to NSString.
6
7Oolite
8Copyright (C) 2004-2013 Giles C Williams and contributors
9
10This program is free software; you can redistribute it and/or
11modify it under the terms of the GNU General Public License
12as published by the Free Software Foundation; either version 2
13of the License, or (at your option) any later version.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23MA 02110-1301, USA.
24
25*/
26
27#import "OOCocoa.h"
28
29
30@interface NSString (OOExtensions)
31
32/* +stringWithContentsOfUnicodeFile:
33
34 Like +stringWithContentsOfFile:, but biased towards Unicode encodings and
35 cross-system consistency. Specifically:
36 * If the file starts with a UTF-16 BOM, assume UTF-16.
37 * Otherwise, if the file can be interpreted as UTF-8, assume UTF-8.
38 * Otherwise, assume ISO-Latin-1.
39*/
40+ (instancetype) stringWithContentsOfUnicodeFile:(NSString *)path;
41
42
43/* +stringWithUTF16String:
44
45 Takes a NUL-terminated native-endian UTF-16 string.
46*/
47+ (instancetype) stringWithUTF16String:(const unichar *)chars;
48
49
50/* -utf16DataWithBOM:
51 Convert to native-endian UTF-16 data.
52*/
53- (NSData *) utf16DataWithBOM:(BOOL)includeByteOrderMark;
54
55/* - oo_hash
56 Hash function for when we want consistency across platforms and versions.
57 It implements modified djb2 (with xor rather than addition) in terms of
58 UTF-16 code elements.
59*/
60- (uint32_t) oo_hash;
61
62
63/* -stringByTrimmingLeadingCharactersInSet:
64 Strips characters belonging to selected character set from start of string.
65*/
66- (NSString *)stringByTrimmingLeadingCharactersInSet:(NSCharacterSet *)characterSet;
67
68
69/* -stringByTrimmingLeadingWhitespaceAndNewlineCharacters:
70 Strips leading whtiespaces and newline characters from string.
71*/
73
74
75/* -stringByTrimmingTrailingCharactersInSet:
76 Strips characters belonging to selected character set from end of string.
77*/
78- (NSString *)stringByTrimmingTrailingCharactersInSet:(NSCharacterSet *)characterSet;
79
80
81 /* -stringByTrimmingTrailingWhitespaceAndNewlineCharacters:
82 Strips trailing whtiespaces and newline characters from string.
83*/
85
86@end
87
88
89@interface NSMutableString (OOExtensions)
90
91- (void) appendLine:(NSString *)line;
92- (void) appendFormatLine:(NSString *)fmt, ...;
93- (void) appendFormatLine:(NSString *)fmt arguments:(va_list)args;
94
95- (void) deleteCharacterAtIndex:(unsigned long)index;
96
97@end
98
99
100/* OOTabString(count)
101
102 Return a string of <count> tabs.
103*/
104NSString *OOTabString(NSUInteger count);
NSString * OOTabString(NSUInteger count)
unsigned count
NSString * stringByTrimmingTrailingWhitespaceAndNewlineCharacters()
NSString * stringByTrimmingLeadingWhitespaceAndNewlineCharacters()