From b7d7724d57908cc59b9f22c4c57418d455b15167 Mon Sep 17 00:00:00 2001 From: Jay Two Date: Wed, 4 Jan 2023 16:02:23 +0900 Subject: [PATCH] rename namespace and functions --- README.md | 53 ++++++++++++++++++++++--- excelColumnNumber/excelColumnNumber.cpp | 8 ++-- excelColumnNumber/excelColumnNumber.h | 24 +++++++++-- excelColumnNumber/excelColumnNumber.pro | 31 --------------- excelColumnNumber/main.cpp | 27 +++++++------ 5 files changed, 86 insertions(+), 57 deletions(-) delete mode 100644 excelColumnNumber/excelColumnNumber.pro diff --git a/README.md b/README.md index e5347e2..b71597b 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/excelColumnNumber/excelColumnNumber.cpp b/excelColumnNumber/excelColumnNumber.cpp index e40e8da..c750313 100644 --- a/excelColumnNumber/excelColumnNumber.cpp +++ b/excelColumnNumber/excelColumnNumber.cpp @@ -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) { @@ -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(); @@ -85,4 +85,4 @@ unsigned int excelColumnStingToNumber(std::string col) return ret; } -} // }} end of namespace \ No newline at end of file +} // }} end of namespace diff --git a/excelColumnNumber/excelColumnNumber.h b/excelColumnNumber/excelColumnNumber.h index ac13419..1631068 100644 --- a/excelColumnNumber/excelColumnNumber.h +++ b/excelColumnNumber/excelColumnNumber.h @@ -11,11 +11,29 @@ #include #include -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); } diff --git a/excelColumnNumber/excelColumnNumber.pro b/excelColumnNumber/excelColumnNumber.pro deleted file mode 100644 index ce2538d..0000000 --- a/excelColumnNumber/excelColumnNumber.pro +++ /dev/null @@ -1,31 +0,0 @@ -# - -QT -= gui - -CONFIG += c++11 console -CONFIG -= app_bundle - -# The following define makes your compiler emit warnings if you use -# any Qt feature that has been marked deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if it uses deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -INCLUDEPATH += . - -HEADERS += \ -excelColumnNumber.h - -SOURCES += \ -excelColumnNumber.cpp \ -main.cpp - -# Default rules for deployment. -qnx: target.path = /tmp/$${TARGET}/bin -else: unix:!android: target.path = /opt/$${TARGET}/bin -!isEmpty(target.path): INSTALLS += target diff --git a/excelColumnNumber/main.cpp b/excelColumnNumber/main.cpp index 8fcc147..c5d3d98 100644 --- a/excelColumnNumber/main.cpp +++ b/excelColumnNumber/main.cpp @@ -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; }