summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-09-09 10:49:13 -0400
committerLinus Groh <mail@linusgroh.de>2021-09-11 11:05:50 +0100
commite6334cb856dde5d1642c21d236fee01cd46f6303 (patch)
tree1566d55a01256750b5b789f994258c03ea9599a4 /Userland/Libraries
parent3ae4ff109f39262515511a209b66d73fa834de09 (diff)
downloadserenity-e6334cb856dde5d1642c21d236fee01cd46f6303.zip
LibUnicode: Add some data related to currency codes
This data is published under ISO-4217 as an XML file. Since we can't parse XML files yet, and the data isn't very large, it was translated to C++ manually here.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibUnicode/CMakeLists.txt1
-rw-r--r--Userland/Libraries/LibUnicode/CurrencyCode.cpp206
-rw-r--r--Userland/Libraries/LibUnicode/CurrencyCode.h21
-rw-r--r--Userland/Libraries/LibUnicode/Forward.h1
4 files changed, 229 insertions, 0 deletions
diff --git a/Userland/Libraries/LibUnicode/CMakeLists.txt b/Userland/Libraries/LibUnicode/CMakeLists.txt
index c06d6d1793..88ea78231e 100644
--- a/Userland/Libraries/LibUnicode/CMakeLists.txt
+++ b/Userland/Libraries/LibUnicode/CMakeLists.txt
@@ -3,6 +3,7 @@ include(${SerenityOS_SOURCE_DIR}/Meta/CMake/unicode_data.cmake)
SET(SOURCES
${UNICODE_DATA_SOURCES}
CharacterTypes.cpp
+ CurrencyCode.cpp
Locale.cpp
)
diff --git a/Userland/Libraries/LibUnicode/CurrencyCode.cpp b/Userland/Libraries/LibUnicode/CurrencyCode.cpp
new file mode 100644
index 0000000000..e19cf8da49
--- /dev/null
+++ b/Userland/Libraries/LibUnicode/CurrencyCode.cpp
@@ -0,0 +1,206 @@
+/*
+ * Copyright (c) 2021, Tim Flynn <trflynn89@pm.me>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibUnicode/CurrencyCode.h>
+
+namespace Unicode {
+
+static auto const& ensure_currency_codes()
+{
+ // https://www.iso.org/iso-4217-currency-codes.html
+ // https://www.six-group.com/dam/download/financial-information/data-center/iso-currrency/amendments/lists/list_one.xml
+ static HashMap<StringView, CurrencyCode> currency_codes {
+ { "AED"sv, { 2 } },
+ { "AFN"sv, { 2 } },
+ { "ALL"sv, { 2 } },
+ { "AMD"sv, { 2 } },
+ { "ANG"sv, { 2 } },
+ { "AOA"sv, { 2 } },
+ { "ARS"sv, { 2 } },
+ { "AUD"sv, { 2 } },
+ { "AWG"sv, { 2 } },
+ { "AZN"sv, { 2 } },
+ { "BAM"sv, { 2 } },
+ { "BBD"sv, { 2 } },
+ { "BDT"sv, { 2 } },
+ { "BGN"sv, { 2 } },
+ { "BHD"sv, { 3 } },
+ { "BIF"sv, { 0 } },
+ { "BMD"sv, { 2 } },
+ { "BND"sv, { 2 } },
+ { "BOB"sv, { 2 } },
+ { "BOV"sv, { 2 } },
+ { "BRL"sv, { 2 } },
+ { "BSD"sv, { 2 } },
+ { "BTN"sv, { 2 } },
+ { "BWP"sv, { 2 } },
+ { "BYN"sv, { 2 } },
+ { "BZD"sv, { 2 } },
+ { "CAD"sv, { 2 } },
+ { "CDF"sv, { 2 } },
+ { "CHE"sv, { 2 } },
+ { "CHF"sv, { 2 } },
+ { "CHW"sv, { 2 } },
+ { "CLF"sv, { 4 } },
+ { "CLP"sv, { 0 } },
+ { "CNY"sv, { 2 } },
+ { "COP"sv, { 2 } },
+ { "COU"sv, { 2 } },
+ { "CRC"sv, { 2 } },
+ { "CUC"sv, { 2 } },
+ { "CUP"sv, { 2 } },
+ { "CVE"sv, { 2 } },
+ { "CZK"sv, { 2 } },
+ { "DJF"sv, { 0 } },
+ { "DKK"sv, { 2 } },
+ { "DOP"sv, { 2 } },
+ { "DZD"sv, { 2 } },
+ { "EGP"sv, { 2 } },
+ { "ERN"sv, { 2 } },
+ { "ETB"sv, { 2 } },
+ { "EUR"sv, { 2 } },
+ { "FJD"sv, { 2 } },
+ { "FKP"sv, { 2 } },
+ { "GBP"sv, { 2 } },
+ { "GEL"sv, { 2 } },
+ { "GHS"sv, { 2 } },
+ { "GIP"sv, { 2 } },
+ { "GMD"sv, { 2 } },
+ { "GNF"sv, { 0 } },
+ { "GTQ"sv, { 2 } },
+ { "GYD"sv, { 2 } },
+ { "HKD"sv, { 2 } },
+ { "HNL"sv, { 2 } },
+ { "HRK"sv, { 2 } },
+ { "HTG"sv, { 2 } },
+ { "HUF"sv, { 2 } },
+ { "IDR"sv, { 2 } },
+ { "ILS"sv, { 2 } },
+ { "INR"sv, { 2 } },
+ { "IQD"sv, { 3 } },
+ { "IRR"sv, { 2 } },
+ { "ISK"sv, { 0 } },
+ { "JMD"sv, { 2 } },
+ { "JOD"sv, { 3 } },
+ { "JPY"sv, { 0 } },
+ { "KES"sv, { 2 } },
+ { "KGS"sv, { 2 } },
+ { "KHR"sv, { 2 } },
+ { "KMF"sv, { 0 } },
+ { "KPW"sv, { 2 } },
+ { "KRW"sv, { 0 } },
+ { "KWD"sv, { 3 } },
+ { "KYD"sv, { 2 } },
+ { "KZT"sv, { 2 } },
+ { "LAK"sv, { 2 } },
+ { "LBP"sv, { 2 } },
+ { "LKR"sv, { 2 } },
+ { "LRD"sv, { 2 } },
+ { "LSL"sv, { 2 } },
+ { "LYD"sv, { 3 } },
+ { "MAD"sv, { 2 } },
+ { "MDL"sv, { 2 } },
+ { "MGA"sv, { 2 } },
+ { "MKD"sv, { 2 } },
+ { "MMK"sv, { 2 } },
+ { "MNT"sv, { 2 } },
+ { "MOP"sv, { 2 } },
+ { "MRU"sv, { 2 } },
+ { "MUR"sv, { 2 } },
+ { "MVR"sv, { 2 } },
+ { "MWK"sv, { 2 } },
+ { "MXN"sv, { 2 } },
+ { "MXV"sv, { 2 } },
+ { "MYR"sv, { 2 } },
+ { "MZN"sv, { 2 } },
+ { "NAD"sv, { 2 } },
+ { "NGN"sv, { 2 } },
+ { "NIO"sv, { 2 } },
+ { "NOK"sv, { 2 } },
+ { "NPR"sv, { 2 } },
+ { "NZD"sv, { 2 } },
+ { "OMR"sv, { 3 } },
+ { "PAB"sv, { 2 } },
+ { "PEN"sv, { 2 } },
+ { "PGK"sv, { 2 } },
+ { "PHP"sv, { 2 } },
+ { "PKR"sv, { 2 } },
+ { "PLN"sv, { 2 } },
+ { "PYG"sv, { 0 } },
+ { "QAR"sv, { 2 } },
+ { "RON"sv, { 2 } },
+ { "RSD"sv, { 2 } },
+ { "RUB"sv, { 2 } },
+ { "RWF"sv, { 0 } },
+ { "SAR"sv, { 2 } },
+ { "SBD"sv, { 2 } },
+ { "SCR"sv, { 2 } },
+ { "SDG"sv, { 2 } },
+ { "SEK"sv, { 2 } },
+ { "SGD"sv, { 2 } },
+ { "SHP"sv, { 2 } },
+ { "SLL"sv, { 2 } },
+ { "SOS"sv, { 2 } },
+ { "SRD"sv, { 2 } },
+ { "SSP"sv, { 2 } },
+ { "STN"sv, { 2 } },
+ { "SVC"sv, { 2 } },
+ { "SYP"sv, { 2 } },
+ { "SZL"sv, { 2 } },
+ { "THB"sv, { 2 } },
+ { "TJS"sv, { 2 } },
+ { "TMT"sv, { 2 } },
+ { "TND"sv, { 3 } },
+ { "TOP"sv, { 2 } },
+ { "TRY"sv, { 2 } },
+ { "TTD"sv, { 2 } },
+ { "TWD"sv, { 2 } },
+ { "TZS"sv, { 2 } },
+ { "UAH"sv, { 2 } },
+ { "UGX"sv, { 0 } },
+ { "USD"sv, { 2 } },
+ { "USN"sv, { 2 } },
+ { "UYI"sv, { 0 } },
+ { "UYU"sv, { 2 } },
+ { "UYW"sv, { 4 } },
+ { "UZS"sv, { 2 } },
+ { "VES"sv, { 2 } },
+ { "VND"sv, { 0 } },
+ { "VUV"sv, { 0 } },
+ { "WST"sv, { 2 } },
+ { "XAF"sv, { 0 } },
+ { "XAG"sv, { {} } },
+ { "XAU"sv, { {} } },
+ { "XBA"sv, { {} } },
+ { "XBB"sv, { {} } },
+ { "XBC"sv, { {} } },
+ { "XBD"sv, { {} } },
+ { "XCD"sv, { 2 } },
+ { "XDR"sv, { {} } },
+ { "XOF"sv, { 0 } },
+ { "XPD"sv, { {} } },
+ { "XPF"sv, { 0 } },
+ { "XPT"sv, { {} } },
+ { "XSU"sv, { {} } },
+ { "XTS"sv, { {} } },
+ { "XUA"sv, { {} } },
+ { "XXX"sv, { {} } },
+ { "YER"sv, { 2 } },
+ { "ZAR"sv, { 2 } },
+ { "ZMW"sv, { 2 } },
+ { "ZWL"sv, { 2 } },
+ };
+
+ return currency_codes;
+}
+
+Optional<CurrencyCode> get_currency_code(StringView currency)
+{
+ static auto const& currency_codes = ensure_currency_codes();
+ return currency_codes.get(currency);
+}
+
+}
diff --git a/Userland/Libraries/LibUnicode/CurrencyCode.h b/Userland/Libraries/LibUnicode/CurrencyCode.h
new file mode 100644
index 0000000000..1eb831e701
--- /dev/null
+++ b/Userland/Libraries/LibUnicode/CurrencyCode.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2021, Tim Flynn <trflynn89@pm.me>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/HashMap.h>
+#include <AK/Optional.h>
+#include <AK/StringView.h>
+
+namespace Unicode {
+
+struct CurrencyCode {
+ Optional<int> minor_unit {};
+};
+
+Optional<CurrencyCode> get_currency_code(StringView currency);
+
+}
diff --git a/Userland/Libraries/LibUnicode/Forward.h b/Userland/Libraries/LibUnicode/Forward.h
index 5d9dde274e..8d6c43e3ff 100644
--- a/Userland/Libraries/LibUnicode/Forward.h
+++ b/Userland/Libraries/LibUnicode/Forward.h
@@ -21,6 +21,7 @@ enum class Script : u8;
enum class Territory : u8;
enum class WordBreakProperty : u8;
+struct CurrencyCode;
struct Keyword;
struct LanguageID;
struct ListPatterns;