11#include "PvlKeyword.h"
23 PvlFormat::PvlFormat() {
36 PvlFormat::PvlFormat(
const QString &file) {
49 PvlFormat::PvlFormat(Pvl &keywordType) {
58 m_keywordMapFile.clear();
68 void PvlFormat::add(
const QString &file) {
69 m_keywordMapFile = file;
76 catch(IException &e) {
78 msg +=
"Unable to open or read keyword to type mapping file [";
90 void PvlFormat::add(Pvl &pvl) {
91 for(
int i = 0; i < pvl.keywords(); ++i) {
92 PvlKeyword &key = pvl[i];
93 QString name = key.name().toUpper();
94 QString type = key[0].toUpper();
95 PvlKeyword newKey(name, type);
96 for(
int j = 1; j < key.size(); ++j) newKey.addValue(key[j]);
111 KeywordType PvlFormat::type(
const PvlKeyword &keyword) {
112 QString name = keyword.name().toUpper();
117 return NoTypeKeyword;
129 int PvlFormat::accuracy(
const PvlKeyword &keyword) {
130 QString name = keyword.name().toUpper();
134 return toInt(key[1]);
147 QString PvlFormat::formatValue(
const PvlKeyword &keyword,
int num) {
156 if(num >= keyword.size()) {
161 if(keyword[num].size() == 0) {
168 val = addQuotes(val);
171 if((keyword.size() > 1) && (num == 0)) {
176 if((!singleUnit) && (keyword.unit(num).size() > 0)) {
177 val +=
" <" + keyword.unit(num) +
">";
181 if(num != keyword.size() - 1) {
185 else if(keyword.size() > 1) {
190 if((singleUnit) && (num == keyword.size() - 1) &&
191 (keyword.unit(num).size() > 0)) {
192 val +=
" <" + keyword.unit(num) +
">";
204 QString PvlFormat::formatName(
const PvlKeyword &keyword) {
205 return keyword.name();
215 QString PvlFormat::formatEnd(
const QString name,
216 const PvlKeyword &keyword) {
217 return "End_" + formatName(keyword);
227 QString PvlFormat::addQuotes(
const QString value) {
230 bool needQuotes =
false;
233 char existingQuoteType =
'\0';
234 for (
int pos = 0; !needQuotes && pos < val.size(); pos++) {
238 if (val[pos] ==
'(' || val[pos] ==
'{') {
241 if (val[pos] ==
'(') {
242 closePos = val.indexOf(
')');
244 if (val[pos] ==
'{') {
245 closePos = val.indexOf(
'}');
249 if (closePos == -1 || closePos != val.size() - 1) {
258 if (val[pos] ==
' ' || val[pos] ==
'(' ||
259 val[pos] ==
'(' || val[pos] ==
')' ||
260 val[pos] ==
'{' || val[pos] ==
'}' ||
261 val[pos] ==
',' || val[pos] ==
'=') {
265 if (pos == val.size() - 1 && val[pos] ==
'-') {
270 if (existingQuoteType ==
'\0') {
271 if (val[pos] ==
'"') {
272 existingQuoteType =
'"';
274 else if (val[pos] ==
'\'') {
275 existingQuoteType =
'\'';
280 if (val[pos] ==
'"' || val[pos] ==
'\'') {
281 val[pos] = existingQuoteType;
287 char quoteValue =
'"';
289 if(existingQuoteType ==
'"') {
294 val = quoteValue + val + quoteValue;
310 bool singleUnit =
true;
311 for(
int i = 0; i < keyword.
size(); i ++) {
@ Programmer
This error is for when a programmer made an API call that was illegal.
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
void deleteKeyword(const QString &name)
Remove a specified keyword.
Container for cube-like labels.
A single keyword-value pair.
int size() const
Returns the number of values stored in this keyword.
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...
static bool stringEqual(const QString &string1, const QString &string2)
Checks to see if two QStrings are equal.
bool hasKeyword(const QString &kname, FindOptions opts) const
See if a keyword is in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within ...
void clear()
Remove everything from the current PvlObject.
PvlKeyword & findKeyword(const QString &kname, FindOptions opts)
Finds a keyword in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within this...
This is free and unencumbered software released into the public domain.
KeywordType
The different types of keywords that can be formatted.
int toInt(const QString &string)
Global function to convert from a string to an integer.
KeywordType toKeywordType(const QString type)
Convert a string representing a type of keyword to the corresponding enumeration.
Namespace for the standard library.