2
* Copyright (C) 2002,2003 Ralf Westram
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License along
15
* with this program; if not, write to the Free Software Foundation, Inc.,
16
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18
* $Id: tools.cc,v 1.4 2003/10/30 19:52:31 reallysoft Exp $
31
string px::concat_paths (const string& path, const string& filename)
33
// concatenate path and filename (or relative subpath)
35
path.substr(0, path.find_last_not_of (PathSeparator)+1) +
37
filename.substr(filename.find_first_not_of (PathSeparator));
40
bool px::split_path (const string& path, string* dir_part, string* filename_part)
42
size_t lslash = path.find_last_of (PathSeparator);
43
if (lslash == path.length()-1) // trailing slash
44
return split_path(path.substr(0, lslash), dir_part, filename_part);
46
if (lslash == string::npos)
49
size_t lnslash = path.find_last_not_of (PathSeparator, lslash);
51
if (dir_part) *dir_part = path.substr(0, lnslash+1);
52
if (filename_part) *filename_part = path.substr(lslash+1);
58
string vstrf(const char *format, va_list argPtr) {
59
static size_t buf_size = 128;
60
static char *buffer = new char[buf_size];
65
assert(buffer); // to stop when debugging
66
return "<alloc problem>";
69
length = vsnprintf(buffer, buf_size, format, argPtr);
70
if (length < buf_size) break; // string fits into current buffer
72
// otherwise resize buffer :
73
buf_size += buf_size/2;
74
// fprintf(stderr, "Reallocating vstrf-buffer to size=%u\n", buf_size);
76
buffer = new char[buf_size];
79
return string(buffer, length);
83
string px::strf(const char *format, ...)
86
va_start(argPtr, format);
87
string result = vstrf(format, argPtr);