MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / StringToMoney

Function StringToMoney

src/openrct2/localisation/Currency.cpp:59–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57 }
58
59 money64 StringToMoney(const char* string_to_monetise)
60 {
61 const char* decimal_char = LanguageGetString(STR_LOCALE_DECIMAL_POINT);
62 const CurrencyDescriptor* currencyDesc = &CurrencyDescriptors[EnumValue(Config::Get().general.currencyFormat)];
63 char processedString[128] = {};
64
65 Guard::Assert(strlen(string_to_monetise) < sizeof(processedString));
66
67 uint32_t numNumbers = 0;
68 bool hasMinus = false;
69 bool hasDecSep = false;
70 const char* src_ptr = string_to_monetise;
71 char* dst_ptr = processedString;
72
73 // Process the string, keeping only numbers decimal, and minus sign(s).
74 while (*src_ptr != '\0')
75 {
76 if (*src_ptr >= '0' && *src_ptr <= '9')
77 {
78 numNumbers++;
79 }
80 else if (*src_ptr == decimal_char[0])
81 {
82 if (hasDecSep)
83 return kMoney64Undefined;
84 hasDecSep = true;
85
86 // Replace localised decimal separator with an English one.
87 *dst_ptr++ = '.';
88 src_ptr++;
89 continue;
90 }
91 else if (*src_ptr == '-')
92 {
93 if (hasMinus)
94 return kMoney64Undefined;
95 hasMinus = true;
96 }
97 else
98 {
99 // Skip invalid characters.
100 src_ptr++;
101 continue;
102 }
103
104 // Copy numeric values.
105 *dst_ptr++ = *src_ptr;
106 src_ptr++;
107 }
108
109 // Terminate destination string.
110 *dst_ptr = '\0';
111
112 if (numNumbers == 0)
113 return kMoney64Undefined;
114
115 if (hasMinus && processedString[0] != '-')
116 {

Callers 3

IncomeOnTextInputMethod · 0.85
onTextInputPriceMethod · 0.85
onTextInputMethod · 0.85

Calls 4

LanguageGetStringFunction · 0.85
EnumValueFunction · 0.85
AssertFunction · 0.85
ToMoney64FromGBPFunction · 0.85

Tested by

no test coverage detected