Oolite
Loading...
Searching...
No Matches
NSString(OldSchoolPropertyListWriting) Category Reference

#include <OldSchoolPropertyListWriting.h>

Inheritance diagram for NSString(OldSchoolPropertyListWriting):
Collaboration diagram for NSString(OldSchoolPropertyListWriting):

Instance Methods

(NSString *) - oldSchoolPListFormatWithIndentation:errorDescription: [implementation]

Detailed Description

Definition at line 39 of file OldSchoolPropertyListWriting.h.

Method Documentation

◆ oldSchoolPListFormatWithIndentation:errorDescription:

- (NSString *) oldSchoolPListFormatWithIndentation: (unsigned) inIndentation
errorDescription: (NSString**) outErrorDescription 
implementation

Reimplemented from <OldSchoolPropertyListWriting>.

Definition at line 30 of file OldSchoolPropertyListWriting.m.

30 :(unsigned)inIndentation errorDescription:(NSString**)outErrorDescription
31{
32 NSCharacterSet* charSet;
33 NSRange foundRange, searchRange;
34 NSString* foundString;
35 NSMutableString* newString;
36 NSUInteger length;
37
38 length = [self length];
39 if (0 != length
40 && [self rangeOfCharacterFromSet:[[NSCharacterSet alphanumericCharacterSet] invertedSet]].location == NSNotFound
41 && ![[NSCharacterSet decimalDigitCharacterSet] longCharacterIsMember:[self characterAtIndex:0]]) {
42 // This is an alphanumeric string whose first character is not a digit
43 return [[self copy] autorelease];
44 } else {
45 charSet = [NSCharacterSet characterSetWithCharactersInString:@"\"\r\n\\"];
46 foundRange = [self rangeOfCharacterFromSet:charSet options:NSLiteralSearch];
47 if (NSNotFound == foundRange.location) {
48 newString = (NSMutableString*)self;
49 } else {
50 // Escape quotes, backslashes and newlines
51 newString = [[[self substringToIndex:foundRange.location] mutableCopy] autorelease];
52
53 for (;;) {
54 // Append escaped character
55 foundString = [self substringWithRange:foundRange];
56 if ([foundString isEqual:@"\""])
57 [newString appendString:@"\\\""];
58 else if ([foundString isEqual:@"\n"])
59 [newString appendString:@"\\\n"];
60 else if ([foundString isEqual:@"\r"])
61 [newString appendString:@"\\\r"];
62 else if ([foundString isEqual:@"\\"])
63 [newString appendString:@"\\\\"];
64 else {
65 [NSException raise:NSInternalInconsistencyException format:@"%s: expected \" or newline, found %@", __PRETTY_FUNCTION__, foundString];
66 }
67
68 // Use rest of string…
69 searchRange.location = foundRange.location + foundRange.length;
70 searchRange.length = length - searchRange.location;
71
72 // …to search for next char needing escaping
73 foundRange = [self rangeOfCharacterFromSet:charSet options:NSLiteralSearch range:searchRange];
74 if (NSNotFound == foundRange.location) {
75 [newString appendString:[self substringWithRange:searchRange]];
76 break;
77 }
78 }
79 }
80
81 return [NSString stringWithFormat:@"\"%@\"", newString];
82 }
83}

The documentation for this category was generated from the following files: