12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
- /*
- * utils.cc
- * Copyright (C) 2016 Unknown <francois@gautrais.eu>
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
- #include "utils.h"
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include <sstream>
- 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<std::string> &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<std::string> split(const std::string &s, char delim) {
- std::vector<std::string> elems;
- split(s, delim, elems);
- return elems;
- }
|