/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ /* * utils.cc * Copyright (C) 2016 Unknown * * histodex is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * histodex is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ #include "utils.h" #include #include #include #include std::string tstr(const char* x) { return std::string(x); } std::string tstr(int x) { char tmp[64]; sprintf(tmp, "%d", x); return std::string(tmp); } void split(const std::string &s, char delim, std::vector &elems) { std::stringstream ss; ss.str(s); std::string item; while (std::getline(ss, item, delim)) { elems.push_back(item); } } std::string tstr(double x, int n) { char sn[16], tmp[64]; sprintf(sn, "%%0.%df", n); sprintf(tmp, sn, x); return tstr(tmp); } std::vector split(const std::string &s, char delim) { std::vector elems; split(s, delim, elems); return elems; }