MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / to_int

Method to_int

modules/gui/gui/src/backend/text_server/ustring.cpp:2769–2798  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2767}
2768
2769int64_t String::to_int() const
2770{
2771 if (length() == 0)
2772 {
2773 return 0;
2774 }
2775
2776 int to = (find(".") >= 0) ? find(".") : length();
2777
2778 int64_t integer = 0;
2779 int64_t sign = 1;
2780
2781 for (int i = 0; i < to; i++)
2782 {
2783 char32_t c = operator[](i);
2784 if (is_digit(c))
2785 {
2786 bool overflow = (integer > INT64_MAX / 10) || (integer == INT64_MAX / 10 && ((sign == 1 && c > '7') || (sign == -1 && c > '8')));
2787 ERR_FAIL_COND_V_MSG(overflow, sign == 1 ? INT64_MAX : INT64_MIN, "Cannot represent " + *this + " as a 64-bit signed integer, since the value is " + (sign == 1 ? "too large." : "too small."));
2788 integer *= 10;
2789 integer += c - '0';
2790 }
2791 else if (integer == 0 && c == '-')
2792 {
2793 sign = -sign;
2794 }
2795 }
2796
2797 return integer * sign;
2798}
2799
2800int64_t String::to_int(const char* p_str, int p_len)
2801{

Callers 2

parse_urlMethod · 0.45
is_valid_ip_addressMethod · 0.45

Calls 5

is_digitFunction · 0.85
StringClass · 0.70
lengthFunction · 0.50
findFunction · 0.50
substrMethod · 0.45

Tested by

no test coverage detected