1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
/*
VOTable common functions
Copyright © 2018 F.Hroch (hroch@physics.muni.cz)
This file is part of Munipack.
Munipack 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.
Munipack 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 Munipack. If not, see <http://www.gnu.org/licenses/>.
*/
#include "votable.h"
#include <wx/wx.h>
#include <wx/regex.h>
#include <wx/filename.h>
// ------------------------------------------------------------------
// Common functions
// it would be nice to create a fortran I/O interoperability functions
// (library)?
wxString GetString(const wxString& line)
{
wxRegEx re(".+ = '(.*)'");
// double quotes in string: "'(''|[^'])*'" - perhaps unfunctional
// wxRegEx re(".+ = '(''|[^']*)'");
wxASSERT(re.IsValid());
if( re.Matches(line) )
return re.GetMatch(line,1);
else
return "";
}
double GetDouble(const wxString& line)
{
double x;
wxString a = line.AfterFirst('=');
if( a.ToCDouble(&x) )
return x;
wxLogFatalError("Failed to read the number: "+a);
return 666; // formally
}
long GetLong(const wxString& line)
{
long l;
wxString a = line.AfterFirst('=');
if( a.ToCLong(&l) )
return l;
wxLogFatalError("Failed to read the number: "+a);
return 0; // formally
}
bool GetBool(const wxString& line)
{
wxRegEx re(".+ = (.*)");
wxASSERT(re.IsValid());
if( re.Matches(line) ) {
wxString a = re.GetMatch(line,1);
a.Upper();
if( a.StartsWith("T") )
return true;
else if( a.StartsWith("F") )
return false;
}
wxLogFatalError("Failed to parse boolean (logical) expression: `"+line+"'.");
return false; // formally
}
wxString GetFileType(const wxString& output)
{
// determine file type of output by suffix
wxString type;
if( ! output.IsEmpty() ) {
wxFileName fn(output);
if( fn.IsOk() )
type = fn.GetExt().Upper();
}
return type;
}
|