| Index: compiled/String.h |
| =================================================================== |
| --- a/compiled/String.h |
| +++ b/compiled/String.h |
| @@ -12,19 +12,20 @@ |
| * GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License |
| * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| */ |
| #pragma once |
| +#include <algorithm> |
| #include <cstddef> |
| #include <cstring> |
| -#include <algorithm> |
| +#include <type_traits> |
| #include <emscripten.h> |
| #include "debug.h" |
| inline void String_assert_readonly(bool readOnly); |
| class String |
| @@ -352,9 +353,38 @@ public: |
| { |
| append(str.mBuf, str.length()); |
| } |
| void append(value_type c) |
| { |
| append(&c, 1); |
| } |
| + |
| + template<typename T, |
| + typename std::enable_if<std::is_integral<T>::value>::type* = nullptr> |
| + void append(T num) |
| + { |
| + bool negative = false; |
| + if (num < 0) |
| + { |
| + negative = true; |
| + num = -num; |
| + } |
| + |
| + size_type size = 0; |
| + for (int i = num; i; i /= 10) |
| + size++; |
| + size = (size ? size : 1); |
| + |
| + size_type pos = length(); |
| + grow((negative ? 1 : 0) + size); |
| + |
| + if (negative) |
| + mBuf[pos++] = '-'; |
| + |
| + for (int i = size - 1; i >= 0; i--) |
| + { |
| + mBuf[pos + i] = '0' + (num % 10); |
| + num /= 10; |
| + } |
| + } |
| }; |