Skip to content

Commit

Permalink
fix: handle string representation for base in toString method
Browse files Browse the repository at this point in the history
- Check if the argument is a string representation for the base.
- Set base to 16 if the argument is "hex".
  • Loading branch information
nnnoel committed Aug 31, 2023
1 parent 9e90739 commit fc1f41f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions cpp/MGBigNumberHostObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,16 @@ namespace margelo
std::shared_ptr<MGBigNumber> thiz = thisValue.getObject(runtime).getHostObject<MGBigNumber>(runtime);

int base = 10;
if (!arguments[0].isUndefined() && arguments[0].isNumber())
{
base = (int)arguments[0].asNumber();
if (!arguments[0].isUndefined()) {
if (arguments[0].isNumber()) {
base = (int)arguments[0].asNumber();

Check failure on line 338 in cpp/MGBigNumberHostObject.cpp

View workflow job for this annotation

GitHub Actions / cpplint

[cpplint] reported by reviewdog 🐶 Using C-style cast. Use static_cast<int>(...) instead [readability/casting] [4] Raw Output: cpp/MGBigNumberHostObject.cpp:338: Using C-style cast. Use static_cast<int>(...) instead [readability/casting] [4]
} else if (arguments[0].isString()) {
std::string argValue = arguments[0].getString(runtime).utf8(runtime);
if (argValue == "hex") {
base = 16;
}
// TODO: Add more conditions here if you support other string representations for bases.
}
}
int len = -1;
if (!arguments[1].isUndefined())
Expand Down

0 comments on commit fc1f41f

Please sign in to comment.