Skip to content

Commit

Permalink
rename namespace and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
j2doll committed Jan 4, 2023
1 parent c7f8f39 commit b7d7724
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 57 deletions.
53 changes: 47 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,54 @@
# excelColumnNumber

- Convert a column string in Excel to a number. :kr: 엑셀 컬럼 문자열을 숫자료 변환합니다.

- Using pure C++ and STL :kr: 씨플러스와 에스티엘만을 사용
- Convert a column string in Excel to a number.
- :kr: 엑셀 컬럼 문자열을 숫자로 변환합니다.

- Using pure C++ and STL
- :kr: 씨플러스와 에스티엘만을 사용

## Example

```cpp
unsigned int debug1 = excelColumnNumber::excelColumnStingToNumber("AB");
std::string debug2 = excelColumnNumber::convertFromNumberToExcelColumn( debug1 );
assert( debug2 == "AB" );
std::cout << " [1] ------------ " << std::endl ;

std::cout << " 0 : " << QXlsx::columnNumberToString( 0 ) << std::endl ;
std::cout << " 1 : " << QXlsx::columnNumberToString( 1 ) << std::endl ;
std::cout << " 2 : " << QXlsx::columnNumberToString( 2 ) << std::endl ;
std::cout << " 100 : " << QXlsx::columnNumberToString( 100 ) << std::endl ;
std::cout << " UINT_MAX : " << QXlsx::columnNumberToString( UINT_MAX ) << std::endl ;

std::cout << " [2] ------------ " << std::endl ;

std::cout << " a : " << QXlsx::alphabetToNumber('a') << std::endl ;
std::cout << " z : " << QXlsx::alphabetToNumber('z') << std::endl ;
std::cout << " A : " << QXlsx::alphabetToNumber('A') << std::endl ;
std::cout << " Z : " << QXlsx::alphabetToNumber('Z') << std::endl ;
std::cout << " 5 : " << QXlsx::alphabetToNumber('5') << std::endl ;

std::cout << " [3] ------------ " << std::endl ;

std::string columnString = "AB";
unsigned int debug1 = QXlsx::columnStringToNumber( columnString );
std::string debug2 = QXlsx::columnNumberToString( debug1 );
std::cout << debug1 << " " << debug2 << std::endl;
assert( debug2 == columnString );
```
- Output :
```
[1] ------------
0 :
1 : A
2 : B
100 : CV
UINT_MAX : MWLQKWU
[2] ------------
a : 1
z : 26
A : 1
Z : 26
5 : 0
[3] ------------
28 AB
```
8 changes: 4 additions & 4 deletions excelColumnNumber/excelColumnNumber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include "excelColumnNumber.h"

namespace excelColumnNumber { // {{ begin of namespace
namespace QXlsx { // {{ begin of namespace

std::string convertFromNumberToExcelColumn(unsigned int n)
std::string columnNumberToString(unsigned int n)
{
if (0 == n)
{
Expand Down Expand Up @@ -68,7 +68,7 @@ unsigned int alphabetToNumber(char alphabet)
return ret;
}

unsigned int excelColumnStingToNumber(std::string col)
unsigned int columnStringToNumber(std::string col)
{
unsigned int ret = 0;
unsigned int colSize = col.size();
Expand All @@ -85,4 +85,4 @@ unsigned int excelColumnStingToNumber(std::string col)
return ret;
}

} // }} end of namespace
} // }} end of namespace
24 changes: 21 additions & 3 deletions excelColumnNumber/excelColumnNumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,29 @@
#include <cmath>
#include <cassert>

namespace excelColumnNumber
namespace QXlsx
{
std::string convertFromNumberToExcelColumn(unsigned int n);
unsigned int excelColumnStingToNumber(std::string col);
///
/// \brief convert from number to excel column string
/// \param n
/// \return
///
std::string columnNumberToString(unsigned int n);

///
/// \brief convert from excel column string to number
/// \param col
/// \return
///
unsigned int columnStringToNumber(std::string col);

///
/// \brief convert from alphabet to number
/// a .. z : 97 ... 122
/// A .. Z : 65 ... 90
/// \param alphabet
/// \return
///
unsigned int alphabetToNumber(char alphabet);
}

31 changes: 0 additions & 31 deletions excelColumnNumber/excelColumnNumber.pro

This file was deleted.

27 changes: 14 additions & 13 deletions excelColumnNumber/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,27 @@ int main(int argc, char *argv[])
{
std::cout << " [1] ------------ " << std::endl ;

std::cout << " 0 : " << excelColumnNumber::convertFromNumberToExcelColumn( 0 ) << std::endl ;
std::cout << " 1 : " << excelColumnNumber::convertFromNumberToExcelColumn( 1 ) << std::endl ;
std::cout << " 2 : " << excelColumnNumber::convertFromNumberToExcelColumn( 2 ) << std::endl ;
std::cout << " 100 : " << excelColumnNumber::convertFromNumberToExcelColumn( 100 ) << std::endl ;
std::cout << " UINT_MAX : " << excelColumnNumber::convertFromNumberToExcelColumn( UINT_MAX ) << std::endl ;
std::cout << " 0 : " << QXlsx::columnNumberToString( 0 ) << std::endl ;
std::cout << " 1 : " << QXlsx::columnNumberToString( 1 ) << std::endl ;
std::cout << " 2 : " << QXlsx::columnNumberToString( 2 ) << std::endl ;
std::cout << " 100 : " << QXlsx::columnNumberToString( 100 ) << std::endl ;
std::cout << " UINT_MAX : " << QXlsx::columnNumberToString( UINT_MAX ) << std::endl ;

std::cout << " [2] ------------ " << std::endl ;

std::cout << " a : " << excelColumnNumber::alphabetToNumber('a') << std::endl ;
std::cout << " z : " << excelColumnNumber::alphabetToNumber('z') << std::endl ;
std::cout << " A : " << excelColumnNumber::alphabetToNumber('A') << std::endl ;
std::cout << " Z : " << excelColumnNumber::alphabetToNumber('Z') << std::endl ;
std::cout << " 5 : " << excelColumnNumber::alphabetToNumber('5') << std::endl ;
std::cout << " a : " << QXlsx::alphabetToNumber('a') << std::endl ;
std::cout << " z : " << QXlsx::alphabetToNumber('z') << std::endl ;
std::cout << " A : " << QXlsx::alphabetToNumber('A') << std::endl ;
std::cout << " Z : " << QXlsx::alphabetToNumber('Z') << std::endl ;
std::cout << " 5 : " << QXlsx::alphabetToNumber('5') << std::endl ;

std::cout << " [3] ------------ " << std::endl ;

unsigned int debug1 = excelColumnNumber::excelColumnStingToNumber("AB");
std::string debug2 = excelColumnNumber::convertFromNumberToExcelColumn( debug1 );
std::string columnString = "AB";
unsigned int debug1 = QXlsx::columnStringToNumber( columnString );
std::string debug2 = QXlsx::columnNumberToString( debug1 );
std::cout << debug1 << " " << debug2 << std::endl;
assert( debug2 == "AB" );
assert( debug2 == columnString );

return 0;
}

0 comments on commit b7d7724

Please sign in to comment.