Oolite 1.91.0.7644-241112-7f5034b
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]
 
- Instance Methods inherited from <OldSchoolPropertyListWriting>

Detailed Description

Definition at line 43 of file OldSchoolPropertyListWriting.h.

Method Documentation

◆ oldSchoolPListFormatWithIndentation:errorDescription:

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

Reimplemented from <OldSchoolPropertyListWriting>.

Definition at line 325 of file OldSchoolPropertyListWriting.m.

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

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