[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Problem with string replacement
From: |
Fred Kiefer |
Subject: |
Problem with string replacement |
Date: |
Fri, 28 Oct 2011 13:21:34 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.23) Gecko/20110920 SUSE/3.1.15 Thunderbird/3.1.15 |
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.
Fred
- Problem with string replacement,
Fred Kiefer <=