Monotone-Parent: 8d642918307c4ec207760dac241eca7219d0074a

Monotone-Revision: 2303b51b776f8ba14da83e3a05e92f43b13279cc

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2007-05-25T17:30:24
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau
2007-05-25 17:30:24 +00:00
parent 8430768d24
commit 8b02b7fe51
9 changed files with 216 additions and 0 deletions

View File

@@ -1,3 +1,12 @@
2007-05-25 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* SoObjects/SOGo/NSDictionary+Utilities.[hm]: new extension
module.
* SoObjects/SOGo/NSObject+Utilities.m ([NSObject
-jsonRepresentation]): new interface method meant to be overriden
by the primitive classes.
2007-05-23 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* UI/MailerUI/UIxMailSplashView.m: removed.

View File

@@ -29,6 +29,8 @@
@interface NSArray (SOGoArrayUtilities)
- (NSString *) jsonRepresentation;
- (NSArray *) stringsWithFormat: (NSString *) format;
#ifdef GNUSTEP_BASE_LIBRARY

View File

@@ -58,6 +58,29 @@
withObject: object2];
}
- (NSString *) jsonRepresentation
{
id currentElement;
NSMutableArray *jsonElements;
NSEnumerator *elements;
NSString *representation;
jsonElements = [NSMutableArray new];
elements = [self objectEnumerator];
currentElement = [elements nextObject];
while (currentElement)
{
[jsonElements addObject: [currentElement jsonRepresentation]];
currentElement = [elements nextObject];
}
representation = [NSString stringWithFormat: @"[%@]",
[jsonElements componentsJoinedByString: @", "]];
[jsonElements release];
return representation;
}
@end
@implementation NSMutableArray (SOGoArrayUtilities)

View File

@@ -0,0 +1,36 @@
/* NSDictionary+Utilities.h - this file is part of SOGo
*
* Copyright (C) 2007 Inverse groupe conseil
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef NSDICTIONARY_UTILITIES_H
#define NSDICTIONARY_UTILITIES_H
#import <Foundation/NSDictionary.h>
@class NSString;
@interface NSDictionary (SOGoDictionaryUtilities)
- (NSString *) jsonRepresentation;
@end
#endif /* NSDICTIONARY_UTILITIES_H */

View File

@@ -0,0 +1,55 @@
/* NSDictionary+Utilities.m - this file is part of SOGo
*
* Copyright (C) 2007 Inverse groupe conseil
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#import <Foundation/NSArray.h>
#import <Foundation/NSString.h>
#import "NSObject+Utilities.h"
#import "NSDictionary+Utilities.h"
@implementation NSDictionary (SOGoDictionaryUtilities)
- (NSString *) jsonRepresentation
{
NSMutableArray *values;
NSString *representation, *currentKey, *currentValue, *currentPair;
NSEnumerator *keys;
values = [NSMutableArray new];
keys = [[self allKeys] objectEnumerator];
currentKey = [keys nextObject];
while (currentKey)
{
currentValue = [[self objectForKey: currentKey] jsonRepresentation];
currentPair = [NSString stringWithFormat: @"%@: %@",
[currentKey jsonRepresentation], currentValue];
[values addObject: currentPair];
currentKey = [keys nextObject];
}
representation = [NSString stringWithFormat: @"{%@}",
[values componentsJoinedByString: @", "]];
[values release];
return representation;
}
@end

View File

@@ -0,0 +1,36 @@
/* NSObject+Utilities.h - this file is part of SOGo
*
* Copyright (C) 2007 Inverse groupe conseil
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef NSOBJECT_UTILITIES_H
#define NSOBJECT_UTILITIES_H
#import <Foundation/NSObject.h>
@class NSString;
@interface NSObject (SOGoObjectUtilities)
- (NSString *) jsonRepresentation;
@end
#endif /* NSOBJECT+UTILITIES_H */

View File

@@ -0,0 +1,36 @@
/* NSObject+Utilities.m - this file is part of SOGo
*
* Copyright (C) 2007 Inverse groupe conseil
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#import <Foundation/NSString.h>
#import "NSObject+Utilities.h"
@implementation NSObject (SOGoObjectUtilities)
- (NSString *) jsonRepresentation
{
[self subclassResponsibility: _cmd];
return nil;
}
@end

View File

@@ -40,6 +40,8 @@
- (NSString *) stringByDetectingURLs;
- (NSString *) jsonRepresentation;
#ifndef GNUSTEP_BASE_LIBRARY
- (BOOL) boolValue;
#endif

View File

@@ -184,6 +184,23 @@ static NSMutableCharacterSet *urlAfterEndingChars = nil;
return selfCopy;
}
- (NSString *) jsonRepresentation
{
NSMutableString *representation;
representation = [NSMutableString stringWithString: self];
[representation replaceString: @"\\" withString: @"\\\\"];
[representation replaceString: @"\"" withString: @"\\\""];
[representation replaceString: @"/" withString: @"\\/"];
[representation replaceString: @"\b" withString: @"\\b"];
[representation replaceString: @"\f" withString: @"\\f"];
[representation replaceString: @"\n" withString: @"\\n"];
[representation replaceString: @"\r" withString: @"\\r"];
[representation replaceString: @"\t" withString: @"\\t"];
return [NSString stringWithFormat: @"\"%@\"", representation];
}
#if LIB_FOUNDATION_LIBRARY
- (BOOL) boolValue
{