It's me again. ;)
I can't find an explanation for this except "bug". I might be missing something, but I suppose this is the best place anyway.
Interestingly, I tried to cut the sample text down a bit for posting here, but the problem seems to only happen with the full string.
#import <Foundation/Foundation.h>
#import <RegexKit/RegexKit.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString *lyric = @"Look at the stars <br/>Look how they shine for you<br/>And everything you do <br/>Yeah, they were all yellow<br/><br/>I came along <br/>I wrote a song for you <br/>And all the things you do<br/>And it was called Yellow <br/> <br/>So then I took my turn <br/>Oh what a thing to've done <br/>And it was all yellow<br/><br/>Your skin <br/>Oh yeah your skin and bones<br/>Turn it into something beautiful<br/>And you know<br/>You know I love you so <br/>You know I love you so<br/><br/>I swam across <br/>I jumped across for you<br/>Oh what a thing to do <br/>'Cause you were all yellow<br/><br/>I drew a line<br/>I drew a line for you<br/>Oh what a thing to do<br/>And it was all yellow<br/><br/>Your skin <br/>Oh yeah your skin and bones<br/>Turn into something beautiful<br/>And you know <br/>For you I'd bleed myself dry<br/>For you I'd bleed myself dry<br/><br/>It's true <br/>Look how they shine for you<br/>Look how they shine for you<br/>Look how they shine for<br/>Look how they shine for you <br/>Look how they shine for you<br/>Look how they shine <br/><br/>Look at the stars<br/>Look how they shine for you<br/>And all the things that you
do";
NSLog(@"Length before: %d", [lyric length]);
lyric = [lyric stringByMatching:@"<br/>" replace:RKReplaceAll withReferenceString:@"<br/>"];
NSLog(@"Length after: %d", [lyric length]);
NSLog(@"%@", lyric);
[pool drain];
return 0;
}
Prints:
2008-04-05 12:21:13.094 bug[25329:10b] Length before: 1235
2008-04-05 12:21:13.103 bug[25329:10b] CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary.
2008-04-05 12:21:13.104 bug[25329:10b] Length after: 362
2008-04-05 12:21:13.105 bug[25329:10b] <br/>.............
I have no idea what's going on, but 3/4 of the string just disappears! Obviously, it happens when not replacing '<br/>' with '<br/>' as well. The idea was to replace <br/> with newlines and strip all other tags (like <i> and <b>) with <[^>]+>.
BTW, thanks for the insanely good answer on the other bug report!
Also, I've worked around this already (with NSStrings native methods), but the bug(?) remains. In other words, please don't spend a lot of time to come up with a workaround. :)
Hi,
I just wanted to add that I've also been bitten by this issue. What I wanted was a way to squish consecutive whitespace characters in a 'dirty' input string, as well as to convert any newlines or tabs to spaces. Basically it's the equivalent of Ruby's gsub(/\s+/, ' ')
f/e:
NSString* lorem = @"This works\njust fine.";
[lorem stringByMatching:@"\\s+" replace:RKReplaceAll withReferenceString:@" "]
Gives me back "This works just fine."
However, if you use a much longer version of Lorem Ipsum (I won't clog up the comments here with that text) what I get back is the *end* of the string (albeit with correct substitutions made).
Thanks,
Trev