File tree Expand file tree Collapse file tree 4 files changed +51
-54
lines changed
Expand file tree Collapse file tree 4 files changed +51
-54
lines changed Original file line number Diff line number Diff line change @@ -205,7 +205,7 @@ static const Signaltype listofsignals[] = {
205205 * \return size of array
206206 * */
207207template <typename T, int size>
208- int GetArrayLength (const T (&)[size])
208+ size_t GetArrayLength (const T (&)[size])
209209{
210210 return size;
211211}
Original file line number Diff line number Diff line change 2121#include " mathlib.h"
2222#include " errorlogger.h"
2323
24- #include < string>
25- #include < sstream>
26- #include < cstdlib>
2724#include < cmath>
2825#include < cctype>
2926#include < limits>
3027
31- MathLib::bigint MathLib::toLongNumber (const std::string &str)
32- {
33- // hexadecimal numbers:
34- if (isHex (str)) {
35- if (str[0 ] == ' -' ) {
36- bigint ret = 0 ;
37- std::istringstream istr (str);
38- istr >> std::hex >> ret;
39- return ret;
40- } else {
41- unsigned long long ret = 0 ;
42- std::istringstream istr (str);
43- istr >> std::hex >> ret;
44- return (bigint)ret;
45- }
46- }
47-
48- // octal numbers:
49- if (isOct (str)) {
50- bigint ret = 0 ;
51- std::istringstream istr (str);
52- istr >> std::oct >> ret;
53- return ret;
54- }
55-
56- // binary numbers:
57- if (isBin (str)) {
58- bigint ret = 0 ;
59- for (std::string::size_type i = str[0 ] == ' 0' ?2 :3 ; i < str.length (); i++) {
60- ret <<= 1 ;
61- if (str[i] == ' 1' )
62- ret |= 1 ;
63- }
64- if (str[0 ] == ' -' )
65- ret = -ret;
66- return ret;
67- }
68-
69- if (isFloat (str))
70- return static_cast <bigint>(std::atof (str.c_str ()));
71-
72- bigint ret = 0 ;
73- std::istringstream istr (str);
74- istr >> ret;
75- return ret;
76- }
77-
7828double MathLib::toDoubleNumber (const std::string &str)
7929{
8030 if (isHex (str))
Original file line number Diff line number Diff line change 2121#define mathlibH
2222// ---------------------------------------------------------------------------
2323
24+ #include < cstdlib>
2425#include < string>
2526#include < sstream>
2627#include " config.h"
@@ -35,7 +36,53 @@ class CPPCHECKLIB MathLib {
3536 typedef long long bigint;
3637 typedef unsigned long long biguint;
3738
38- static bigint toLongNumber (const std::string & str);
39+ template < class T = bigint >
40+ static T toLongNumber (const std::string & str) {
41+ // hexadecimal numbers:
42+ if (isHex (str)) {
43+ if (str[0 ] == ' -' ) {
44+ T ret = 0 ;
45+ std::istringstream istr (str);
46+ istr >> std::hex >> ret;
47+ return ret;
48+ } else {
49+ unsigned long long ret = 0 ;
50+ std::istringstream istr (str);
51+ istr >> std::hex >> ret;
52+ return (T)ret;
53+ }
54+ }
55+
56+ // octal numbers:
57+ if (isOct (str)) {
58+ T ret = 0 ;
59+ std::istringstream istr (str);
60+ istr >> std::oct >> ret;
61+ return ret;
62+ }
63+
64+ // binary numbers:
65+ if (isBin (str)) {
66+ T ret = 0 ;
67+ for (std::string::size_type i = str[0 ] == ' 0' ?2 :3 ; i < str.length (); i++) {
68+ ret <<= 1 ;
69+ if (str[i] == ' 1' )
70+ ret |= 1 ;
71+ }
72+ if (str[0 ] == ' -' )
73+ ret = -ret;
74+ return ret;
75+ }
76+
77+ if (isFloat (str))
78+ return static_cast <T>(std::atof (str.c_str ()));
79+
80+ T ret = 0 ;
81+ std::istringstream istr (str);
82+ istr >> ret;
83+ return ret;
84+ }
85+
3986 template <class T > static std::string toString (T value) {
4087 std::ostringstream result;
4188 result << value;
Original file line number Diff line number Diff line change @@ -803,8 +803,8 @@ static bool isLowerEqualThanMulDiv(const Token* lower)
803803template <typename T>
804804std::string typeCorrectShift (const char cop, const Token* left, const Token* right)
805805{
806- const T leftInt=MathLib::toLongNumber (left->str ());
807- const T rightInt=MathLib::toLongNumber (right->str ());
806+ const T leftInt=MathLib::toLongNumber<T> (left->str ());
807+ const T rightInt=MathLib::toLongNumber<T> (right->str ());
808808
809809 if (cop == ' &' || cop == ' |' || cop == ' ^' )
810810 return MathLib::calculate (left->str (), right->str (), cop);
You can’t perform that action at this time.
0 commit comments