diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2020-03-30 12:40:45 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2020-03-30 14:39:19 +0200 |
| commit | da700859e6a3d3a22f1784e520c650be067e5c19 (patch) | |
| tree | 23a846045773aa74a295f32f0d844002caa7d474 /ios/MullvadVPN/String+Split.swift | |
| parent | eb58ceec08e3c387e055a0d10fad5c4dfb2711c7 (diff) | |
| download | mullvadvpn-da700859e6a3d3a22f1784e520c650be067e5c19.tar.xz mullvadvpn-da700859e6a3d3a22f1784e520c650be067e5c19.zip | |
Format account token in Account view
Diffstat (limited to 'ios/MullvadVPN/String+Split.swift')
| -rw-r--r-- | ios/MullvadVPN/String+Split.swift | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/ios/MullvadVPN/String+Split.swift b/ios/MullvadVPN/String+Split.swift new file mode 100644 index 0000000000..82352280fc --- /dev/null +++ b/ios/MullvadVPN/String+Split.swift @@ -0,0 +1,22 @@ +// +// String+Split.swift +// MullvadVPN +// +// Created by pronebird on 27/03/2020. +// Copyright © 2020 Mullvad VPN AB. All rights reserved. +// + +import Foundation + +extension String { + + /// Returns the array of the longest possible subsequences of the given length. + func split(every length: Int) -> [Substring] { + guard length > 0 else { return [prefix(upTo: endIndex)] } + + let resultCount = Int((Float(count) / Float(length)).rounded(.up)) + + return (0 ..< resultCount) + .map { dropFirst($0 * length).prefix(length) } + } +} |
