Handle more tricky characters in deprecation message in ObjCExport
This commit is contained in:
committed by
SvyatoslavScherbina
parent
b1a9715907
commit
9cfa98c416
+18
-2
@@ -1234,7 +1234,23 @@ private fun Deprecation.toDeprecationAttribute(): String {
|
||||
// TODO: consider avoiding code generation for unavailable.
|
||||
|
||||
val message = this.message.orEmpty()
|
||||
.replace("\n", "\\n")
|
||||
|
||||
return "$attribute(\"$message\")"
|
||||
return "$attribute(${quoteAsCStringLiteral(message)})"
|
||||
}
|
||||
|
||||
private fun quoteAsCStringLiteral(str: String): String = buildString {
|
||||
append('"')
|
||||
for (c in str) {
|
||||
when (c) {
|
||||
'\n' -> append("\\n")
|
||||
|
||||
'\r' -> append("\\r")
|
||||
|
||||
'"', '\\' -> append('\\').append(c)
|
||||
|
||||
// TODO: handle more special cases.
|
||||
else -> append(c)
|
||||
}
|
||||
}
|
||||
append('"')
|
||||
}
|
||||
|
||||
@@ -519,6 +519,13 @@ __attribute__((swift_name("JsonConfiguration")))
|
||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||
@end;
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("MoreTrickyChars")))
|
||||
@interface KtMoreTrickyChars : KtBase
|
||||
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)) __attribute__((deprecated("'\"\\@$(){}\r\n")));
|
||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||
@end;
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("Kt39206Kt")))
|
||||
@interface KtKt39206Kt : KtBase
|
||||
|
||||
@@ -11,4 +11,7 @@ fun myFunc() = 17
|
||||
"Instead of storing JsonConfiguration instances of the code, Json instances can be used directly:" +
|
||||
"'Json(MyJsonConfiguration.copy(prettyPrint = true))' can be replaced with 'Json(from = MyApplicationJson) { prettyPrint = true }'"
|
||||
)
|
||||
public open class JsonConfiguration
|
||||
public open class JsonConfiguration
|
||||
|
||||
@Deprecated("'\"\\@\$(){}\r\n")
|
||||
class MoreTrickyChars
|
||||
@@ -4,10 +4,15 @@ private func test1() throws {
|
||||
try assertEquals(actual: Kt39206Kt.myFunc(), expected: 17)
|
||||
}
|
||||
|
||||
private func test2() throws {
|
||||
try assertTrue(MoreTrickyChars() as AnyObject is MoreTrickyChars)
|
||||
}
|
||||
|
||||
class Kt39206Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Test1", test1)
|
||||
test("Test2", test2)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user