September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
51
Task/Strip-block-comments/Kotlin/strip-block-comments.kotlin
Normal file
51
Task/Strip-block-comments/Kotlin/strip-block-comments.kotlin
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
// version 1.1.4-3
|
||||
|
||||
val sample = """
|
||||
/**
|
||||
* Some comments
|
||||
* longer comments here that we can parse.
|
||||
*
|
||||
* Rahoo
|
||||
*/
|
||||
function subroutine() {
|
||||
a = /* inline comment */ b + c ;
|
||||
}
|
||||
/*/ <-- tricky comments */
|
||||
|
||||
/**
|
||||
* Another comment.
|
||||
*/
|
||||
function something() {
|
||||
}
|
||||
"""
|
||||
|
||||
val sample2 = """
|
||||
``{
|
||||
` Some comments
|
||||
` longer comments here that we can parse.
|
||||
`
|
||||
` Rahoo
|
||||
``}
|
||||
function subroutine2() {
|
||||
d = ``{ inline comment ``} e + f ;
|
||||
}
|
||||
``{ / <-- tricky comments ``}
|
||||
|
||||
``{
|
||||
` Another comment.
|
||||
``}
|
||||
function something2() {
|
||||
}
|
||||
"""
|
||||
|
||||
fun stripBlockComments(text: String, del1: String = "/*", del2: String = "*/"): String {
|
||||
val d1 = Regex.escape(del1)
|
||||
val d2 = Regex.escape(del2)
|
||||
val r = Regex("""(?s)$d1.*?$d2""")
|
||||
return text.replace(r, "")
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println(stripBlockComments(sample))
|
||||
println(stripBlockComments(sample2, "``{", "``}"))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue