[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problem with string replacement
From: |
Richard Frith-Macdonald |
Subject: |
Re: Problem with string replacement |
Date: |
Fri, 28 Oct 2011 13:13:58 +0100 |
On 28 Oct 2011, at 12:21, Fred Kiefer wrote:
> Yesterday I noticed that I have a few additional failing tests for base. Most
> of these come from the test for NSJSONSerialization. After a closer look I
> was able to restrict the issue down to the following code, which hasn't
> anything to do with JSON any more.
> In the JSON test code we had a string that contained the character " and the
> unicode value 1 and the serialisation tries to deal with these value by
> replacing them.
>
>
> NSMutableString *str1, *str2;
> unichar chars[3];
>
> chars[0] = '\"';
> chars[1] = 1;
> str1 = [NSMutableString stringWithCharacters: chars length: 2];
> [str1 replaceOccurrencesOfString: @"\""
> withString: @"\\\""
> options: 0
> range: NSMakeRange(0, [str1 length])];
>
> chars[0] = '\\';
> chars[1] = '\"';
> chars[2] = 1;
> str2 = [NSMutableString stringWithCharacters: chars length: 3];
> NSLog(@"string 1 %@ string 2 %@", str1, str2);
> PASS([str1 isEqual: str2],
> "string occurrences replacement works");
>
> To me this looks like a bug in the code of replaceOccurrencesOfString:... I
> tried to understand that code but completely failed inside the GSeq.h
> functions. At least I noticed a few things, first we end of using the
> function strRangeCsNs, this is because the searched string is an
> NSConstantString and all the optimisations don't kick in for that case. The
> second is that this function returns twice the range {0, 1} although the
> second time the search range is {2, 1}.
>
> Could somebody please explain this to me? If this is an actual problem I
> would like to add the above code into the NSMutableString tests.
Please add it to the tests ... I'll have a look at it.
I couldn't reproduce the problem on my main system, but on my 64bit test system
where I'm experimenting with clang it shows up ... so it's probably a 64bit
related issue.