Skip to content

Commit fd87d8b

Browse files
committed
Merge pull request #200 from mac-cain13/bugfix/escape-crlf
Correctly escape CR+LF in R.string
2 parents a869bd0 + b002e7c commit fd87d8b

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

R.swift/Generators/StringsGenerator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,17 +289,17 @@ private struct StringValues {
289289
let anyNone = values.any { $0.0.isNone }
290290

291291
if let baseValue = baseValue {
292-
let str = "Base translation: \(baseValue)".stringByReplacingOccurrencesOfString("\n", withString: " ")
292+
let str = "Base translation: \(baseValue)".commentString
293293
results.append(str)
294294
}
295295
else if !containsBase {
296296
if let (locale, value) = values.first {
297297
if let localeDescription = locale.localeDescription {
298-
let str = "\(localeDescription) translation: \(value)".stringByReplacingOccurrencesOfString("\n", withString: " ")
298+
let str = "\(localeDescription) translation: \(value)".commentString
299299
results.append(str)
300300
}
301301
else {
302-
let str = "Value: \(value)".stringByReplacingOccurrencesOfString("\n", withString: " ")
302+
let str = "Value: \(value)".commentString
303303
results.append(str)
304304
}
305305
}

R.swift/Util/UtilExtensions.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,16 @@ extension String {
5656
.stringByReplacingOccurrencesOfString("\\", withString: "\\\\")
5757
.stringByReplacingOccurrencesOfString("\"", withString: "\\\"")
5858
.stringByReplacingOccurrencesOfString("\t", withString: "\\t")
59+
.stringByReplacingOccurrencesOfString("\r", withString: "\\r")
5960
.stringByReplacingOccurrencesOfString("\n", withString: "\\n")
6061
}
62+
63+
var commentString: String {
64+
return self
65+
.stringByReplacingOccurrencesOfString("\r\n", withString: " ")
66+
.stringByReplacingOccurrencesOfString("\r", withString: " ")
67+
.stringByReplacingOccurrencesOfString("\n", withString: " ")
68+
}
6169
}
6270

6371
// MARK: NSURL operations

ResourceApp/ResourceApp/Strings/Base.lproj/Settings.strings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
\"\\DEF/\"
1616
GHI Base";
1717
"Copy.Progress" = "%1$d of %2$i files copied, %3$f.2%% completed.";
18+
"We need a couple things\r\nbefore you get started." = "We need a couple things\r\nbefore you get started.";
1819

1920
"FormatSpecifiers1" = "number 1: %d, number 2: %i, string 3: %@";
2021
"FormatSpecifiers2" = "string 3: %3$@, number 2: %2$d, number 1: %1$i";

ResourceApp/ResourceApp/Strings/nl.lproj/Settings.strings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
\"\\DEF/\"
1616
GHI Dutch";
1717
"Copy.Progress" = "Van de %2$d bestanden zijn er %1$d gekopieerd, %3$.2f%% compleet.";
18+
"We need a couple things\r\nbefore you get started." = "We hebben een aantal dingen nodig\r\nvoordat je begint.";
1819

1920
"FormatSpecifiers1" = "number 1: %d, number 2: %i";
2021
"FormatSpecifiers2" = "string 3: %3$@, number 1: %1$i";

0 commit comments

Comments
 (0)