summaryrefslogtreecommitdiffstats
path: root/src/cppvalue.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cppvalue.cpp')
-rw-r--r--src/cppvalue.cpp45
1 files changed, 26 insertions, 19 deletions
diff --git a/src/cppvalue.cpp b/src/cppvalue.cpp
index 1543498..8cd7c5c 100644
--- a/src/cppvalue.cpp
+++ b/src/cppvalue.cpp
@@ -1,13 +1,10 @@
/******************************************************************************
*
- *
- *
- *
- * Copyright (C) 1997-2015 by Dimitri van Heesch.
+ * Copyright (C) 1997-2021 by Dimitri van Heesch.
*
* Permission to use, copy, modify, and distribute this software and its
- * documentation under the terms of the GNU General Public License is hereby
- * granted. No representations are made about the suitability of this software
+ * documentation under the terms of the GNU General Public License is hereby
+ * granted. No representations are made about the suitability of this software
* for any purpose. It is provided "as is" without express or implied warranty.
* See the GNU General Public License for more details.
*
@@ -21,40 +18,50 @@
#include "cppvalue.h"
#include "constexp.h"
-CPPValue parseOctal(const QCString& token)
+CPPValue parseOctal(const std::string& token)
{
long val = 0;
- for (const char *p = token.data(); *p != 0; p++)
+ for (const char *p = token.c_str(); *p != 0; p++)
{
if (*p >= '0' && *p <= '7') val = val * 8 + *p - '0';
}
return CPPValue(val);
}
-CPPValue parseDecimal(const QCString& token)
+CPPValue parseDecimal(const std::string& token)
{
long val = 0;
- for (const char *p = token.data(); *p != 0; p++)
+ for (const char *p = token.c_str(); *p != 0; p++)
{
if (*p >= '0' && *p <= '9') val = val * 10 + *p - '0';
}
return CPPValue(val);
}
-CPPValue parseHexadecimal(const QCString& token)
+CPPValue parseHexadecimal(const std::string& token)
{
long val = 0;
- for (const char *p = token.data(); *p != 0; p++)
+ for (const char *p = token.c_str(); *p != 0; p++)
{
if (*p >= '0' && *p <= '9') val = val * 16 + *p - '0';
else if (*p >= 'a' && *p <= 'f') val = val * 16 + *p - 'a' + 10;
else if (*p >= 'A' && *p <= 'F') val = val * 16 + *p - 'A' + 10;
}
- //printf("parseHexadecimal %s->%x\n",token.data(),val);
+ //printf("parseHexadecimal %s->%x\n",qPrint(token),val);
+ return CPPValue(val);
+}
+
+CPPValue parseBinary(const std::string& token)
+{
+ long val = 0;
+ for (const char *p = token.c_str(); *p != 0; p++)
+ {
+ if (*p >= '0' && *p <= '1') val = val * 2 + *p - '0';
+ }
return CPPValue(val);
}
-CPPValue parseCharacter(const QCString& token) // does not work for '\n' and the alike
+CPPValue parseCharacter(const std::string& token) // does not work for '\n' and the alike
{
if (token[1]=='\\')
{
@@ -80,16 +87,16 @@ CPPValue parseCharacter(const QCString& token) // does not work for '\n' and the
case '6': // fall through
case '7': // fall through
return parseOctal(token);
- case 'x':
+ case 'x':
case 'X': return parseHexadecimal(token);
- default: printf("Invalid escape sequence %s found!\n",token.data());
- return CPPValue(0L);
+ default: printf("Invalid escape sequence %s found!\n",token.c_str());
+ return CPPValue(0L);
}
}
return CPPValue((long)token[1]);
}
-CPPValue parseFloat(const QCString& token)
+CPPValue parseFloat(const std::string& token)
{
- return CPPValue(atof(token));
+ return CPPValue(std::stod(token));
}