Oolite
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 "OOFoundation.h"
28
29@interface NSString (OOExtensions)
30
31/* +stringWithContentsOfUnicodeFile:
32
33 Like +stringWithContentsOfFile:, but biased towards Unicode encodings and
34 cross-system consistency. Specifically:
35 * If the file starts with a UTF-16 BOM, assume UTF-16.
36 * Otherwise, if the file can be interpreted as UTF-8, assume UTF-8.
37 * Otherwise, assume ISO-Latin-1.
38*/
39+ (instancetype)stringWithContentsOfUnicodeFile:(NSString*)path;
40
41/* +stringWithUTF16String:
42
43 Takes a NUL-terminated native-endian UTF-16 string.
44*/
45+ (instancetype)stringWithUTF16String:(const unichar*)chars;
46
47/* -utf16DataWithBOM:
48 Convert to native-endian UTF-16 data.
49*/
50- (NSData*)utf16DataWithBOM:(BOOL)includeByteOrderMark;
51
52/* - oo_hash
53 Hash function for when we want consistency across platforms and versions.
54 It implements modified djb2 (with xor rather than addition) in terms of
55 UTF-16 code elements.
56*/
57- (uint32_t)oo_hash;
58
59/* -stringByTrimmingLeadingCharactersInSet:
60 Strips characters belonging to selected character set from start of string.
61*/
62- (NSString*)stringByTrimmingLeadingCharactersInSet:(NSCharacterSet*)characterSet;
63
64/* -stringByTrimmingLeadingWhitespaceAndNewlineCharacters:
65 Strips leading whtiespaces and newline characters from string.
66*/
68
69/* -stringByTrimmingTrailingCharactersInSet:
70 Strips characters belonging to selected character set from end of string.
71*/
72- (NSString*)stringByTrimmingTrailingCharactersInSet:(NSCharacterSet*)characterSet;
73
74/* -stringByTrimmingTrailingWhitespaceAndNewlineCharacters:
75 Strips trailing whtiespaces and newline characters from string.
76*/
78
79@end
80
81@interface NSMutableString (OOExtensions)
82
83- (void)appendLine:(NSString*)line;
84- (void)appendFormatLine:(NSString*)fmt, ...;
85- (void)appendFormatLine:(NSString*)fmt arguments:(va_list)args;
86
87- (void)deleteCharacterAtIndex:(unsigned long)index;
88
89@end
90
91/* OOTabString(count)
92
93 Return a string of <count> tabs.
94*/
95NSString* OOTabString(NSUInteger count);
NSString * OOTabString(NSUInteger count)
unsigned count
NSString * stringByTrimmingTrailingWhitespaceAndNewlineCharacters()
NSString * stringByTrimmingLeadingWhitespaceAndNewlineCharacters()