File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -113,10 +113,19 @@ namespace rift {
113
113
114
114
// If either value is a string, repeat it n times, where n is the second value.
115
115
if (isString () || other.isString ()) {
116
+ // make sure only one of them is a string
117
+ if (isString () && other.isString ()) {
118
+ return string (" <error: multiplication of strings>" );
119
+ }
120
+
121
+ // figure out which one is string
122
+ const Value &str = isString () ? *this : other;
123
+ const Value &num = isString () ? other : *this ;
124
+
125
+ // repeat the string n times
116
126
std::string result;
117
- auto count = other.isInteger () ? other.toInteger () : static_cast <int >(other.toFloat ());
118
- for (int i = 0 ; i < count; ++i) {
119
- result += isString () ? getString () : other.getString ();
127
+ for (int i = 0 ; i < num.toInteger (); ++i) {
128
+ result += str.toString ();
120
129
}
121
130
return string (std::move (result));
122
131
}
Original file line number Diff line number Diff line change @@ -94,6 +94,7 @@ int main() {
94
94
RIFT_TEST_CASE (" {$'string interpolation: {2 + 2}'}" , " string interpolation: 4" );
95
95
RIFT_TEST_CASE (" {float('3.14')} {int('100')} {str(3.1415926)} {int('ABC')}" , " 3.14 100 3.14 NaN" );
96
96
RIFT_TEST_CASE (" {precision(float('3.149268') * 1.5, 6)}" , " 4.723902" );
97
+ RIFT_TEST_CASE (" {'*' * 5} {4 * '*'} {'*' * 3.0} {2.0 * '*'}" , " ***** **** *** **" );
97
98
}
98
99
99
100
// Show the results
You can’t perform that action at this time.
0 commit comments