gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-ios] 13/19: ScopedCurrencyInfo, SuperScriptDigit


From: gnunet
Subject: [taler-taler-ios] 13/19: ScopedCurrencyInfo, SuperScriptDigit
Date: Sat, 02 Sep 2023 22:01:14 +0200

This is an automated email from the git hooks/post-receive script.

marc-stibane pushed a commit to branch master
in repository taler-ios.

commit a747968ddc6e027e62fd869019d3fe3a9bb70e73
Author: Marc Stibane <marc@taler.net>
AuthorDate: Thu Aug 31 21:11:44 2023 +0200

    ScopedCurrencyInfo, SuperScriptDigit
---
 TalerWallet1/Model/Model+Exchange.swift      |  6 ------
 taler-swift/Sources/taler-swift/Amount.swift | 32 +++++++++++++++++++++++++++-
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/TalerWallet1/Model/Model+Exchange.swift 
b/TalerWallet1/Model/Model+Exchange.swift
index 434311d..f52ee75 100644
--- a/TalerWallet1/Model/Model+Exchange.swift
+++ b/TalerWallet1/Model/Model+Exchange.swift
@@ -78,12 +78,6 @@ fileprivate struct AddExchange: 
WalletBackendFormattedRequest {
 }
 
 /// A request to get info about a currency
-struct ScopedCurrencyInfo: Decodable {
-    var decimalSeparator: String
-    var numFractionalDigits: Int        // 0 Yen, 2 €,$, 3 arabic
-    var numTinyDigits: Int              // SuperScriptDigits
-    var isCurrencyNameLeading: Bool
-}
 
 fileprivate struct GetScopedCurrencyInfo: WalletBackendFormattedRequest {
     typealias Response = ScopedCurrencyInfo
diff --git a/taler-swift/Sources/taler-swift/Amount.swift 
b/taler-swift/Sources/taler-swift/Amount.swift
index cfd01e0..647055b 100644
--- a/taler-swift/Sources/taler-swift/Amount.swift
+++ b/taler-swift/Sources/taler-swift/Amount.swift
@@ -4,6 +4,22 @@
  */
 import Foundation
 
+public func SuperScriptDigit(_ number: UInt32) -> String {
+    switch number {
+        case 0: return String("\u{2070}")
+        case 1: return String("\u{00B9}")
+        case 2: return String("\u{00B2}")
+        case 3: return String("\u{00B3}")
+        case 4: return String("\u{2074}")
+        case 5: return String("\u{2075}")
+        case 6: return String("\u{2076}")
+        case 7: return String("\u{2077}")
+        case 8: return String("\u{2078}")
+        case 9: return String("\u{2079}")
+        default: return ""
+    }
+}
+
 /// Errors for `Amount`.
 enum AmountError: Error {
     /// The string cannot be parsed to create an `Amount`.
@@ -22,6 +38,13 @@ enum AmountError: Error {
     case divideByZero
 }
 
+public struct ScopedCurrencyInfo: Codable {
+    var decimalSeparator: String
+    var numFractionalDigits: Int        // 0 Yen, 2 €,$, 3 arabic
+    var numTinyDigits: Int              // SuperScriptDigits
+    var isCurrencyNameLeading: Bool
+}
+
 /// A value of some currency.
 public class Amount: Codable, Hashable, CustomStringConvertible {
     /// Format that a currency must match.
@@ -45,6 +68,9 @@ public class Amount: Codable, Hashable, 
CustomStringConvertible {
     /// The fractional value of the amount (number to the right of the decimal 
point).
     var fraction: UInt32
 
+    /// Additional info for formatting currency strings
+    var currencyInfo: ScopedCurrencyInfo?
+
     public func hash(into hasher: inout Hasher) {
         hasher.combine(currency)
         if let normalized = try? normalizedCopy() {
@@ -69,6 +95,10 @@ public class Amount: Codable, Hashable, 
CustomStringConvertible {
 
     /// The string representation of the value, formatted as 
"`integer`.`fraction`".
     public var valueStr: String {
+        var decimalSeparator = "."
+        if let currencyInfo {
+            decimalSeparator = currencyInfo.decimalSeparator
+        }
         if fraction == 0 {
             return "\(integer)"
         } else {
@@ -78,7 +108,7 @@ public class Amount: Codable, Hashable, 
CustomStringConvertible {
                 fracStr += "\(frac / (Amount.fractionalBase / 10))"
                 frac = (frac * 10) % Amount.fractionalBase
             }
-            return "\(integer).\(fracStr)"
+            return "\(integer)\(decimalSeparator)\(fracStr)"
         }
     }
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]