Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_Common/ExpandingString.h
Views: 1798
/*1This program is free software: you can redistribute it and/or modify2it under the terms of the GNU General Public License as published by3the Free Software Foundation, either version 3 of the License, or4(at your option) any later version.56This program is distributed in the hope that it will be useful,7but WITHOUT ANY WARRANTY; without even the implied warranty of8MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9GNU General Public License for more details.1011You should have received a copy of the GNU General Public License12along with this program. If not, see <http://www.gnu.org/licenses/>.13*/14/*15expanding string for easy construction of text buffers16*/1718#pragma once1920#include <AP_Common/AP_Common.h>2122#include <stdint.h>2324class ExpandingString {25public:26ExpandingString() : buf(0), buflen(0), used(0), allocation_failed(false), external_buffer(false) {}27ExpandingString(char* s, uint32_t total_len);2829const char *get_string(void) const {30return buf;31}32uint32_t get_length(void) const {33return used;34}35char *get_writeable_string(void) const {36return buf;37}3839// print into the string40void printf(const char *format, ...) FMT_PRINTF(2,3);4142// append data to the string. s can be null for zero fill43bool append(const char *s, uint32_t len);4445// set address to custom external buffer46void set_buffer(char *s, uint32_t total_len, uint32_t used_len);47// zero out the string48void reset() { used = 0; }4950// destructor51~ExpandingString();5253bool has_failed_allocation() const {54return allocation_failed;55}5657private:58char *buf;59uint32_t buflen;60uint32_t used;61bool allocation_failed;62bool external_buffer;6364// try to expand the buffer65bool expand(uint32_t min_needed) WARN_IF_UNUSED;66};676869