Fix CRLF handling in source-sections plugin

This commit is contained in:
Ilya Chernikov
2017-04-03 19:00:48 +02:00
parent 0199ec18b1
commit 30048f8f49
2 changed files with 30 additions and 1 deletions
@@ -41,7 +41,14 @@ class FilteredSectionsVirtualFile(val delegate: VirtualFile, val sectionIds: Col
override fun getTimeStamp(): Long = delegate.timeStamp
override fun getName(): String = delegate.name
override fun contentsToByteArray(): ByteArray = filterByteContents(sectionIds, delegate.contentsToByteArray(), delegate.charset)
override fun contentsToByteArray(): ByteArray {
val res = filterByteContents(sectionIds, delegate.contentsToByteArray(), delegate.charset)
val dbgDumpFile = delegate.canonicalPath?.let { java.io.File(it + ".${sectionIds.joinToString(".")}.dump") }
if (dbgDumpFile != null && !dbgDumpFile.exists()) {
dbgDumpFile.writeText(String(res))
}
return res
}
override fun getInputStream(): InputStream = ByteArrayInputStream(contentsToByteArray())
@@ -71,6 +78,11 @@ private fun filterByteContents(sectionIds: Collection<String>, bytes: ByteArray,
}
private fun filterStringBuilderContents(content: StringBuilder, sectionIds: Collection<String>): StringBuilder {
for (i in 0..content.length - 1) {
if (content[i] == '\r') {
content[i] = ' '
}
}
var curPos = 0
val sectionsIter = FilteredSectionsTokensRangeIterator(content, sectionIds)
for (range in sectionsIter) {