]> git.mxchange.org Git - simgear.git/blob - Lib/Misc/fgpath.cxx
Fixed an IRIX warning message where an inline function is referenced
[simgear.git] / Lib / Misc / fgpath.cxx
1 //
2 // fgpath.cxx -- routines to abstract out path separator differences
3 //               between MacOS and the rest of the world
4 //
5 // Written by Curtis L. Olson, started April 1999.
6 //
7 // Copyright (C) 1999  Curtis L. Olson - curt@flightgear.org
8 //
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of the
12 // License, or (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 // General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 //
23 // $Id$
24
25
26 #include "fgpath.hxx"
27
28
29 // If Unix, replace all ":" with "/".  If MacOS, replace all "/" with
30 // ":" it should go without saying that neither of these characters
31 // should be used in file or directory names.
32
33 static string fix_path( const string path ) {
34     string result = path;
35
36     for ( int i = 0; i < (int)path.size(); ++i ) {
37         if ( result[i] == FG_BAD_PATH_SEP ) {
38             result[i] = FG_PATH_SEP;
39         }
40     }
41
42     return result;
43 }
44
45
46 // default constructor
47 FGPath::FGPath() {
48     path = "";
49 }
50
51
52 // create a path based on "path"
53 FGPath::FGPath( const string p ) {
54     set( p );
55 }
56
57
58 // destructor
59 FGPath::~FGPath() {
60 }
61
62
63 // set path
64 void FGPath::set( const string p ) {
65     path = fix_path( p );
66 }
67
68
69 // append another piece to the existing path
70 void FGPath::append( const string p ) {
71     string part = fix_path( p );
72
73     if ( path.size() == 0 ) {
74         path = part;
75     } else {
76         if ( part[0] != FG_PATH_SEP ) {
77             path += FG_PATH_SEP;
78         }
79         path += part;
80     }
81 }
82
83
84 // concatenate a string to the end of the path without inserting a
85 // path separator
86 void FGPath::concat( const string p ) {
87     string part = fix_path( p );
88
89     if ( path.size() == 0 ) {
90         path = part;
91     } else {
92         path += part;
93     }
94 }