Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the end went for regex approach using <a href="http://regexkit.sourceforge.net/RegexKitLite/index.html" rel="nofollow noreferrer">RegexKitLite</a> </p> <p>The code below is not fully tested but does work with the case St3fan pointed out.</p> <pre><code>- (NSArray *) scanContent:(NSMutableString **)content { NSMutableArray *tokens = [[NSMutableArray alloc] init]; NSArray *captureRegex = [[NSArray alloc] initWithObjects: @"\\[\\[(.*?)\\]\\]",@"\\*\\*(.*?)\\*\\*", nil]; NSArray *tokenID = [[NSArray alloc] initWithObjects: @"Italic",@"Bold", nil]; int index = 0; for (NSString*capture in captureRegex) { NSRange captureRange; NSRange stringRange; stringRange.location = 0; stringRange.length = [*content length]; do { captureRange = [*content rangeOfRegex:capture inRange:stringRange]; if ( captureRange.location != NSNotFound ) { NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init]; [dictionary setObject:[tokenID objectAtIndex:index] forKey:@"Token"]; [dictionary setObject:[NSNumber numberWithInt:captureRange.location] forKey:@"Start"]; [dictionary setObject:[NSNumber numberWithInt:captureRange.length] forKey:@"Length"]; [tokens addObject:dictionary]; for (NSMutableDictionary *dict in tokens) { NSNumber *nRange = [dict objectForKey:@"Start"]; int start = [nRange intValue]; if (start &gt; captureRange.location) { nRange = [NSNumber numberWithInt:start - 4]; // Removing 4 characters [dict setObject:nRange forKey:@"Start"]; } if (start == captureRange.location) { NSString *data = [*content stringByMatching:capture options:RKLMultiline inRange:captureRange capture:1 error:NULL]; NSLog(@"data: %@",data); [*content replaceOccurrencesOfRegex:capture withString:data range:captureRange]; NSLog(@"Replaced Content: %@",*content); } } stringRange.location = captureRange.location + captureRange.length -4; stringRange.length = [*content length] - stringRange.location; } } while ( captureRange.location != NSNotFound ); index++; } return tokens; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload