App: [skip ci] use curly braces for if/else-statements and for loops
This commit is contained in:
@@ -77,8 +77,9 @@ Range::Range(const char * range, bool normalize)
|
||||
row_end = end.row();
|
||||
col_end = end.col();
|
||||
|
||||
if (normalize)
|
||||
if (normalize) {
|
||||
this->normalize();
|
||||
}
|
||||
row_curr = row_begin;
|
||||
col_curr = col_begin;
|
||||
}
|
||||
@@ -89,8 +90,9 @@ Range::Range(int _row_begin, int _col_begin, int _row_end, int _col_end, bool no
|
||||
, row_end(_row_end)
|
||||
, col_end(_col_end)
|
||||
{
|
||||
if (normalize)
|
||||
if (normalize) {
|
||||
this->normalize();
|
||||
}
|
||||
row_curr = row_begin;
|
||||
col_curr = col_begin;
|
||||
}
|
||||
@@ -101,18 +103,21 @@ Range::Range(const CellAddress &from, const CellAddress &to, bool normalize)
|
||||
, row_end(to.row())
|
||||
, col_end(to.col())
|
||||
{
|
||||
if (normalize)
|
||||
if (normalize) {
|
||||
this->normalize();
|
||||
}
|
||||
row_curr = row_begin;
|
||||
col_curr = col_begin;
|
||||
}
|
||||
|
||||
void Range::normalize()
|
||||
{
|
||||
if (row_begin > row_end)
|
||||
if (row_begin > row_end) {
|
||||
std::swap(row_begin, row_end);
|
||||
if (col_begin > col_end)
|
||||
}
|
||||
if (col_begin > col_end) {
|
||||
std::swap(col_begin, col_end);
|
||||
}
|
||||
}
|
||||
|
||||
bool Range::next()
|
||||
@@ -144,22 +149,24 @@ int App::decodeRow(const std::string &rowstr, bool silent)
|
||||
{
|
||||
int row = validRow(rowstr);
|
||||
|
||||
if (silent || row >= 0)
|
||||
if (silent || row >= 0) {
|
||||
return row;
|
||||
else
|
||||
throw Base::IndexError("Invalid row specification.");
|
||||
}
|
||||
|
||||
throw Base::IndexError("Invalid row specification.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Assumes well-formed input. A through ZZZ. 0-based output
|
||||
*/
|
||||
int columnStringToNum(const std::string &colstr){
|
||||
double out {0};
|
||||
int pos {0};
|
||||
for(auto chr = colstr.crbegin(); chr != colstr.crend(); chr++){
|
||||
out += (*chr - 'A' + 1) * std::pow(26, pos++);
|
||||
}
|
||||
return static_cast<int>(out - 1);
|
||||
int columnStringToNum(const std::string &colstr) {
|
||||
double out {0};
|
||||
int pos {0};
|
||||
for (auto chr = colstr.crbegin(); chr != colstr.crend(); chr++){
|
||||
out += (*chr - 'A' + 1) * std::pow(26, pos++);
|
||||
}
|
||||
|
||||
return static_cast<int>(out - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,10 +180,14 @@ int columnStringToNum(const std::string &colstr){
|
||||
|
||||
int App::decodeColumn( const std::string &colstr, bool silent )
|
||||
{
|
||||
if(validColumn( colstr ) )
|
||||
return columnStringToNum( colstr );
|
||||
if( silent )
|
||||
if (validColumn(colstr)) {
|
||||
return columnStringToNum(colstr);
|
||||
}
|
||||
|
||||
if (silent) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
throw Base::IndexError("Invalid column specification");
|
||||
}
|
||||
|
||||
@@ -193,8 +204,9 @@ int App::validRow(const std::string &rowstr)
|
||||
char * end;
|
||||
int i = strtol(rowstr.c_str(), &end, 10);
|
||||
|
||||
if (i <=0 || i > CellAddress::MAX_ROWS || *end)
|
||||
if (i <=0 || i > CellAddress::MAX_ROWS || *end) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return i - 1;
|
||||
}
|
||||
@@ -233,21 +245,28 @@ App::CellAddress App::stringToAddress(const char * strAddress, bool silent)
|
||||
if (boost::regex_match(strAddress, cm, e)) {
|
||||
bool absCol = (cm[1].first[0]=='$');
|
||||
std::string r,c;
|
||||
if(absCol)
|
||||
if (absCol) {
|
||||
c = std::string(cm[1].first+1,cm[1].second);
|
||||
else
|
||||
}
|
||||
else {
|
||||
c = std::string(cm[1].first,cm[1].second);
|
||||
}
|
||||
|
||||
bool absRow = (cm[2].first[0]=='$');
|
||||
if(absRow)
|
||||
if (absRow) {
|
||||
r = std::string(cm[2].first+1,cm[2].second);
|
||||
else
|
||||
}
|
||||
else {
|
||||
r = std::string(cm[2].first,cm[2].second);
|
||||
}
|
||||
|
||||
return CellAddress(decodeRow(r,silent), decodeColumn(c,silent), absRow, absCol);
|
||||
}
|
||||
else if(silent)
|
||||
else if (silent) {
|
||||
return CellAddress();
|
||||
else
|
||||
throw Base::RuntimeError("Invalid cell specifier.");
|
||||
}
|
||||
|
||||
throw Base::RuntimeError("Invalid cell specifier.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -262,8 +281,9 @@ std::string App::CellAddress::toString(Cell cell) const
|
||||
|
||||
Base::Flags<Cell> flags(cell);
|
||||
if (flags.testFlag(Cell::ShowColumn)) {
|
||||
if (_absCol && flags.testFlag(Cell::Absolute))
|
||||
if (_absCol && flags.testFlag(Cell::Absolute)) {
|
||||
s << '$';
|
||||
}
|
||||
if (col() < 26) {
|
||||
s << static_cast<char>('A' + col());
|
||||
}
|
||||
@@ -276,8 +296,9 @@ std::string App::CellAddress::toString(Cell cell) const
|
||||
}
|
||||
|
||||
if (flags.testFlag(Cell::ShowRow)) {
|
||||
if (_absRow && flags.testFlag(Cell::Absolute))
|
||||
if (_absRow && flags.testFlag(Cell::Absolute)) {
|
||||
s << '$';
|
||||
}
|
||||
s << (row() + 1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user