From 765889a9d68f8c28ab5ea2214d3c169d818f8dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Tue, 26 Dec 2023 13:04:42 +0300 Subject: [PATCH] d --- src/MeetupId.swift | 30 ++++++++++++++++-------------- src/VM.swift | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/MeetupId.swift b/src/MeetupId.swift index 41f6172..4db3661 100644 --- a/src/MeetupId.swift +++ b/src/MeetupId.swift @@ -7,21 +7,23 @@ enum MeetupId { case meetupIdTextUI } - static func shouldFormat(_ s: String) -> String? { - let digits = s.components(separatedBy: NSCharacterSet.decimalDigits.inverted).reduce("") { $0 + $1 } - var r = "" - var i = 0 - for v in digits { - r += String(v) - i = i + 1 - if i % 3 == 0 { - r += "-" - } + static func onlyFormat(_ s: String) -> String? { + let digits = s.components(separatedBy: NSCharacterSet.decimalDigits.inverted).reduce("") { $0 + $1 } + var r = "" + var i = 0 + // Делим каждые три цифры дефисом. + for v in digits { + r += String(v) + i = i + 1 + if i % 3 == 0 { + r += "-" } - if r.hasSuffix("-") { - r = String(r.dropLast(1)) - } - return r + } + // Исключаем дефис в конце. + if r.hasSuffix("-") { + r = String(r.dropLast(1)) + } + return r } } diff --git a/src/VM.swift b/src/VM.swift index a4ac538..0935b5e 100644 --- a/src/VM.swift +++ b/src/VM.swift @@ -6,7 +6,7 @@ final class VM: ObservableObject { let format = Bus.Processor( MeetupId.K.meetupIdTextUI.rawValue, MeetupId.K.meetupIdTextApp.rawValue, - MeetupId.shouldFormat + MeetupId.onlyFormat ) var subscriptions = [AnyCancellable]()