forked from scala-cli/libsodiumjni
-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.sc
44 lines (39 loc) · 1.09 KB
/
util.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def toCrLfOpt(content: Array[Byte]): Option[Array[Byte]] = {
val cr = '\r'.toByte
val lf = '\n'.toByte
val indices = content
.iterator
.zipWithIndex
.collect {
case (`lf`, idx) if idx > 0 && content(idx - 1) != cr => idx
}
.toVector
if (indices.isEmpty)
None
else {
val updatedContent = Array.ofDim[Byte](content.length + indices.length)
var i = 0 // content index
var j = 0 // updatedContent index
var n = 0 // indices index
while (n < indices.length) {
val idx = indices(n)
System.arraycopy(content, i, updatedContent, j, idx - i)
j += idx - i
i = idx
updatedContent(j) = cr
updatedContent(j + 1) = lf
i += 1
j += 2
n += 1
}
val idx = content.length
System.arraycopy(content, i, updatedContent, j, content.length - i)
j += idx - i
i = idx
assert(i == content.length)
assert(j == updatedContent.length)
Some(updatedContent)
}
}
def isArmArchitecture: Boolean =
os.proc("uname", "-p").call(cwd = os.pwd).out.trim() == "arm"