mirror of
https://github.com/gnustep/libs-gsweb.git
synced 2025-04-23 07:20:55 +00:00
added
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@25032 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3f43e4a9c3
commit
08d948d1dd
2 changed files with 140 additions and 0 deletions
41
GSWeb.framework/NSDictionary+HTML.h
Normal file
41
GSWeb.framework/NSDictionary+HTML.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/** NSDictionary+HTML.h - <title>GSWeb: NSString / HTML</title>
|
||||
|
||||
Copyright (C) 2005-2006 Free Software Foundation, Inc.
|
||||
|
||||
Written by: David Wetzel <dave@turbocat.de> http://www.turbocat.de/
|
||||
Date: Jan 2006
|
||||
|
||||
$Revision: 1.5 $
|
||||
$Date: 2005/03/10 16:10:03 $
|
||||
|
||||
This file is part of the GNUstep Web Library.
|
||||
|
||||
<license>
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
</license>
|
||||
**/
|
||||
|
||||
// $Id: NSString+HTML.h,v 1.5 2005/03/10 16:10:03 dwetzel Exp $
|
||||
|
||||
#ifndef _NSDictionary_HTML_h__
|
||||
#define _NSDictionary_HTML_h__
|
||||
|
||||
|
||||
@interface NSDictionary (HTML)
|
||||
- (NSString*) encodeAsCGIFormValues;
|
||||
|
||||
@end
|
||||
|
||||
#endif //_NSDictionary_HTML_h__
|
99
GSWeb.framework/NSDictionary+HTML.m
Normal file
99
GSWeb.framework/NSDictionary+HTML.m
Normal file
|
@ -0,0 +1,99 @@
|
|||
/** NSDictionary+HTML.m - <title>GSWeb: NSDictionary+HTML</title>
|
||||
|
||||
Copyright (C) 2005-2006 Free Software Foundation, Inc.
|
||||
|
||||
Written by: David Wetzel <dave@turbocat.de>
|
||||
Date: Jan 2006
|
||||
|
||||
$Revision: 1.17 $
|
||||
$Date: 2004/12/31 14:33:16 $
|
||||
|
||||
This file is part of the GNUstep Web Library.
|
||||
|
||||
<license>
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
</license>
|
||||
**/
|
||||
|
||||
|
||||
#include "config.h"
|
||||
|
||||
RCS_ID("$Id: GSWDynamicGroup.m,v 1.17 2004/12/31 14:33:16 mguesdon Exp $")
|
||||
|
||||
#include "GSWeb.h"
|
||||
|
||||
|
||||
//====================================================================
|
||||
|
||||
static Class NSDictionaryClass = Nil;
|
||||
static Class NSArrayClass = Nil;
|
||||
|
||||
|
||||
@implementation NSDictionary (GSWHTML)
|
||||
|
||||
/* mybe we need that later.
|
||||
static inline void initClasses(void)
|
||||
{
|
||||
if (NSDictionaryClass == Nil) {
|
||||
NSDictionaryClass = [NSDictionary class];
|
||||
NSArrayClass = [NSArray class];
|
||||
}
|
||||
}
|
||||
*/
|
||||
static NSString* _encodeObjectAndKeyUsingEncoding(id obj, id key, NSStringEncoding encoding)
|
||||
{
|
||||
NSString * codeStr = nil;
|
||||
NSString * strVal = nil;
|
||||
|
||||
if (obj != nil) {
|
||||
strVal = obj; // stringValue??
|
||||
codeStr = [strVal encodeURL]; // give encoding to method?
|
||||
codeStr = [key stringByAppendingFormat:@"=%@", codeStr];
|
||||
}
|
||||
|
||||
return codeStr;
|
||||
}
|
||||
|
||||
static NSMutableArray* _encodeAsCGIFormValuesInDictionaryUsingEncoding(NSDictionary* dict, NSStringEncoding encoding)
|
||||
{
|
||||
NSMutableArray * array = [NSMutableArray arrayWithCapacity:[dict count]];
|
||||
NSEnumerator * enumer = [dict keyEnumerator];
|
||||
NSString * key = nil;
|
||||
NSString * subCodeStr = nil;
|
||||
NSString * codeStr = nil;
|
||||
id obj = nil;
|
||||
|
||||
while (key = [enumer nextObject]) {
|
||||
obj = [dict objectForKey:key];
|
||||
codeStr = [key encodeURL]; // give encoding to method?
|
||||
if (subCodeStr = _encodeObjectAndKeyUsingEncoding(obj, codeStr, encoding)) {
|
||||
[array addObject: subCodeStr];
|
||||
}
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
|
||||
// encodeAsCGIFormValues
|
||||
- (NSString*) encodeAsCGIFormValues
|
||||
{
|
||||
// todo set urlEncoding from the WOURLEncoding key in the dict?
|
||||
NSStringEncoding urlEncoding = NSUTF8StringEncoding;
|
||||
NSMutableArray * array = _encodeAsCGIFormValuesInDictionaryUsingEncoding(self, urlEncoding);
|
||||
return [array componentsJoinedByString:@"&"];
|
||||
}
|
||||
|
||||
@end
|
Loading…
Reference in a new issue