Line data Source code
1 0 : /* 2 : 3 : NSStringOOExtensions.h 4 : 5 : Convenience extensions to NSString. 6 : 7 : Oolite 8 : Copyright (C) 2004-2013 Giles C Williams and contributors 9 : 10 : This program is free software; you can redistribute it and/or 11 : modify it under the terms of the GNU General Public License 12 : as published by the Free Software Foundation; either version 2 13 : of the License, or (at your option) any later version. 14 : 15 : This program is distributed in the hope that it will be useful, 16 : but WITHOUT ANY WARRANTY; without even the implied warranty of 17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 : GNU General Public License for more details. 19 : 20 : You should have received a copy of the GNU General Public License 21 : along with this program; if not, write to the Free Software 22 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 23 : MA 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 0 : + (instancetype) stringWithContentsOfUnicodeFile:(NSString *)path; 41 : 42 : 43 : /* +stringWithUTF16String: 44 : 45 : Takes a NUL-terminated native-endian UTF-16 string. 46 : */ 47 0 : + (instancetype) stringWithUTF16String:(const unichar *)chars; 48 : 49 : 50 : /* -utf16DataWithBOM: 51 : Convert to native-endian UTF-16 data. 52 : */ 53 0 : - (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 0 : - (uint32_t) oo_hash; 61 : 62 : 63 : /* -stringByTrimmingLeadingCharactersInSet: 64 : Strips characters belonging to selected character set from start of string. 65 : */ 66 0 : - (NSString *)stringByTrimmingLeadingCharactersInSet:(NSCharacterSet *)characterSet; 67 : 68 : 69 : /* -stringByTrimmingLeadingWhitespaceAndNewlineCharacters: 70 : Strips leading whtiespaces and newline characters from string. 71 : */ 72 0 : - (NSString *)stringByTrimmingLeadingWhitespaceAndNewlineCharacters; 73 : 74 : 75 : /* -stringByTrimmingTrailingCharactersInSet: 76 : Strips characters belonging to selected character set from end of string. 77 : */ 78 0 : - (NSString *)stringByTrimmingTrailingCharactersInSet:(NSCharacterSet *)characterSet; 79 : 80 : 81 : /* -stringByTrimmingTrailingWhitespaceAndNewlineCharacters: 82 : Strips trailing whtiespaces and newline characters from string. 83 : */ 84 0 : - (NSString *)stringByTrimmingTrailingWhitespaceAndNewlineCharacters; 85 : 86 : @end 87 : 88 : 89 : @interface NSMutableString (OOExtensions) 90 : 91 0 : - (void) appendLine:(NSString *)line; 92 0 : - (void) appendFormatLine:(NSString *)fmt, ...; 93 0 : - (void) appendFormatLine:(NSString *)fmt arguments:(va_list)args; 94 : 95 0 : - (void) deleteCharacterAtIndex:(unsigned long)index; 96 : 97 : @end 98 : 99 : 100 : /* OOTabString(count) 101 : 102 : Return a string of <count> tabs. 103 : */ 104 0 : NSString *OOTabString(NSUInteger count);