MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / evaluateString

Function evaluateString

src/bzfs/bzfs.cpp:1733–1799  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1731
1732
1733static std::string evaluateString(const std::string& raw) {
1734 std::string eval;
1735 const int rawLen = (int)raw.size();
1736 for (int i = 0; i < rawLen; i++) {
1737 char current = raw[i];
1738 if (current != '\\') {
1739 eval += current;
1740 }
1741 else {
1742 char next = raw[i + 1];
1743 switch (next) {
1744 case '\\' : {
1745 eval += '\\';
1746 i++;
1747 break;
1748 }
1749 case 'n' : {
1750 eval += "\\n";
1751 i++;
1752 break;
1753 }
1754 case '{' : {
1755 unsigned int start = (i + 2);
1756 std::string::size_type end = raw.find_first_of('}', start);
1757 if (end == std::string::npos) {
1758 i = rawLen; // unterminated, ignore the rest of the string
1759 }
1760 else {
1761 const std::string var = raw.substr(start, end - start);
1762 i += (end - start) + 2;
1763 if (BZDB.isSet(var)) {
1764 eval += BZDB.get(var);
1765 }
1766 else {
1767 eval += "*BADBZDB*";
1768 }
1769 }
1770 break;
1771 }
1772 case '(' : {
1773 unsigned int start = (i + 2);
1774 std::string::size_type end = raw.find_first_of(')', start);
1775 if (end == std::string::npos) {
1776 i = rawLen; // unterminated, ignore the rest of the string
1777 }
1778 else {
1779 const std::string var = raw.substr(start, end - start);
1780 i += (end - start) + 2;
1781 if (var == "uptime") {
1782 char buffer[16];
1783 const float uptime = (float)(BzTime::getCurrent() - BzTime::getStartTime());
1784 snprintf(buffer, 16, "%i", (int)uptime);
1785 eval += buffer;
1786 }
1787 else {
1788 eval += "*BADVAR*";
1789 }
1790 }

Callers 2

addPlayerFunction · 0.85
doTextBroadcastsFunction · 0.85

Calls 3

isSetMethod · 0.80
sizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected