From b08a752369e70bee4da977d6b17cb1649cd16dc9 Mon Sep 17 00:00:00 2001 From: Haik Aslanyan Date: Sun, 12 Apr 2020 19:41:28 +0400 Subject: [PATCH] fixed character count --- Sources/Internal/RCBitCoder.swift | 6 +++--- Sources/Public/RCCoderConfiguration.swift | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/RCBitCoder.swift b/Sources/Internal/RCBitCoder.swift index 026ebc7..1687fd6 100644 --- a/Sources/Internal/RCBitCoder.swift +++ b/Sources/Internal/RCBitCoder.swift @@ -49,9 +49,9 @@ extension RCBitCoder { //adding staring character index and filling with special indexes indexes.insert(configuration.characters.firstIndex(of: configuration.version.startingCharacter)!, at: 0) let emptyIndexes = configuration.version.emptyCharacters.map({configuration.characters.firstIndex(of: $0)!}) - let randomBytes = (0.. [RCBit] in var stringValue = String(repeating: "0", count: configuration.bitesPerSymbol) @@ -96,7 +96,7 @@ extension RCBitCoder { //mapping to custom size byte let bytes = stride(from: 0, to: dataBits.count, by: configuration.bitesPerSymbol).map { Array(dataBits[$0 ..< min($0 + configuration.bitesPerSymbol, dataBits.count)]) - }.prefix(configuration.maxMessageCount) + }.prefix(configuration.maxMessageCount + 1) //converting binary into decimal let indexes = bytes.map({ bits in return bits.reduce(0) { accumulated, current in diff --git a/Sources/Public/RCCoderConfiguration.swift b/Sources/Public/RCCoderConfiguration.swift index 394b5dd..c94bb18 100644 --- a/Sources/Public/RCCoderConfiguration.swift +++ b/Sources/Public/RCCoderConfiguration.swift @@ -36,7 +36,7 @@ public struct RCCoderConfiguration { charactersArray.append(contentsOf: version.emptyCharacters) self.characters = charactersArray self.bitesPerSymbol = String(charactersArray.count - 1, radix: 2).count - self.maxMessageCount = version.maxBitesPerSection * 3 / bitesPerSymbol + self.maxMessageCount = version.maxBitesPerSection * 3 / bitesPerSymbol - 1 } func validate(_ text: String) -> Bool {