MCPcopy Create free account
hub / github.com/Tablecruncher/tablecruncher / genericColumnNameToIndex

Method genericColumnNameToIndex

src/helper.cpp:78–96  ·  view source on GitHub ↗

Returns index for excel style column name Return -1 if colName is not a valid uppercase excel style column Inverse function to createGenericColumnNames() */

Source from the content-addressed store, hash-verified

76 Inverse function to createGenericColumnNames()
77 */
78int Helper::genericColumnNameToIndex(std::string colName) {
79 int base = 26;
80 int col = 0;
81 int pos = 0;
82 bool error = false;
83 for( int c = colName.size() - 1; c >= 0 ; --c ) {
84 if( colName[c] < 'A' || colName[c] > 'Z' ) {
85 error = true;
86 break;
87 }
88 unsigned char digit = ((unsigned char) colName[c]) - '@';
89 col += std::pow(base, pos) * digit;
90 ++pos;
91 }
92 if( error ) {
93 col = 0; // causes to return -1
94 }
95 return col - 1;
96}
97
98
99/*

Callers

nothing calls this directly

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected