Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
36
Task/Strip-block-comments/Swift/strip-block-comments.swift
Normal file
36
Task/Strip-block-comments/Swift/strip-block-comments.swift
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import Foundation
|
||||
|
||||
func stripBlocks(from str: String, open: String = "/*", close: String = "*/") -> String {
|
||||
guard !open.isEmpty && !close.isEmpty else {
|
||||
return str
|
||||
}
|
||||
|
||||
var ret = str
|
||||
|
||||
while let begin = ret.range(of: open), let end = ret[begin.upperBound...].range(of: close) {
|
||||
ret.replaceSubrange(Range(uncheckedBounds: (begin.lowerBound, end.upperBound)), with: "")
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
let test = """
|
||||
/**
|
||||
* Some comments
|
||||
* longer comments here that we can parse.
|
||||
*
|
||||
* Rahoo
|
||||
*/
|
||||
function subroutine() {
|
||||
a = /* inline comment */ b + c ;
|
||||
}
|
||||
/*/ <-- tricky comments */
|
||||
|
||||
/**
|
||||
* Another comment.
|
||||
*/
|
||||
function something() {
|
||||
}
|
||||
"""
|
||||
|
||||
print(stripBlocks(from: test))
|
||||
Loading…
Add table
Add a link
Reference in a new issue