mirror of
https://github.com/gnustep/libs-gsweb.git
synced 2025-02-21 02:41:04 +00:00
* GSWeb.framework/GSWGNUmakefile: o removed NSObject+IVarAccess+PerformSel.* * GSWeb.framework/GSWConstants.m: o fix GSWHTTPHeader_Response_HeaderLineEnd: remove space at the begining o use RCS_ID * GSWeb.framework/Adaptors/common/GSWHTTPResponse.c: o fix status in GSWHTTPResponse_New() * GSWAdaptors/Apache/mod_gsweb.c: o fixes bad returned status o traces * GSWeb.framework/GSWTemplateParserANTLR.m: o removed logs o fixes for warnings o use RCS_ID * GSWeb.framework/GSWApplication.m: o use RCS_ID o added logs o new method to begin rewrite exception handling * GSWeb.framework/GSWRequest.m: o logs o fix in -_getFormValuesFromMultipartFormData to handle more than one value per name o use RCS_ID o -fix bad types in uriElementForKey: * GSWeb.framework/GSWConditional.m: o added asserts o use RCS_ID * GSWeb.framework/GSWHTMLStaticElement.m: o added asserts o clean warnings o use RCS_ID * GSWeb.framework/GSWComponentReference.m: o added asserts o use RCS_ID * GSWeb.framework/GSWActiveImage.m: o added asserts * GSWeb.framework/GSWComponentContent.m: o added asserts o use RCS_ID * GSWeb.framework/GSWForm.m: o added asserts o use RCS_ID * GSWeb.framework/GSWHTMLDynamicElement.m: o added asserts o use RCS_ID * GSWeb.framework/GSWHTMLURLValuedElement.m: o use RCS_ID o added asserts * GSWeb.framework/GSWRepetition.m: o added asserts o use RCS_ID * GSWeb.framework/GSWExtensions.framework/GNUmakefile: o added GSWPageRestorationErrorPage.gswc * GSWeb.framework/GSWFileUploadComponent.m: o use RCS_ID * GSWeb.framework/GSWImage.m: o Don't output nil height/width o fix: get component before using ! o use RCS_ID * GSWeb.framework/GSWElementIDString.m: o in -initWithCoder: retain _string o use RCS_ID * GSWeb.framework/GSWElementIDString.h: o cleaned * config.h.in: o define RCS_ID like in GDL2 * GSWeb.framework/GSWDirectActionRequestHandler.[hm]: o added +additionalRequestPathArrayFromRequest: o enable directAction with additional path components o use RCS_ID * GSWeb.framework/GSWDirectAction.[hm]: o added -additionalRequestPathArray o use RCS_ID * GSWeb.framework/GSWeb.h: o include GSCategories.h * GSWeb.framework/GSWDebug.m: o use RCS_ID * GSWeb.framework/GSWPageDefParserExt.m: o use RCS_ID * GSWeb.framework/GSWPageDefElement.m: o use RCS_ID * GSWeb.framework/GSWDeployedBundle.m: o use RCS_ID * GSWeb.framework/GSWProjectBundle.m: o use RCS_ID * GSWeb.framework/GSWStats.m: o use RCS_ID * GSWeb.framework/GSWBundle.m: o clean warnings o use RCS_ID * GSWeb.framework/GSWTemplateParser.m:: o clean warnings o use RCS_ID * GSWeb.framework/GSWTemplateParserXML.m: o clean warnings o use RCS_ID * GSWeb.framework/GSWComponent.m: o clean warnings o use RCS_ID * GSWeb.framework/GSWDisplayGroup.m: o clean warnings o fix -validateValue:forKey: call o use RCS_ID * GSWeb.framework/GSWHTMLParserExt.m: o use RCS_ID * GSWeb.framework/GSWAssociation.m: o clean warnings o use RCS_ID * GSWeb.framework/GSWResourceManager.m: o clean warnings o use RCS_ID * GSWeb.framework/GSWSession.m: o clean warnings o use RCS_ID * GSWeb.framework/GSWMultiKeyDictionary.m: o use RCS_ID * GSWeb.framework/GSWResponse.m: o clean warnings o use RCS_ID * GSWeb.framework/GSWStatisticsStore.m: o clean warnings * GSWeb.framework/GSWAdaptor.m: o use RCS_ID * GSWeb.framework/GSWGeometricRegion.[hm]: o types change o use RCS_ID * GSWeb.framework/GSWActiveImage.m: o clean warnings o use RCS_ID * GSWeb.framework/GSWBody.m: o use RCS_ID * GSWeb.framework/GSWTextField.m: o use RCS_ID * GSWeb.framework/GSWSubmitButton.m: o clean warnings o use RCS_ID * GSWeb.framework/GSWHTMLBareString.m: o use RCS_ID * GSWeb.framework/GSWHTMLComment.m: o use RCS_ID * GSWeb.framework/GSWApplet.m: o use RCS_ID * GSWeb.framework/GSWBrowser.m: o use RCS_ID * GSWeb.framework/GSWCheckBoxList.m: o use RCS_ID * GSWeb.framework/GSWEmbeddedObject.m: o use RCS_ID * GSWeb.framework/GSWFrame.m: o use RCS_ID * GSWeb.framework/GSWGenericContainer.m: o use RCS_ID * GSWeb.framework/GSWGenericElement.m: o use RCS_ID * GSWeb.framework/GSWHyperlink.m: o use RCS_ID o clean warnings * GSWeb.framework/GSWImageButton.m: o use RCS_ID o clean warnings * GSWeb.framework/GSWJavaScript.m: o use RCS_ID * GSWeb.framework/GSWNestedList.m: o use RCS_ID * GSWeb.framework/GSWParam.m: o use RCS_ID * GSWeb.framework/GSWPasswordField.m: o use RCS_ID * GSWeb.framework/GSWPopUpButton.m: o use RCS_ID * GSWeb.framework/GSWRadioButtonList.m: o use RCS_ID * GSWeb.framework/GSWResetButton.m: o use RCS_ID * GSWeb.framework/GSWSwitchComponent.m: o use RCS_ID * GSWeb.framework/GSWVBScript.m: o use RCS_ID * GSWeb.framework/GSWString.m: o use RCS_ID * GSWeb.framework/GSWText.m: o use RCS_ID * GSWeb.framework/GSWCookie.m: o use RCS_ID * GSWeb.framework/GSWRequestHandler.m: o use RCS_ID * GSWeb.framework/GSWMailDelivery.m: o use RCS_ID * GSWeb.framework/GSWComponentRequestHandler.m: o use RCS_ID o clean warnings * GSWeb.framework/GSWKeyValueAssociation.m: o use RCS_ID * GSWeb.framework/GSWHTMLStaticGroup.m: o use RCS_ID * GSWeb.framework/GSWConstantValueAssociation.m: o use RCS_ID * GSWeb.framework/GSWDynamicURLString.m: o use RCS_ID * GSWeb.framework/GSWBindingNameAssociation.m: o use RCS_ID * GSWeb.framework/GSWBindingNameAssociation.[hm] o clean warnings o use RCS_ID * GSWeb.framework/GSWURLValuedElementData.m: o clean warnings o use RCS_ID * GSWeb.framework/GSWToggle.m: o use RCS_ID * GSWeb.framework/GSWFileUpload.m: o use RCS_ID * GSWeb.framework/GSWResourceURL.m: o use RCS_ID * GSWeb.framework/GSWProcFS.m: o use RCS_ID * GSWeb.framework/GSWActionURL.m: o use RCS_ID * GSWeb.framework/GSWContext.m: o use RCS_ID * GSWeb.framework/GSWDefaultAdaptorThread.m: o use RCS_ID * GSWeb.framework/GSWDynamicElement.m: o use RCS_ID * GSWeb.framework/GSWeb.m: o use RCS_ID * GSWeb.framework/GSWElement.m: o use RCS_ID * GSWeb.framework/GSWResourceRequestHandler.m: o use RCS_ID * GSWeb.framework/GSWServerSessionStore.m: o use RCS_ID * GSWeb.framework/GSWSessionStore.m: o use RCS_ID * GSWeb.framework/GSWSessionTimeOut.m: o use RCS_ID * GSWeb.framework/GSWSessionTimeOutManager.m: o use RCS_ID * GSWeb.framework/GSWTransactionRecord.m: o use RCS_ID * GSWeb.framework/GSWUtils.m: o use RCS_ID * GSWeb.framework/GSWWOCompatibility.m: o use RCS_ID * GSWeb.framework/NSString+HTML.m: o use RCS_ID * GSWeb.framework/NSString+Trimming.m: o use RCS_ID git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@16216 72102866-910b-0410-8b05-ffd578937521
536 lines
19 KiB
Objective-C
536 lines
19 KiB
Objective-C
/** NSString+HTML.m - <title>GSWeb: NSString / HTML</title>
|
||
|
||
Copyright (C) 1999-2003 Free Software Foundation, Inc.
|
||
|
||
Written by: Manuel Guesdon <mguesdon@orange-concept.com>
|
||
Date: Jan 1999
|
||
|
||
$Revision$
|
||
$Date$
|
||
$Id$
|
||
|
||
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$")
|
||
|
||
#include "GSWeb.h"
|
||
|
||
static NSArray* normalChars=nil;
|
||
static NSArray* htmlChars=nil;
|
||
|
||
|
||
/*
|
||
<!ENTITY amp CDATA "&" -- ampersand -->
|
||
<!ENTITY gt CDATA ">" -- greater than -->
|
||
<!ENTITY lt CDATA "<" -- less than -->
|
||
<!ENTITY quot CDATA """ -- double quote -->
|
||
<!ENTITY nbsp CDATA " " -- no-break space -->
|
||
<!ENTITY iexcl CDATA "¡" -- inverted exclamation mark -->
|
||
<!ENTITY cent CDATA "¢" -- cent sign -->
|
||
<!ENTITY pound CDATA "£" -- pound sterling sign -->
|
||
<!ENTITY curren CDATA "¤" -- general currency sign -->
|
||
<!ENTITY yen CDATA "¥" -- yen sign -->
|
||
<!ENTITY brvbar CDATA "¦" -- broken (vertical) bar -->
|
||
<!ENTITY sect CDATA "§" -- section sign -->
|
||
<!ENTITY uml CDATA "¨" -- umlaut (dieresis) -->
|
||
<!ENTITY copy CDATA "©" -- copyright sign -->
|
||
<!ENTITY ordf CDATA "ª" -- ordinal indicator, feminine -->
|
||
<!ENTITY laquo CDATA "«" -- angle quotation mark, left -->
|
||
<!ENTITY not CDATA "¬" -- not sign -->
|
||
<!ENTITY shy CDATA "­" -- soft hyphen -->
|
||
<!ENTITY reg CDATA "®" -- registered sign -->
|
||
<!ENTITY macr CDATA "¯" -- macron -->
|
||
<!ENTITY deg CDATA "°" -- degree sign -->
|
||
<!ENTITY plusmn CDATA "±" -- plus-or-minus sign -->
|
||
<!ENTITY sup2 CDATA "²" -- superscript two -->
|
||
<!ENTITY sup3 CDATA "³" -- superscript three -->
|
||
<!ENTITY acute CDATA "´" -- acute accent -->
|
||
<!ENTITY micro CDATA "µ" -- micro sign -->
|
||
<!ENTITY para CDATA "¶" -- pilcrow (paragraph sign) -->
|
||
<!ENTITY middot CDATA "·" -- middle dot -->
|
||
<!ENTITY cedil CDATA "¸" -- cedilla -->
|
||
<!ENTITY sup1 CDATA "¹" -- superscript one -->
|
||
<!ENTITY ordm CDATA "º" -- ordinal indicator, masculine -->
|
||
<!ENTITY raquo CDATA "»" -- angle quotation mark, right -->
|
||
<!ENTITY frac14 CDATA "¼" -- fraction one-quarter -->
|
||
<!ENTITY frac12 CDATA "½" -- fraction one-half -->
|
||
<!ENTITY frac34 CDATA "¾" -- fraction three-quarters -->
|
||
<!ENTITY iquest CDATA "¿" -- inverted question mark -->
|
||
<!ENTITY Agrave CDATA "À" -- capital A, grave accent -->
|
||
<!ENTITY Aacute CDATA "Á" -- capital A, acute accent -->
|
||
<!ENTITY Acirc CDATA "Â" -- capital A, circumflex accent -->
|
||
<!ENTITY Atilde CDATA "Ã" -- capital A, tilde -->
|
||
<!ENTITY Auml CDATA "Ä" -- capital A, dieresis or umlaut -->
|
||
<!ENTITY Aring CDATA "Å" -- capital A, ring -->
|
||
<!ENTITY AElig CDATA "Æ" -- capital AE diphthong (ligature) -->
|
||
<!ENTITY Ccedil CDATA "Ç" -- capital C, cedilla -->
|
||
<!ENTITY Egrave CDATA "È" -- capital E, grave accent -->
|
||
<!ENTITY Eacute CDATA "É" -- capital E, acute accent -->
|
||
<!ENTITY Ecirc CDATA "Ê" -- capital E, circumflex accent -->
|
||
<!ENTITY Euml CDATA "Ë" -- capital E, dieresis or umlaut -->
|
||
<!ENTITY Igrave CDATA "Ì" -- capital I, grave accent -->
|
||
<!ENTITY Iacute CDATA "Í" -- capital I, acute accent -->
|
||
<!ENTITY Icirc CDATA "Î" -- capital I, circumflex accent -->
|
||
<!ENTITY Iuml CDATA "Ï" -- capital I, dieresis or umlaut -->
|
||
<!ENTITY ETH CDATA "Ð" -- capital Eth, Icelandic -->
|
||
<!ENTITY Ntilde CDATA "Ñ" -- capital N, tilde -->
|
||
<!ENTITY Ograve CDATA "Ò" -- capital O, grave accent -->
|
||
<!ENTITY Oacute CDATA "Ó" -- capital O, acute accent -->
|
||
<!ENTITY Ocirc CDATA "Ô" -- capital O, circumflex accent -->
|
||
<!ENTITY Otilde CDATA "Õ" -- capital O, tilde -->
|
||
<!ENTITY Ouml CDATA "Ö" -- capital O, dieresis or umlaut -->
|
||
<!ENTITY times CDATA "×" -- multiply sign -->
|
||
<!ENTITY Oslash CDATA "Ø" -- capital O, slash -->
|
||
<!ENTITY Ugrave CDATA "Ù" -- capital U, grave accent -->
|
||
<!ENTITY Uacute CDATA "Ú" -- capital U, acute accent -->
|
||
<!ENTITY Ucirc CDATA "Û" -- capital U, circumflex accent -->
|
||
<!ENTITY Uuml CDATA "Ü" -- capital U, dieresis or umlaut -->
|
||
<!ENTITY Yacute CDATA "Ý" -- capital Y, acute accent -->
|
||
<!ENTITY THORN CDATA "Þ" -- capital Thorn, Icelandic -->
|
||
<!ENTITY szlig CDATA "ß" -- small sharp s, German (sz ligature) -->
|
||
<!ENTITY agrave CDATA "à" -- small a, grave accent -->
|
||
<!ENTITY aacute CDATA "á" -- small a, acute accent -->
|
||
<!ENTITY acirc CDATA "â" -- small a, circumflex accent -->
|
||
<!ENTITY atilde CDATA "ã" -- small a, tilde -->
|
||
<!ENTITY auml CDATA "ä" -- small a, dieresis or umlaut -->
|
||
<!ENTITY aring CDATA "å" -- small a, ring -->
|
||
<!ENTITY aelig CDATA "æ" -- small ae diphthong (ligature) -->
|
||
<!ENTITY ccedil CDATA "ç" -- small c, cedilla -->
|
||
<!ENTITY egrave CDATA "è" -- small e, grave accent -->
|
||
<!ENTITY eacute CDATA "é" -- small e, acute accent -->
|
||
<!ENTITY ecirc CDATA "ê" -- small e, circumflex accent -->
|
||
<!ENTITY euml CDATA "ë" -- small e, dieresis or umlaut -->
|
||
<!ENTITY igrave CDATA "ì" -- small i, grave accent -->
|
||
<!ENTITY iacute CDATA "í" -- small i, acute accent -->
|
||
<!ENTITY icirc CDATA "î" -- small i, circumflex accent -->
|
||
<!ENTITY iuml CDATA "ï" -- small i, dieresis or umlaut -->
|
||
<!ENTITY eth CDATA "ð" -- small eth, Icelandic -->
|
||
<!ENTITY ntilde CDATA "ñ" -- small n, tilde -->
|
||
<!ENTITY ograve CDATA "ò" -- small o, grave accent -->
|
||
<!ENTITY oacute CDATA "ó" -- small o, acute accent -->
|
||
<!ENTITY ocirc CDATA "ô" -- small o, circumflex accent -->
|
||
<!ENTITY otilde CDATA "õ" -- small o, tilde -->
|
||
<!ENTITY ouml CDATA "ö" -- small o, dieresis or umlaut -->
|
||
<!ENTITY divide CDATA "÷" -- divide sign -->
|
||
<!ENTITY oslash CDATA "ø" -- small o, slash -->
|
||
<!ENTITY ugrave CDATA "ù" -- small u, grave accent -->
|
||
<!ENTITY uacute CDATA "ú" -- small u, acute accent -->
|
||
<!ENTITY ucirc CDATA "û" -- small u, circumflex accent -->
|
||
<!ENTITY uuml CDATA "ü" -- small u, dieresis or umlaut -->
|
||
<!ENTITY yacute CDATA "ý" -- small y, acute accent -->
|
||
<!ENTITY thorn CDATA "þ" -- small thorn, Icelandic -->
|
||
<!ENTITY yuml CDATA "ÿ" -- small y, dieresis or umlaut -->
|
||
*/
|
||
|
||
|
||
void initHtmlChars()
|
||
{
|
||
if (!normalChars)
|
||
{
|
||
normalChars=[[NSArray arrayWithObjects:
|
||
@"&",
|
||
@">",
|
||
@"<",
|
||
@"\"",
|
||
@"<EFBFBD>",
|
||
@"|",
|
||
@"<EFBFBD>",
|
||
@"<EFBFBD>",
|
||
@"<EFBFBD>",
|
||
@"<EFBFBD>",
|
||
@"<EFBFBD>",
|
||
@"<EFBFBD>",
|
||
@"<EFBFBD>",
|
||
@"<EFBFBD>",
|
||
@"<EFBFBD>",
|
||
@"<EFBFBD>",
|
||
@"<EFBFBD>",
|
||
@"<EFBFBD>",
|
||
@"<EFBFBD>",
|
||
@"<EFBFBD>",
|
||
@"<EFBFBD>",
|
||
nil
|
||
] retain];
|
||
};
|
||
if (!htmlChars)
|
||
{
|
||
htmlChars=[[NSArray arrayWithObjects:
|
||
@"&",
|
||
@">",
|
||
@"<",
|
||
@""",
|
||
@"£",
|
||
@"¦",
|
||
@"°",
|
||
@"é",
|
||
@"ç",
|
||
@"à",
|
||
@"â",
|
||
@"ã",
|
||
@"è",
|
||
@"ê",
|
||
@"ì",
|
||
@"î",
|
||
@"ñ",
|
||
@"ô",
|
||
@"õ",
|
||
@"ù",
|
||
@"û",
|
||
nil
|
||
] retain];
|
||
};
|
||
};
|
||
|
||
//====================================================================
|
||
@implementation NSString (HTMLString)
|
||
|
||
//--------------------------------------------------------------------
|
||
-(NSString*)htmlPlus2Space
|
||
{
|
||
return [self stringByReplacingString:@"+"
|
||
withString:@" "];
|
||
};
|
||
|
||
//--------------------------------------------------------------------
|
||
// void decodeURL(String &str)
|
||
// Convert the given URL string to a normal string. This means that
|
||
// all escaped characters are converted to their normal values. The
|
||
// escape character is '%' and is followed by 2 hex digits
|
||
// representing the octet.
|
||
//
|
||
-(NSString*)decodeURL
|
||
{
|
||
//TODO speed
|
||
unichar* unichars=NULL;
|
||
unichar uniChar=0;
|
||
NSString* voidString=nil;
|
||
NSString* temp=nil;
|
||
const char* p=NULL;
|
||
int uniCharsIndex=0;
|
||
NSDebugMLLog(@"low",@"self=%@",self);
|
||
voidString=[self htmlPlus2Space];
|
||
NSDebugMLLog(@"low",@"voidString=%@",voidString);
|
||
unichars=GSAutoreleasedBuffer(sizeof(unichar)*([voidString length]+1));
|
||
NSDebugMLLog(@"low",@"[voidString cString]=%s",[voidString cString]);
|
||
for (p=[voidString cString];p && *p;p++)
|
||
{
|
||
if (*p == '%')
|
||
{
|
||
//
|
||
// 2 hex digits follow...
|
||
//
|
||
int i=0;
|
||
uniChar=0;
|
||
for (i=0;p[1] && i<2;i++)
|
||
{
|
||
p++;
|
||
NSDebugMLLog(@"low",@"*p=%c %u",(char)*p,(unsigned int)*p);
|
||
uniChar <<= 4;
|
||
NSDebugMLLog(@"low",@"uniChar=%x",(unsigned int)uniChar);
|
||
if (isdigit(*p))
|
||
uniChar+=*p-'0';
|
||
else
|
||
uniChar+=toupper(*p)-'A'+10;
|
||
NSDebugMLLog(@"low",@"uniChar=%x",(unsigned int)uniChar);
|
||
};
|
||
}
|
||
else
|
||
uniChar=(unsigned char)*p;
|
||
unichars[uniCharsIndex]=uniChar;
|
||
uniCharsIndex++;
|
||
};
|
||
temp=[NSString stringWithCharacters:unichars
|
||
length:uniCharsIndex];
|
||
NSDebugMLLog(@"low",@"temp=%@",temp);
|
||
NSDebugMLLog(@"low",@"temp data=%@",[temp dataUsingEncoding:NSISOLatin1StringEncoding]);
|
||
return temp;
|
||
};
|
||
|
||
|
||
//--------------------------------------------------------------------
|
||
// void encodeURL(String &str, char *valid)
|
||
// Convert a normal string to a URL 'safe' string. This means that
|
||
// all characters not explicitly mentioned in the URL BNF will be
|
||
// escaped. The escape character is '%' and is followed by 2 hex
|
||
// digits representing the octet.
|
||
//
|
||
-(NSString*)encodeURL
|
||
{
|
||
return [self encodeURLWithValid:nil];
|
||
};
|
||
|
||
//--------------------------------------------------------------------
|
||
-(NSString*)encodeURLWithValid:(NSString*)validString
|
||
{
|
||
NSMutableString* temp=[NSMutableString stringWithCapacity:[self length]];
|
||
const char* p=NULL;
|
||
const char* valid=[validString cString];
|
||
static char *digits = "0123456789ABCDEF";
|
||
for (p =[self cString]; p && *p; p++)
|
||
{
|
||
if (isdigit(*p) || isalpha(*p) || (valid && strchr(valid, *p)))
|
||
[temp appendFormat:@"%c",*p];
|
||
else
|
||
[temp appendFormat:@"%%%c%c",digits[(*p >> 4) & 0x0f],digits[*p & 0x0f]];
|
||
};
|
||
return [NSString stringWithString:temp];
|
||
}
|
||
|
||
//--------------------------------------------------------------------
|
||
-(NSDictionary*)dictionaryQueryString
|
||
{
|
||
return [self dictionaryWithSep1:@"&"
|
||
withSep2:@"="
|
||
withOptionUnescape:YES
|
||
forceArray:YES];
|
||
};
|
||
|
||
//--------------------------------------------------------------------
|
||
-(NSDictionary*)dictionaryWithSep1:(NSString*)sep1
|
||
withSep2:(NSString*)sep2
|
||
withOptionUnescape:(BOOL)unescape
|
||
{
|
||
return [self dictionaryWithSep1:sep1
|
||
withSep2:sep2
|
||
withOptionUnescape:unescape
|
||
forceArray:NO];
|
||
};
|
||
//--------------------------------------------------------------------
|
||
-(NSDictionary*)dictionaryWithSep1:(NSString*)sep1
|
||
withSep2:(NSString*)sep2
|
||
withOptionUnescape:(BOOL)unescape
|
||
forceArray:(BOOL)forceArray// Put value in array even if there's only one value
|
||
{
|
||
NSMutableDictionary* pDico=nil;
|
||
if ([self length]>0)
|
||
{
|
||
NSArray* listItems = [self componentsSeparatedByString:sep1];
|
||
int iCount=0;
|
||
pDico=(NSMutableDictionary*)[NSMutableDictionary dictionary];
|
||
for(iCount=0;iCount<[listItems count];iCount++)
|
||
{
|
||
if ([[listItems objectAtIndex:iCount] length]>0)
|
||
{
|
||
NSArray* listParam = [[listItems objectAtIndex:iCount] componentsSeparatedByString:sep2];
|
||
id key=nil;
|
||
id value=nil;
|
||
if ([listParam count]==1)
|
||
{
|
||
key=[listParam objectAtIndex:0];
|
||
if (unescape)
|
||
key=[key decodeURL];
|
||
}
|
||
else if ([listParam count]==2)
|
||
{
|
||
key=[listParam objectAtIndex:0];
|
||
value=[listParam objectAtIndex:1];
|
||
if (unescape)
|
||
{
|
||
key=[key decodeURL];
|
||
value=[value decodeURL];
|
||
};
|
||
};
|
||
if (key)
|
||
{
|
||
id newValue=nil;
|
||
id prevValue=[pDico objectForKey:key];
|
||
if (!value)
|
||
value=[NSString string];
|
||
if (prevValue)
|
||
{
|
||
if (!forceArray || [prevValue isKindOfClass:[NSArray class]])
|
||
newValue=[prevValue arrayByAddingObject:value];
|
||
else
|
||
newValue=[NSArray arrayWithObjects:prevValue,value,nil];
|
||
}
|
||
else
|
||
{
|
||
if (forceArray)
|
||
newValue=[NSArray arrayWithObject:value];
|
||
else
|
||
newValue=value;
|
||
};
|
||
[pDico setObject:newValue
|
||
forKey: key];
|
||
};
|
||
};
|
||
};
|
||
pDico=[NSDictionary dictionaryWithDictionary:pDico];
|
||
};
|
||
return pDico;
|
||
};
|
||
|
||
//--------------------------------------------------------------------
|
||
-(BOOL)ismapCoordx:(int*)x
|
||
y:(int*)y
|
||
{
|
||
BOOL ok=NO;
|
||
NSScanner* scanner=[NSScanner scannerWithString:self];
|
||
if ([scanner scanInt:x])
|
||
{
|
||
if (x)
|
||
{
|
||
NSDebugMLLog(@"low",@"x=%d",*x);
|
||
};
|
||
if ([scanner scanString:@","
|
||
intoString:NULL])
|
||
{
|
||
if ([scanner scanInt:y])
|
||
{
|
||
if (y)
|
||
{
|
||
NSDebugMLLog(@"low",@"y=%d",*y);
|
||
};
|
||
NSDebugMLLog(@"low",@"[scanner isAtEnd]=%d",(int)[scanner isAtEnd]);
|
||
if ([scanner isAtEnd])
|
||
{
|
||
ok=YES;
|
||
};
|
||
};
|
||
};
|
||
};
|
||
if (!ok)
|
||
{
|
||
if (x)
|
||
*x=INT_MAX;
|
||
if (y)
|
||
*y=INT_MAX;
|
||
};
|
||
return ok;
|
||
};
|
||
|
||
//--------------------------------------------------------------------
|
||
-(NSString*)stringByEscapingHTMLString
|
||
{
|
||
//TODO speed
|
||
NSString* str=nil;
|
||
if ([self length]>0)
|
||
{
|
||
NSMutableString* tmp=[self mutableCopy];
|
||
[tmp replaceString:@"&" withString:@"&"];
|
||
[tmp replaceString:@"\"" withString:@"""];
|
||
[tmp replaceString:@"<" withString:@"<"];
|
||
[tmp replaceString:@">" withString:@">"];
|
||
str = AUTORELEASE([tmp copy]);
|
||
RELEASE(tmp);
|
||
};
|
||
return str;
|
||
};
|
||
|
||
//--------------------------------------------------------------------
|
||
-(NSString*)stringByEscapingHTMLAttributeValue
|
||
{
|
||
//TODO speed
|
||
NSString* str=nil;
|
||
if ([self length]>0)
|
||
{
|
||
NSMutableString* tmp=[self mutableCopy];
|
||
[tmp replaceString:@"&" withString:@"&"];
|
||
[tmp replaceString:@"\"" withString:@"""];
|
||
[tmp replaceString:@"<" withString:@"<"];
|
||
[tmp replaceString:@">" withString:@">"];
|
||
[tmp replaceString:@"\t" withString:@"	"];
|
||
[tmp replaceString:@"\n" withString:@" "];
|
||
[tmp replaceString:@"\r" withString:@" "];
|
||
str = AUTORELEASE([tmp copy]);
|
||
RELEASE(tmp);
|
||
};
|
||
return str;
|
||
};
|
||
|
||
//--------------------------------------------------------------------
|
||
-(NSString*)stringByConvertingToHTMLEntities
|
||
{
|
||
//TODO speed
|
||
NSString* str=nil;
|
||
if ([self length]>0)
|
||
{
|
||
int i=0;
|
||
NSMutableString* tmp=[self mutableCopy];
|
||
if (!normalChars)
|
||
initHtmlChars();
|
||
for(i=0;i<[normalChars count];i++)
|
||
{
|
||
[tmp replaceString:[normalChars objectAtIndex:i]
|
||
withString:[htmlChars objectAtIndex:i]];
|
||
};
|
||
str = AUTORELEASE([tmp copy]);
|
||
RELEASE(tmp);
|
||
};
|
||
return str;
|
||
};
|
||
|
||
//--------------------------------------------------------------------
|
||
-(NSString*)stringByConvertingFromHTMLEntities
|
||
{
|
||
NSString* str=nil;
|
||
if ([self length]>0)
|
||
{
|
||
int i=0;
|
||
NSMutableString* tmp=[self mutableCopy];
|
||
if (!normalChars)
|
||
initHtmlChars();
|
||
for(i=0;i<[normalChars count];i++)
|
||
{
|
||
[tmp replaceString:[htmlChars objectAtIndex:i]
|
||
withString:[normalChars objectAtIndex:i]];
|
||
};
|
||
str = AUTORELEASE([tmp copy]);
|
||
RELEASE(tmp);
|
||
};
|
||
return str;
|
||
};
|
||
|
||
//--------------------------------------------------------------------
|
||
-(NSString*)stringByConvertingToHTML
|
||
{
|
||
NSString* str=nil;
|
||
if ([self length]>0)
|
||
{
|
||
//TODO speed
|
||
NSMutableString* tmp=[[self stringByConvertingToHTMLEntities] mutableCopy];
|
||
[tmp replaceString:@"\r\n" withString:@"<BR>"];
|
||
[tmp replaceString:@"\r" withString:@"<BR>"];
|
||
[tmp replaceString:@"\n" withString:@"<BR>"];
|
||
str = AUTORELEASE([tmp copy]);
|
||
RELEASE(tmp);
|
||
};
|
||
return str;
|
||
};
|
||
|
||
//--------------------------------------------------------------------
|
||
-(NSString*)stringByConvertingFromHTML
|
||
{
|
||
NSString* str=nil;
|
||
if ([self length]>0)
|
||
{
|
||
//TODO speed
|
||
NSMutableString* tmp=[[self stringByConvertingFromHTMLEntities] mutableCopy];
|
||
[tmp replaceString:@"<BR>" withString:@"\n"];
|
||
str = AUTORELEASE([tmp copy]);
|
||
RELEASE(tmp);
|
||
};
|
||
return str;
|
||
};
|
||
|
||
@end
|
||
|