From: znek Date: Wed, 21 Feb 2007 08:36:13 +0000 (+0000) Subject: Fixed bugs in STXSaxDriver. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79fd75bcae1021d23c71b5f8530bd5a762cc85d3;p=sope Fixed bugs in STXSaxDriver. git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1438 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-xml/STXSaxDriver/ChangeLog b/sope-xml/STXSaxDriver/ChangeLog index 9ea4e506..8e1d3467 100644 --- a/sope-xml/STXSaxDriver/ChangeLog +++ b/sope-xml/STXSaxDriver/ChangeLog @@ -1,3 +1,16 @@ +2007-02-21 Marcus Mueller + + * v4.7.15 + + * STXSaxDriver.m, ExtraSTX/StructuredTextRenderingDelegate.h: changed + the API, which was broken by design, to properly deal with block + elements (which can be nested). + + * Model/{StructuredTextBodyElement.[hm], StructuredTextParagraph.m}: + changed API and implementation to properly deal with block elements. + + * data/znektest1.stx: trimmed testcase + 2007-02-19 Marcus Mueller * data/znektest1.stx: added testcase demonstrating a bug in conjunction diff --git a/sope-xml/STXSaxDriver/ExtraSTX/StructuredTextRenderingDelegate.h b/sope-xml/STXSaxDriver/ExtraSTX/StructuredTextRenderingDelegate.h index 13093acc..d4c417d8 100644 --- a/sope-xml/STXSaxDriver/ExtraSTX/StructuredTextRenderingDelegate.h +++ b/sope-xml/STXSaxDriver/ExtraSTX/StructuredTextRenderingDelegate.h @@ -28,13 +28,18 @@ @protocol StructuredTextRenderingDelegate -- (NSString *)insertText:(NSString *)_txt inContext:(NSDictionary *)_ctx; -- (NSString *)insertItalics:(NSString *)_txt inContext:(NSDictionary *)_ctx; -- (NSString *)insertUnderline:(NSString *)_txt inContext:(NSDictionary *)_ctx; -- (NSString *)insertBold:(NSString *)_txt inContext:(NSDictionary *)_ctx; -- (NSString *)insertPreformatted:(NSString *)_txt - inContext:(NSDictionary *)_ctx; - +- (void)appendText:(NSString *)_txt inContext:(NSDictionary *)_ctx; +- (void)beginItalicsInContext:(NSDictionary *)_ctx; +- (void)endItalicsInContext:(NSDictionary *)_ctx; +- (void)beginUnderlineInContext:(NSDictionary *)_ctx; +- (void)endUnderlineInContext:(NSDictionary *)_ctx; +- (void)beginBoldInContext:(NSDictionary *)_ctx; +- (void)endBoldInContext:(NSDictionary *)_ctx; +- (void)beginPreformattedInContext:(NSDictionary *)_ctx; +- (void)endPreformattedInContext:(NSDictionary *)_ctx; +- (void)beginParagraphInContext:(NSDictionary *)_ctx; +- (void)endParagraphInContext:(NSDictionary *)_ctx; + - (NSString *)insertLink:(NSString *)_txt withUrl:(NSString *)anUrl target:(NSString *)aTarget inContext:(NSDictionary *)_ctx; diff --git a/sope-xml/STXSaxDriver/Model/StructuredTextBodyElement.h b/sope-xml/STXSaxDriver/Model/StructuredTextBodyElement.h index 6ad6e565..e3742ad7 100644 --- a/sope-xml/STXSaxDriver/Model/StructuredTextBodyElement.h +++ b/sope-xml/STXSaxDriver/Model/StructuredTextBodyElement.h @@ -48,10 +48,18 @@ - (NSRange)findLinkTargetFromString:(NSString *)_str; - (NSRange)findDynamicKeySubstring:(NSString *)_str; -- (NSString *)preformattedText:(NSString *)_s inContext:(NSDictionary *)_ctx; -- (NSString *)boldText:(NSString *)_str inContext:(NSDictionary *)_ctx; -- (NSString *)italicsText:(NSString *)_str inContext:(NSDictionary *)_ctx; -- (NSString *)underlineText:(NSString *)_str inContext:(NSDictionary *)_ctx; +- (void)appendText:(NSString *)_txt inContext:(NSDictionary *)_ctx; +- (void)beginItalicsInContext:(NSDictionary *)_ctx; +- (void)endItalicsInContext:(NSDictionary *)_ctx; +- (void)beginUnderlineInContext:(NSDictionary *)_ctx; +- (void)endUnderlineInContext:(NSDictionary *)_ctx; +- (void)beginBoldInContext:(NSDictionary *)_ctx; +- (void)endBoldInContext:(NSDictionary *)_ctx; +- (void)beginPreformattedInContext:(NSDictionary *)_ctx; +- (void)endPreformattedInContext:(NSDictionary *)_ctx; +- (void)beginParagraphInContext:(NSDictionary *)_ctx; +- (void)endParagraphInContext:(NSDictionary *)_ctx; + - (NSString *)linkImage:(NSString *)_str inContext:(NSDictionary *)_ctx; - (NSString *)linkText:(NSString *)_str inContext:(NSDictionary *)_ctx; - (NSString *)linkTargetFromString:(NSString *)_str; diff --git a/sope-xml/STXSaxDriver/Model/StructuredTextBodyElement.m b/sope-xml/STXSaxDriver/Model/StructuredTextBodyElement.m index 76e55c6c..902ce2f4 100644 --- a/sope-xml/STXSaxDriver/Model/StructuredTextBodyElement.m +++ b/sope-xml/STXSaxDriver/Model/StructuredTextBodyElement.m @@ -75,9 +75,9 @@ static BOOL debugOn = NO; - (NSString *)parseText:(NSString *)_str inContext:(NSDictionary *)_ctx { // TODO: too big a method NSMutableString *result; - NSString *text; - NSRange range, rangeOut; - int i, length, start; + NSString *text; + NSRange range, rangeOut; + int i, length, start; if (debugOn) NSLog(@"PARSE TEXT: '%@' (delegate=0x%p)", _str, self->_delegate); @@ -97,8 +97,7 @@ static BOOL debugOn = NO; if (i - start > 0) { range.location = start; range.length = (i - start); - - [result appendString:[text substringWithRange:range]]; + [self appendText:[text substringWithRange:range] inContext:_ctx]; } start = ++i; @@ -107,9 +106,9 @@ static BOOL debugOn = NO; case '\'': if (i - start > 0) { range.location = start; - range.length = i - start; + range.length = i - start; - [result appendString:[text substringWithRange:range]]; + [self appendText:[text substringWithRange:range] inContext:_ctx]; } if (i + 1 < length) { @@ -122,86 +121,82 @@ static BOOL debugOn = NO; } range.location = i + 1; - range.length = length - range.location; - - rangeOut = [text rangeOfString:@"'" options:0 range:range]; + range.length = length - range.location; + rangeOut = [text rangeOfString:@"'" options:0 range:range]; if (rangeOut.length > 0) { - NSString *s; + NSString *s; range.location = i + 1; - range.length = rangeOut.location - range.location; + range.length = rangeOut.location - range.location; + start = i = rangeOut.location + 1; - s = [[text substringWithRange:range] unescapedString]; - s = [self preformattedText:s inContext:_ctx]; - [result appendString:s]; - - start = i = rangeOut.location + 1; + s = [[text substringWithRange:range] unescapedString]; + [self beginPreformattedInContext:_ctx]; + [self appendText:s inContext:_ctx]; + [self endPreformattedInContext:_ctx]; } else { start = i; } break; - case ST_UNDERLINE_CHAR: // underline + case ST_UNDERLINE_CHAR: if (i - start > 0) { range.location = start; - range.length = i - start; - - [result appendString:[text substringWithRange:range]]; + range.length = i - start; + start = i; - start = i; + [self appendText:[text substringWithRange:range] inContext:_ctx]; } range = [self findUnderlineSubstring:[text substringFromIndex:i + 1]]; if (range.length > 0) { - NSString *s; + NSString *s; - range.location = i + 1; + range.location = i + 1; + i += range.length + 1; + start = i + 1; - s = [[text substringWithRange:range] unescapedString]; - s = [self parseText:s inContext:_ctx]; - s = [self underlineText:s inContext:_ctx]; - if (s) [result appendString:s]; - - i += range.length + 1; - start = i + 1; + s = [[text substringWithRange:range] unescapedString]; + [self beginUnderlineInContext:_ctx]; + s = [self parseText:s inContext:_ctx]; + [self appendText:s inContext:_ctx]; + [self endUnderlineInContext:_ctx]; } break; - case ST_DYNAMICKEY_CHAR: // dynamicKey + case ST_DYNAMICKEY_CHAR: if (i - start > 0) { range.location = start; - range.length = i - start; - - [result appendString:[text substringWithRange:range]]; + range.length = i - start; + start = i; - start = i; + [self appendText:[text substringWithRange:range] inContext:_ctx]; } range = [self findDynamicKeySubstring:[text substringFromIndex:i + 1]]; if (range.length > 0) { - NSString *s; + NSString *s; range.location = i + 1; + i += range.length + 1; + start = i + 1; - s = [self parseText:[text substringWithRange:range] inContext:_ctx]; - [result appendString:[self dynamicKeyText:s inContext:_ctx]]; - - i += range.length + 1; - start = i + 1; + s = [self parseText:[text substringWithRange:range] inContext:_ctx]; + [self appendText:[self dynamicKeyText:s inContext:_ctx] + inContext:_ctx]; } break; - case ST_ITALICS_CHAR: { // italics e bold + case ST_ITALICS_CHAR: { // italics and bold if (i - start > 0) { range.location = start; - range.length = i - start; - - [result appendString:[text substringWithRange:range]]; + range.length = i - start; + start = i; - start = i; + [self appendText:[text substringWithRange:range] inContext:_ctx]; } if (i + 1 < length) { @@ -211,34 +206,34 @@ static BOOL debugOn = NO; range = [self findBoldSubstring:[text substringFromIndex:i + 2]]; if (range.length > 0) { - NSString *s; + NSString *s; range.location = i + 2; - - s = [[text substringWithRange:range] unescapedString]; - s = [self parseText:s inContext:_ctx]; - s = [self boldText:s inContext:_ctx]; - if (s) [result appendString:s]; - - i += range.length + 3; - start = i + 1; + i += range.length + 3; + start = i + 1; + + s = [[text substringWithRange:range] unescapedString]; + [self beginBoldInContext:_ctx]; + s = [self parseText:s inContext:_ctx]; + [self appendText:s inContext:_ctx]; + [self endBoldInContext:_ctx]; } } else { range = [self findItalicsSubstring:[text substringFromIndex:i + 1]]; if (range.length > 0) { - NSString *s; + NSString *s; range.location = i + 1; - - s = [[text substringWithRange:range] unescapedString]; - s = [self parseText:s inContext:_ctx]; - s = [self italicsText:s inContext:_ctx]; - if (s) [result appendString:s]; - - i += range.length + 1; - start = i + 1; + i += range.length + 1; + start = i + 1; + + s = [[text substringWithRange:range] unescapedString]; + [self beginItalicsInContext:_ctx]; + s = [self parseText:s inContext:_ctx]; + [self appendText:s inContext:_ctx]; + [self endItalicsInContext:_ctx]; } } } @@ -248,25 +243,23 @@ static BOOL debugOn = NO; case ST_LINKIMAGE_CHAR: // links if (i - start > 0) { range.location = start; - range.length = i - start; - - [result appendString:[text substringWithRange:range]]; + range.length = i - start; + start = i; - start = i; + [self appendText:[text substringWithRange:range] inContext:_ctx]; } range = [self findLinkImageSubstring:[text substringFromIndex:i + 1]]; if (range.length > 0) { - NSString *s; + NSString *s; range.location = i + 1; + i += range.length; + start = i + 1; - s = [self linkImage:[text substringWithRange:range] inContext:_ctx]; - [result appendString:s]; - - i += range.length; - start = i + 1; + s = [self linkImage:[text substringWithRange:range] inContext:_ctx]; + [self appendText:s inContext:_ctx]; } break; @@ -275,25 +268,23 @@ static BOOL debugOn = NO; if (i - start > 0) { range.location = start; range.length = i - start; + start = i; - [result appendString:[text substringWithRange:range]]; - - start = i; + [self appendText:[text substringWithRange:range] inContext:_ctx]; } range = [self findLinkSubstring:[text substringFromIndex:(i + 1)]]; if (range.length > 0) { - NSString *s; + NSString *s; range.location = i + 1; + i += range.length; + start = i + 1; - s = [self linkText:[text substringWithRange:range] inContext:_ctx]; - [result appendString:s]; - - if (debugOn) NSLog(@"found link substring: '%@'", s); - - i += range.length; - start = i + 1; + s = [self linkText:[text substringWithRange:range] inContext:_ctx]; + [self appendText:s inContext:_ctx]; + + if (debugOn) NSLog(@"found link substring: '%@'", s); } break; @@ -302,15 +293,54 @@ static BOOL debugOn = NO; if (i - start > 0) { range.location = start; - range.length = i - start; + range.length = i - start; - [result appendString:[text substringWithRange:range]]; + [self appendText:[text substringWithRange:range] inContext:_ctx]; } if (debugOn) NSLog(@" result: '%@'", result); return result; } +- (void)appendText:(NSString *)_txt inContext:(NSDictionary *)_ctx { + [self->_delegate appendText:_txt inContext:_ctx]; +} + +- (void)beginItalicsInContext:(NSDictionary *)_ctx { + [self->_delegate beginItalicsInContext:_ctx]; +} +- (void)endItalicsInContext:(NSDictionary *)_ctx { + [self->_delegate endItalicsInContext:_ctx]; +} + +- (void)beginUnderlineInContext:(NSDictionary *)_ctx { + [self->_delegate beginUnderlineInContext:_ctx]; +} +- (void)endUnderlineInContext:(NSDictionary *)_ctx { + [self->_delegate endUnderlineInContext:_ctx]; +} + +- (void)beginBoldInContext:(NSDictionary *)_ctx { + [self->_delegate beginBoldInContext:_ctx]; +} +- (void)endBoldInContext:(NSDictionary *)_ctx { + [self->_delegate endBoldInContext:_ctx]; +} + +- (void)beginPreformattedInContext:(NSDictionary *)_ctx { + [self->_delegate beginPreformattedInContext:_ctx]; +} +- (void)endPreformattedInContext:(NSDictionary *)_ctx { + [self->_delegate endPreformattedInContext:_ctx]; +} + +- (void)beginParagraphInContext:(NSDictionary *)_ctx { + [self->_delegate beginParagraphInContext:_ctx]; +} +- (void)endParagraphInContext:(NSDictionary *)_ctx { + [self->_delegate endParagraphInContext:_ctx]; +} + - (NSRange)findMarkerSubstring:(NSString *)_str withMarker:(unichar)aMarker markerLength:(int)markLength { @@ -374,10 +404,6 @@ static BOOL debugOn = NO; /* operations */ -- (NSString *)preformattedText:(NSString *)_s inContext:(NSDictionary *)_ctx { - return [self->_delegate insertPreformatted:_s inContext:_ctx]; -} - - (NSRange)_findLinkBlockTargetSubstring:(NSString *)_str { NSRange range, rangeTarget; int length; @@ -585,26 +611,6 @@ static BOOL debugOn = NO; return range; } -/* processing */ - -- (NSString *)boldText:(NSString *)_str inContext:(NSDictionary *)_ctx { - return (_delegate) - ? [_delegate insertBold:_str inContext:_ctx] - : _str; -} - -- (NSString *)italicsText:(NSString *)_str inContext:(NSDictionary *)_ctx { - return (_delegate) - ? [_delegate insertItalics:_str inContext:_ctx] - : _str; -} - -- (NSString *)underlineText:(NSString *)_str inContext:(NSDictionary *)_ctx { - return (_delegate) - ? [_delegate insertUnderline:_str inContext:_ctx] - : _str; -} - /* links */ - (NSString *)_linkBlockTarget:(NSString *)_str withName:(NSString *)aName diff --git a/sope-xml/STXSaxDriver/Model/StructuredTextParagraph.m b/sope-xml/STXSaxDriver/Model/StructuredTextParagraph.m index 9f3ad8c5..5d4d7d96 100644 --- a/sope-xml/STXSaxDriver/Model/StructuredTextParagraph.m +++ b/sope-xml/STXSaxDriver/Model/StructuredTextParagraph.m @@ -24,22 +24,22 @@ @implementation StructuredTextParagraph -- (id)initWithString:(NSString *)aString { +- (id)initWithString:(NSString *)_s { if ((self = [super init])) { - _text = [aString retain]; + self->_text = [_s retain]; } return self; } - (void)dealloc { - [_text release]; + [self->_text release]; [super dealloc]; } /* accessors */ - (NSString *)text { - return _text; + return self->_text; } /* processing */ @@ -47,14 +47,11 @@ - (NSString *)textParsedWithDelegate:(id)_del inContext:(NSDictionary *)_ctx { - NSString *text; - self->_delegate = _del; - text = [self parseText:[self text] inContext:_ctx]; - - return (_del) - ? [_del insertText:text inContext:_ctx] - : text; + [self beginParagraphInContext:_ctx]; + [self parseText:[self text] inContext:_ctx]; + [self endParagraphInContext:_ctx]; + return nil; } @end /* StructuredTextParagraph */ diff --git a/sope-xml/STXSaxDriver/STXSaxDriver.m b/sope-xml/STXSaxDriver/STXSaxDriver.m index bfb2379e..50e51ccc 100644 --- a/sope-xml/STXSaxDriver/STXSaxDriver.m +++ b/sope-xml/STXSaxDriver/STXSaxDriver.m @@ -170,45 +170,44 @@ static BOOL debugOn = NO; /* STX delegate */ -- (NSString *)insertText:(NSString *)_txt inContext:(NSDictionary *)_ctx { - if (debugOn) NSLog(@" insert text: (len=%d)", [_txt length]); - [self _beginTag:@"p"]; + +- (void)appendText:(NSString *)_txt inContext:(NSDictionary *)_ctx { [self _characters:_txt]; - [self _endTag:@"p"]; - return nil; } -- (NSString *)insertItalics:(NSString *)_txt inContext:(NSDictionary *)_ctx { - if (debugOn) NSLog(@" insert italics: (len=%d)", [_txt length]); +- (void)beginItalicsInContext:(NSDictionary *)_ctx { [self _beginTag:@"em"]; - [self _characters:_txt]; +} +- (void)endItalicsInContext:(NSDictionary *)_ctx { [self _endTag:@"em"]; - return nil; } -- (NSString *)insertUnderline:(NSString *)_txt inContext:(NSDictionary *)_ctx { - if (debugOn) NSLog(@" insert underline: (len=%d)", [_txt length]); +- (void)beginUnderlineInContext:(NSDictionary *)_ctx { [self _beginTag:@"u"]; - [self _characters:_txt]; +} +- (void)endUnderlineInContext:(NSDictionary *)_ctx { [self _endTag:@"u"]; - return nil; } -- (NSString *)insertBold:(NSString *)_txt inContext:(NSDictionary *)_ctx { - if (debugOn) NSLog(@" insert bold: (len=%d)", [_txt length]); +- (void)beginBoldInContext:(NSDictionary *)_ctx { [self _beginTag:@"strong"]; - [self _characters:_txt]; +} +- (void)endBoldInContext:(NSDictionary *)_ctx { [self _endTag:@"strong"]; - return nil; } -- (NSString *)insertPreformatted:(NSString *)_txt - inContext:(NSDictionary *)_ctx -{ +- (void)beginPreformattedInContext:(NSDictionary *)_ctx { [self _beginTag:@"pre"]; - [self _characters:_txt]; +} +- (void)endPreformattedInContext:(NSDictionary *)_ctx { [self _endTag:@"pre"]; - return nil; +} + +- (void)beginParagraphInContext:(NSDictionary *)_ctx { + [self _beginTag:@"p"]; +} +- (void)endParagraphInContext:(NSDictionary *)_ctx { + [self _endTag:@"p"]; } - (NSString *)insertLink:(NSString *)_txt diff --git a/sope-xml/STXSaxDriver/Version b/sope-xml/STXSaxDriver/Version index f61be538..cb19d00e 100644 --- a/sope-xml/STXSaxDriver/Version +++ b/sope-xml/STXSaxDriver/Version @@ -1,3 +1,3 @@ # Version file -SUBMINOR_VERSION:=14 +SUBMINOR_VERSION:=15 diff --git a/sope-xml/STXSaxDriver/data/znektest1.stx b/sope-xml/STXSaxDriver/data/znektest1.stx index d96efc42..54cd138d 100644 --- a/sope-xml/STXSaxDriver/data/znektest1.stx +++ b/sope-xml/STXSaxDriver/data/znektest1.stx @@ -1,6 +1,2 @@ -* "test 1":http://www.example.org/test1 - -* "test 2":http://www.example.org/test2 - The *test 3* URL should appear here "test 3":http://www.example.org/test3 and not anywhere else.