Smallville7123
04/18/2019, 5:40 PMjw
04/18/2019, 5:42 PMSmallville7123
04/18/2019, 5:43 PMjw
04/18/2019, 5:45 PMkarelpeeters
04/18/2019, 5:47 PMensureCapacity you asked about earlierSmallville7123
04/18/2019, 5:50 PMfun String.padExtendEnd(to: Int, char: Char) = this.toStringBuilder().append(char.toString().repeat(to-this.length)).toString()karelpeeters
04/18/2019, 5:52 PMimport kotlin.math.max
fun String.padExtendEnd(to: Int): String {
val build = StringBuilder(max(this.length, to));
build.append(this);
while(build.length != to) build.append(' ')
return build.toString()
}karelpeeters
04/18/2019, 5:54 PMSmallville7123
04/18/2019, 6:00 PMSmallville7123
04/18/2019, 6:00 PM.repeat slow?karelpeeters
04/18/2019, 6:01 PMString instance, which is dumb since you already have a new temporary array in the StringBuilder.Smallville7123
04/18/2019, 6:02 PMkarelpeeters
04/18/2019, 6:02 PMSmallville7123
04/18/2019, 6:02 PMkarelpeeters
04/18/2019, 6:03 PMSmallville7123
04/18/2019, 6:04 PMjw
04/18/2019, 6:09 PMthis and whether it causes expansionjw
04/18/2019, 6:09 PMSmallville7123
04/18/2019, 6:12 PMjw
04/18/2019, 6:13 PMjw
04/18/2019, 6:14 PMkarelpeeters
04/18/2019, 6:18 PMmax thing, I wonder if I'm wrong with that?Smallville7123
04/18/2019, 6:26 PMSmallville7123
04/18/2019, 6:34 PMpadExtendStart(1, ' ') = "a " 4 expect " abc"
padExtendEnd (1, ' ') = "a " 4 expect "abc "karelpeeters
04/18/2019, 6:34 PMSmallville7123
04/18/2019, 6:37 PMpadExtendEnd extends the end to to when it is larger then this.length specifying a value lower than this.length should do the opposite (in which as pads from the end right untill to characters remain) right? if so should the same apply for padExtendStart but in the other direction?karelpeeters
04/18/2019, 6:38 PMpad functions don't work like this, eg. the ones in Kotlin don't.Smallville7123
04/18/2019, 6:41 PMSmallville7123
04/18/2019, 6:55 PMSmallville7123
04/18/2019, 7:42 PMpadExtend and padShrink are based loosely on Sign Extension https://en.wikipedia.org/wiki/Sign_extensionkarelpeeters
04/18/2019, 7:43 PMSmallville7123
04/18/2019, 7:55 PM