Returns index for excel style column name Return -1 if colName is not a valid uppercase excel style column Inverse function to createGenericColumnNames() */
| 76 | Inverse function to createGenericColumnNames() |
| 77 | */ |
| 78 | int 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 | /* |