diff options
Diffstat (limited to 'dviware/dvisvgm/src/utility.hpp')
-rw-r--r-- | dviware/dvisvgm/src/utility.hpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/dviware/dvisvgm/src/utility.hpp b/dviware/dvisvgm/src/utility.hpp index 7127280284..7ad3bc8d69 100644 --- a/dviware/dvisvgm/src/utility.hpp +++ b/dviware/dvisvgm/src/utility.hpp @@ -2,7 +2,7 @@ ** utility.hpp ** ** ** ** This file is part of dvisvgm -- a fast DVI to SVG converter ** -** Copyright (C) 2005-2019 Martin Gieseking <martin.gieseking@uos.de> ** +** Copyright (C) 2005-2020 Martin Gieseking <martin.gieseking@uos.de> ** ** ** ** This program is free software; you can redistribute it and/or ** ** modify it under the terms of the GNU General Public License as ** @@ -88,10 +88,12 @@ std::vector<uint8_t> bytes (T val, int n=0) { * the result to the range starting at 'dest'. * @param[in] first initial position of the range to be encoded * @param[in] last final position of the range to be encoded - * @param[in] dest first position of the destination range */ + * @param[in] dest first position of the destination range + * @param[in] wrap if > 0, add a newline after the given number of characters written */ template <typename InputIterator, typename OutputIterator> -void base64_copy (InputIterator first, InputIterator last, OutputIterator dest) { +void base64_copy (InputIterator first, InputIterator last, OutputIterator dest, int wrap=0) { static const char *base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + int count=0; while (first != last) { int padding = 0; unsigned char c0 = *first++, c1=0, c2=0; @@ -106,15 +108,29 @@ void base64_copy (InputIterator first, InputIterator last, OutputIterator dest) } uint32_t n = (c0 << 16) | (c1 << 8) | c2; for (int i=0; i <= 3-padding; i++) { + if (wrap > 0 && ++count > wrap) { + count = 1; + *dest++ = '\n'; + } *dest++ = base64_chars[(n >> 18) & 0x3f]; n <<= 6; } - while (padding--) + while (padding--) { + if (wrap > 0 && ++count > wrap) { + count = 1; + *dest++ = '\n'; + } *dest++ = '='; + } } } +inline void base64_copy (std::istream &is, std::ostream &os, int wrap=0) { + base64_copy(std::istreambuf_iterator<char>(is), std::istreambuf_iterator<char>(), std::ostreambuf_iterator<char>(os), wrap); +} + + /** Simple implementation mimicking std::make_unique introduced in C++14. * Constructs an object of class T on the heap and returns a unique_ptr<T> to it. * @param[in] args arguments forwarded to an constructor of T */ |