Currency to_currency(std::string const& code) { Currency currency; if (!to_currency(currency, code)) currency = noCurrency(); return currency; }
IOU Account::operator[](std::string const& s) const { auto const currency = to_currency(s); assert(currency != noCurrency()); return IOU(*this, currency); }
std::string to_string(Currency const& currency) { static Currency const sIsoBits ("FFFFFFFFFFFFFFFFFFFFFFFF000000FFFFFFFFFF"); // Characters we are willing to allow in the ASCII representation of a // three-letter currency code. static std::string const allowed_characters = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789" "<>(){}[]|?!@#$%^&*"; if (currency == zero) return systemCurrencyCode(); if (currency == vbcCurrency()) return systemCurrencyCodeVBC(); if (currency == noCurrency()) return "1"; if ((currency & sIsoBits).isZero ()) { // The offset of the 3 character ISO code in the currency descriptor int const isoOffset = 12; std::string const iso( currency.data () + isoOffset, currency.data () + isoOffset + 3); // Specifying the system currency code using ISO-style representation // is not allowed. if ((iso != systemCurrencyCode()) && (iso != systemCurrencyCodeVBC()) && (iso.find_first_not_of (allowed_characters) == std::string::npos)) { return iso; } } return strHex (currency.begin (), currency.size ()); }