Skip to content

Commit ae39af2

Browse files
committed
Merge branch 'ryu2-master' into develop
2 parents 91a60cf + 699df4d commit ae39af2

File tree

6 files changed

+32
-5
lines changed

6 files changed

+32
-5
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: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ - (NSString *)stringByNumberingFormatPlaceholders
1515
static dispatch_once_t onceToken;
1616
static NSRegularExpression *matchNonEscapedPercent = nil;
1717
dispatch_once(&onceToken, ^{
18-
matchNonEscapedPercent = [NSRegularExpression regularExpressionWithPattern:@"(?<=[^%]|^)(?:(?:%%)*)(%)(?:[^%]|$)" options:0 error:NULL];
18+
matchNonEscapedPercent = [NSRegularExpression regularExpressionWithPattern:@"(?<=[^%]|^)(?:(?:%%)*)(%(?!\\d+\\$))(?:[^%]|$)" options:0 error:NULL];
1919
});
2020

2121
__block NSMutableString *tmpString = nil;
@@ -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/Resources/Testcases.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ NSString *message = [NSString stringWithFormat:NSLocalizedString(@"\"%@\" has be
77

88
NSLocalizedString(@"%@ had been successfully added to the Address Book.\nWould you like to edit the card now?", nil);
99

10+
NSLocalizedString(@"foo " @"bar", @"Test multi-part quoted strings");
11+
12+
NSLocalizedString(@"Item %1$d of %2$d", @"Test positional params");
13+
1014
// some regular test cases
1115

1216

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)