39 PvlFormat::PvlFormat() {
52 PvlFormat::PvlFormat(
const QString &file) {
65 PvlFormat::PvlFormat(Pvl &keywordType) {
72 void PvlFormat::init() {
74 m_keywordMapFile.clear();
84 void PvlFormat::add(
const QString &file) {
85 m_keywordMapFile = file;
92 catch(IException &e) {
94 msg +=
"Unable to open or read keyword to type mapping file [";
96 throw IException(e, IException::Programmer, msg,
_FILEINFO_);
106 void PvlFormat::add(Pvl &pvl) {
107 for(
int i = 0; i < pvl.keywords(); ++i) {
108 PvlKeyword &key = pvl[i];
109 QString name = key.name().toUpper();
110 QString type = key[0].toUpper();
111 PvlKeyword newKey(name, type);
112 for(
int j = 1; j < key.size(); ++j) newKey.addValue(key[j]);
114 if (m_keywordMap.hasKeyword(name)) {
115 m_keywordMap.deleteKeyword(name);
117 m_keywordMap.addKeyword(newKey);
127 KeywordType PvlFormat::type(
const PvlKeyword &keyword) {
128 QString name = keyword.name().toUpper();
129 if(m_keywordMap.hasKeyword(name)) {
130 PvlKeyword &key = m_keywordMap.findKeyword(name);
133 return NoTypeKeyword;
145 int PvlFormat::accuracy(
const PvlKeyword &keyword) {
146 QString name = keyword.name().toUpper();
147 if(m_keywordMap.hasKeyword(name)) {
148 PvlKeyword &key = m_keywordMap.findKeyword(name);
150 return toInt(key[1]);
163 QString PvlFormat::formatValue(
const PvlKeyword &keyword,
int num) {
169 bool singleUnit = isSingleUnit(keyword);
172 if(num >= keyword.size()) {
177 if(keyword[num].size() == 0) {
184 val = addQuotes(val);
187 if((keyword.size() > 1) && (num == 0)) {
192 if((!singleUnit) && (keyword.unit(num).size() > 0)) {
193 val +=
" <" + keyword.unit(num) +
">";
197 if(num != keyword.size() - 1) {
201 else if(keyword.size() > 1) {
206 if((singleUnit) && (num == keyword.size() - 1) &&
207 (keyword.unit(num).size() > 0)) {
208 val +=
" <" + keyword.unit(num) +
">";
220 QString PvlFormat::formatName(
const PvlKeyword &keyword) {
221 return keyword.name();
231 QString PvlFormat::formatEnd(
const QString name,
232 const PvlKeyword &keyword) {
233 return "End_" + formatName(keyword);
243 QString PvlFormat::addQuotes(
const QString value) {
246 bool needQuotes =
false;
249 char existingQuoteType =
'\0';
250 for (
int pos = 0; !needQuotes && pos < val.size(); pos++) {
254 if (val[pos] ==
'(' || val[pos] ==
'{') {
257 if (val[pos] ==
'(') {
258 closePos = val.indexOf(
')');
260 if (val[pos] ==
'{') {
261 closePos = val.indexOf(
'}');
265 if (closePos == -1 || closePos != val.size() - 1) {
274 if (val[pos] ==
' ' || val[pos] ==
'(' ||
275 val[pos] ==
'(' || val[pos] ==
')' ||
276 val[pos] ==
'{' || val[pos] ==
'}' ||
277 val[pos] ==
',' || val[pos] ==
'=') {
281 if (pos == val.size() - 1 && val[pos] ==
'-') {
286 if (existingQuoteType ==
'\0') {
287 if (val[pos] ==
'"') {
288 existingQuoteType =
'"';
290 else if (val[pos] ==
'\'') {
291 existingQuoteType =
'\'';
296 if (val[pos] ==
'"' || val[pos] ==
'\'') {
297 val[pos] = existingQuoteType;
303 char quoteValue =
'"';
305 if(existingQuoteType ==
'"') {
310 val = quoteValue + val + quoteValue;
326 bool singleUnit =
true;
327 for(
int i = 0; i < keyword.
size(); i ++) {
QString unit(const int index=0) const
Returns the units of measurement of the element of the array of values for the object at the specifie...
int toInt(const QString &string)
Global function to convert from a string to an integer.
Namespace for the standard library.
static bool stringEqual(const QString &string1, const QString &string2)
Checks to see if two QStrings are equal.
int size() const
Returns the number of values stored in this keyword.
KeywordType toKeywordType(const QString type)
Convert a string representing a type of keyword to the corresponding enumeration. ...
#define _FILEINFO_
Macro for the filename and line number.
A single keyword-value pair.
Container for cube-like labels.
KeywordType
The different types of keywords that can be formatted.
Namespace for ISIS/Bullet specific routines.