2
// flnfc_common.cxx -- common string subs for Fl_Native_File_Chooser
4
// Copyright 2004 by Greg Ercolano.
6
// This library is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU Library General Public
8
// License as published by the Free Software Foundation; either
9
// version 2 of the License, or (at your option) any later version.
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
// Library General Public License for more details.
16
// You should have received a copy of the GNU Library General Public
17
// License along with this library; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21
// Please keep code 80 column compliant.
23
// 10 20 30 40 50 60 70
25
// 4567890123456789012345678901234567890123456789012345678901234567890123456789
30
// COPY A STRING WITH 'new'
33
static char *strnew(const char *val) {
34
if ( val == NULL ) return(NULL);
35
char *s = new char[strlen(val)+1];
40
// FREE STRING CREATED WITH strnew(), NULLS OUT STRING
43
static char *strfree(char *val) {
44
if ( val ) delete [] val;
48
// 'DYNAMICALLY' APPEND ONE STRING TO ANOTHER
49
// Returns newly allocated string, or NULL
50
// if s && val == NULL.
51
// 's' can be NULL; returns a strnew(val).
52
// 'val' can be NULL; s is returned unmodified.
55
// char *s = strnew("foo"); // s = "foo"
56
// s = strapp(s, "bar"); // s = "foobar"
58
static char *strapp(char *s, const char *val) {
60
return(s); // Nothing to append? return s
63
return(strnew(val)); // New string? return copy of val
65
char *news = new char[strlen(s)+strlen(val)+1];
68
delete [] s; // delete old string
69
return(news); // return new copy
72
// APPEND A CHARACTER TO A STRING
73
// This does NOT allocate space for the new character.
75
static void chrcat(char *s, char c) {
76
char tmp[2] = { c, '\0' };