Skip to content

Commit a475327

Browse files
committed
Handle comments beginning/ending with " properly.
It was trimming all the quotes, not just leading/trailing ones.
1 parent d51a9fc commit a475327

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

Core/Source/DTLocalizableStringEntry.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ - (void)addComment:(NSString *)comment
101101
comment = [self _stringByRecognizingNil:comment];
102102

103103
// remove the quotes
104-
comment = [comment stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\""]];
104+
comment = [comment stringByRemovingSurroundingQuotes];
105105

106106
if (![comment length])
107107
{

Core/Source/NSString+DTLocalizableStringScanner.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,11 @@
4646
@returns The receiver's content with control characters slash-escaped
4747
*/
4848
- (NSString *)stringByAddingSlashEscapes;
49+
50+
/**
51+
Change "foo" to foo. This will remove just one set of quotes, so that e.g. ""foo"" becomes "foo"
52+
If the string does not begin and end with a quote, returns it unmodified.
53+
@returns The string with one set of surrounding quotes removed.
54+
*/
55+
- (NSString *)stringByRemovingSurroundingQuotes;
4956
@end

Core/Source/NSString+DTLocalizableStringScanner.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,4 +618,16 @@ - (NSString *)stringByAddingSlashEscapes
618618
return clean;
619619
}
620620

621+
- (NSString *)stringByRemovingSurroundingQuotes
622+
{
623+
NSUInteger length = [self length];
624+
NSString *clean = self;
625+
626+
if (length >= 2 && [self characterAtIndex:0] == '\"' && [self characterAtIndex:length-1] == '\"') {
627+
clean = [self substringWithRange:NSMakeRange(1, length-2)];
628+
}
629+
630+
return clean;
631+
}
632+
621633
@end
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/* Tests if the escaping of double quotes and slashes works */
22

3-
NSLocalizedString(@"here are three \\\\\\\"\"\"\nslashes&quotes: \\\\\\\"\"\"", nil)
3+
NSLocalizedString(@"here are three \\\\\\\"\"\"\nslashes&quotes: \\\\\\\"\"\"", nil)
4+
5+
NSLocalizedString(@"bar", @"Test comment ending with \"quotes\"");

Test/Source/UnitTest.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,10 @@ - (void)internalTestCaseWithURL:(NSURL *)URL withTempPath:(NSString *)tempPath
179179
NSString *genstrings1Contents = [NSString stringWithContentsOfFile:genstrings1File usedEncoding:NULL error:NULL];
180180
NSString *genstrings2Contents = [NSString stringWithContentsOfFile:genstrings2File usedEncoding:NULL error:NULL];
181181

182-
// size check does not work because predicate editor output repeats comment for each token
183-
// STAssertEquals([genstrings1Contents length], [genstrings2Contents length], @"Different file sizes on %@", genstrings1File);
182+
// size check does not work because predicate editor output repeats comment for each token
183+
if (![[URL absoluteString] hasSuffix:@"NSPredicateEditor.txt"]) {
184+
STAssertEquals([genstrings1Contents length], [genstrings2Contents length], @"Different file sizes on %@", genstrings1File);
185+
}
184186

185187
NSDictionary *genstrings1Stuff = [genstrings1Contents propertyListFromStringsFileFormat];
186188
NSDictionary *genstrings2Stuff = [genstrings2Contents propertyListFromStringsFileFormat];

0 commit comments

Comments
 (0)