Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reason: '-[__NSCFString replaceOccurrencesOfString:withString:options:range:]: Range {0, 6} out of bounds; string length 2' #58

Open
KittenYang opened this issue Aug 2, 2014 · 2 comments

Comments

@KittenYang
Copy link

我遇到这个问题,i find the reason lies on RTLabel.m—— line 848~858:
if (position!=NSNotFound)
{
if ([delimiter rangeOfString:@"<p"].location==0)
{
data = [data stringByReplacingOccurrencesOfString:delimiter withString:paragraphReplacement options:NSCaseInsensitiveSearch range:NSMakeRange(last_position, position+delimiter.length-last_position)];
}
else
{
data = [data stringByReplacingOccurrencesOfString:delimiter withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(last_position, position+delimiter.length-last_position)];
}

        data = [data stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
        data = [data stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];
    }

How can i resolve it?THANKS!

@Eloreden
Copy link

Eloreden commented Sep 3, 2014

i think that i have solved your problem on

unsigned long position = [data rangeOfString:delimiter].location; // Here the problem because miss precision because position is declared like int
if (position!=NSNotFound)
{
if ([delimiter rangeOfString:@"<p"].location==0)
{
data = [data stringByReplacingOccurrencesOfString:delimiter withString:paragraphReplacement options:NSCaseInsensitiveSearch range:NSMakeRange(last_position, position+delimiter.length-last_position)];
}
else
{
data = [data stringByReplacingOccurrencesOfString:delimiter withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(last_position, position+delimiter.length-last_position)];
}

        data = [data stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
        data = [data stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];
    }

@KittenYang
Copy link
Author

THX!Actually,I finally resolve it by changing RTLabel.m line 844- 858 like that:

int position = [data rangeOfString:delimiter options:NSCaseInsensitiveSearch range:NSMakeRange(last_position, [data length] - last_position)].location;
        if (position != NSNotFound && position >= last_position)
        {
            if ([delimiter rangeOfString:@"<p"].location==0)
            {
                data = [data stringByReplacingOccurrencesOfString:delimiter withString:paragraphReplacement options:NSCaseInsensitiveSearch range:NSMakeRange(position, delimiter.length)];
            }
            else
            {
                data = [data stringByReplacingOccurrencesOfString:delimiter withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(position, delimiter.length)];
            }

            data = [data stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
            data = [data stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];
        }

:D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants