formatKeyString static method
Formats the given key
by chunking the key
and adding the begin
and end
to the key
.
The line length will be defined by the given chunkSize
. The default value is 64.
Each line will be delimited by the given lineDelimiter
. The default value is '\n'.w
Implementation
static String formatKeyString(String key, String begin, String end,
{int chunkSize = 64, String lineDelimiter = '\n'}) {
var sb = StringBuffer();
var chunks = StringUtils.chunk(key, chunkSize);
if (StringUtils.isNotNullOrEmpty(begin)) {
sb.write(begin + lineDelimiter);
}
for (var s in chunks) {
sb.write(s + lineDelimiter);
}
if (StringUtils.isNotNullOrEmpty(end)) {
sb.write(end);
return sb.toString();
} else {
var tmp = sb.toString();
return tmp.substring(0, tmp.lastIndexOf(lineDelimiter));
}
}