- (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);
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;
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) {
}
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) {
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];
}
}
}
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;
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;
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
{
/* operations */
-- (NSString *)preformattedText:(NSString *)_s inContext:(NSDictionary *)_ctx {
- return [self->_delegate insertPreformatted:_s inContext:_ctx];
-}
-
- (NSRange)_findLinkBlockTargetSubstring:(NSString *)_str {
NSRange range, rangeTarget;
int length;
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
/* 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