Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix over-escaping of "\" in JSON format

  • Loading branch information...
commit d48b8a781fbcae33e93ef6bc48764d2a6248691f 1 parent a884ef5
Pascal Pfiffner authored
13 FileExport/PPStringFormat.m
View
@@ -422,21 +422,18 @@ + (PPStringFormat *) jsonFormat
myself.exportHeaders = NO;
// Setup CSV properties
- NSArray *keyPairs = [PPStringFormatTransformPair transformPairsFromTo:
+ NSArray *transformPairs = [PPStringFormatTransformPair transformPairsFromTo:
+ @"\\", @"\\\\",
@"\"", @"\\\"",
@"'", @"\\'",
- @"\\", @"\\\\", nil];
- NSArray *valuePairs = [PPStringFormatTransformPair transformPairsFromTo:
- @"\"", @"\\\"",
- @"'", @"\\'",
- @"\\", @"\\\\", nil];
+ nil];
PPStringFormatEntity *valueEntity = [PPStringFormatEntity formatEntity];
valueEntity.separator = @",\n\t\t";
valueEntity.stringFormat = @"\"$key\":\"$value\"";
valueEntity.numberFormat = @"\"$key\":$value";
- valueEntity.keyTransforms = keyPairs;
- valueEntity.valueTransforms = valuePairs;
+ valueEntity.keyTransforms = transformPairs;
+ valueEntity.valueTransforms = transformPairs;
PPStringFormatRow *row = [PPStringFormatRow formatRow];
row.format = @"\t{\n\t\t@values\n\t},\n";
5 FileExport/PPStringFormatTransformPair.h
View
@@ -13,10 +13,7 @@
/**
* A class that transforms occurrences of "from" to "to" in a mutable string.
*/
-@interface PPStringFormatTransformPair : NSObject <NSCoding> {
- NSString *from;
- NSString *to;
-}
+@interface PPStringFormatTransformPair : NSObject <NSCoding, NSCopying>
@property (nonatomic, retain) NSString *from;
@property (nonatomic, retain) NSString *to;
23 FileExport/PPStringFormatTransformPair.m
View
@@ -13,9 +13,6 @@
@implementation PPStringFormatTransformPair
-@synthesize from;
-@synthesize to;
-
+ (NSArray *) transformPairsFromTo:(NSString *)first, ...
{
@@ -81,8 +78,20 @@ - (id) initWithCoder:(NSCoder *)aDecoder
- (void) encodeWithCoder:(NSCoder *)aCoder
{
- [aCoder encodeObject:from forKey:@"from"];
- [aCoder encodeObject:to forKey:@"to"];
+ [aCoder encodeObject:_from forKey:@"from"];
+ [aCoder encodeObject:_to forKey:@"to"];
+}
+
+
+
+#pragma mark - NSCopying
+- (id) copyWithZone:(NSZone *)zone
+{
+ PPStringFormatTransformPair *copy = [[self class] new];
+ copy.from = _from;
+ copy.to = _to;
+
+ return copy;
}
@@ -91,7 +100,7 @@ - (void) encodeWithCoder:(NSCoder *)aCoder
- (NSMutableString *) transform:(NSMutableString *)string
{
if (nil != string) {
- [string replaceOccurrencesOfString:from withString:to options:0 range:NSMakeRange(0, [string length])];
+ [string replaceOccurrencesOfString:_from withString:_to options:0 range:NSMakeRange(0, [string length])];
}
return string;
}
@@ -101,7 +110,7 @@ - (NSMutableString *) transform:(NSMutableString *)string
#pragma mark - Utilities
- (NSString *) description
{
- return [NSString stringWithFormat:@"%@ <%p> from '%@' to '%@'", NSStringFromClass([self class]), self, from, to];
+ return [NSString stringWithFormat:@"%@ <%p> from '%@' to '%@'", NSStringFromClass([self class]), self, _from, _to];
}
Please sign in to comment.
Something went wrong with that request. Please try again.