changed default MSVC version to 22
parent
9056c61902
commit
407d30f853
@ -1,59 +1,59 @@
|
|||||||
######################## VSCODE IGNORES
|
######################## VSCODE IGNORES
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
|
|
||||||
######################## C++ IGNORES
|
######################## C++ IGNORES
|
||||||
# Prerequisites
|
# Prerequisites
|
||||||
*.d
|
*.d
|
||||||
|
|
||||||
# Compiled Object files
|
# Compiled Object files
|
||||||
*.slo
|
*.slo
|
||||||
*.lo
|
*.lo
|
||||||
*.o
|
*.o
|
||||||
*.obj
|
*.obj
|
||||||
|
|
||||||
# Precompiled Headers
|
# Precompiled Headers
|
||||||
*.gch
|
*.gch
|
||||||
*.pch
|
*.pch
|
||||||
|
|
||||||
# Compiled Dynamic libraries
|
# Compiled Dynamic libraries
|
||||||
*.so
|
*.so
|
||||||
*.dylib
|
*.dylib
|
||||||
*.dll
|
*.dll
|
||||||
|
|
||||||
# Fortran module files
|
# Fortran module files
|
||||||
*.mod
|
*.mod
|
||||||
*.smod
|
*.smod
|
||||||
|
|
||||||
# Compiled Static libraries
|
# Compiled Static libraries
|
||||||
*.lai
|
*.lai
|
||||||
*.la
|
*.la
|
||||||
*.a
|
*.a
|
||||||
*.lib
|
*.lib
|
||||||
|
|
||||||
# Executables
|
# Executables
|
||||||
*.exe
|
*.exe
|
||||||
*.out
|
*.out
|
||||||
*.app
|
*.app
|
||||||
|
|
||||||
# other
|
# other
|
||||||
*.log
|
*.log
|
||||||
*.zip
|
*.zip
|
||||||
*.ini
|
*.ini
|
||||||
test_data/test_save.xml
|
test_data/test_save.xml
|
||||||
|
|
||||||
######################## CMAKE IGNORES
|
######################## CMAKE IGNORES
|
||||||
CMakeLists.txt.user
|
CMakeLists.txt.user
|
||||||
CMakeCache.txt
|
CMakeCache.txt
|
||||||
CMakeFiles
|
CMakeFiles
|
||||||
CMakeScripts
|
CMakeScripts
|
||||||
Testing
|
Testing
|
||||||
Makefile
|
Makefile
|
||||||
cmake_install.cmake
|
cmake_install.cmake
|
||||||
install_manifest.txt
|
install_manifest.txt
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
CTestTestfile.cmake
|
CTestTestfile.cmake
|
||||||
_deps
|
_deps
|
||||||
|
|
||||||
######################## BUILD IGNORES
|
######################## BUILD IGNORES
|
||||||
build/
|
build/
|
||||||
@ -1,25 +1,25 @@
|
|||||||
cmake_minimum_required(VERSION 3.16.3)
|
cmake_minimum_required(VERSION 3.16.3)
|
||||||
|
|
||||||
# Set the project name and version
|
# Set the project name and version
|
||||||
project(cgen VERSION 1.0.0)
|
project(cgen VERSION 1.0.5)
|
||||||
|
|
||||||
# specify the C++ standard
|
# specify the C++ standard
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
|
|
||||||
configure_file(cgenConfig.h.in cgenConfig.h)
|
configure_file(cgenConfig.h.in cgenConfig.h)
|
||||||
|
|
||||||
# specify the project source files
|
# specify the project source files
|
||||||
set( CGEN_SRC
|
set( CGEN_SRC
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
src/utils/CmdArgParser.cpp
|
src/utils/CmdArgParser.cpp
|
||||||
src/utils/StringManip.cpp
|
src/utils/StringManip.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# add the executable
|
# add the executable
|
||||||
add_executable(${PROJECT_NAME} ${CGEN_SRC})
|
add_executable(${PROJECT_NAME} ${CGEN_SRC})
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME}
|
target_include_directories(${PROJECT_NAME}
|
||||||
PUBLIC "${PROJECT_BINARY_DIR}"
|
PUBLIC "${PROJECT_BINARY_DIR}"
|
||||||
PUBLIC src
|
PUBLIC src
|
||||||
)
|
)
|
||||||
@ -1,7 +1,7 @@
|
|||||||
Copyright 2021 Joseph R Pollack
|
Copyright 2021 Joseph R Pollack
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
@ -1,4 +1,4 @@
|
|||||||
// the configured options and settings for Lunarium
|
// the configured options and settings for Lunarium
|
||||||
#define cgen_VERSION_MAJOR @cgen_VERSION_MAJOR@
|
#define cgen_VERSION_MAJOR @cgen_VERSION_MAJOR@
|
||||||
#define cgen_VERSION_MINOR @cgen_VERSION_MINOR@
|
#define cgen_VERSION_MINOR @cgen_VERSION_MINOR@
|
||||||
#define cgen_VERSION_PATCH @cgen_VERSION_PATCH@
|
#define cgen_VERSION_PATCH @cgen_VERSION_PATCH@
|
||||||
@ -1,3 +1,3 @@
|
|||||||
|
|
||||||
✔ @high Add an option to change the compiler/generator (vs version, clang, etc) @done(22-04-18 17:58)
|
✔ @high Add an option to change the compiler/generator (vs version, clang, etc) @done(22-04-18 17:58)
|
||||||
☐ Add library source directories to the root CMake project include directories
|
☐ Add library source directories to the root CMake project include directories
|
||||||
@ -1,17 +1,17 @@
|
|||||||
@echo off
|
@echo off
|
||||||
REM This script expects to be run from the parent directory
|
REM This script expects to be run from the parent directory
|
||||||
REM ex. scripts/build.bat
|
REM ex. scripts/build.bat
|
||||||
|
|
||||||
IF not exist build/ (
|
IF not exist build/ (
|
||||||
echo This script needs to be run from the directory above build/
|
echo This script needs to be run from the directory above build/
|
||||||
goto END
|
goto END
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
IF "%~1" == "r" (
|
IF "%~1" == "r" (
|
||||||
cmake --build build/ --target ALL_BUILD --config Release
|
cmake --build build/ --target ALL_BUILD --config Release
|
||||||
) ELSE (
|
) ELSE (
|
||||||
cmake --build build/ --target ALL_BUILD --config Debug
|
cmake --build build/ --target ALL_BUILD --config Debug
|
||||||
)
|
)
|
||||||
|
|
||||||
:END
|
:END
|
||||||
@ -1,14 +1,14 @@
|
|||||||
|
|
||||||
@echo off
|
@echo off
|
||||||
|
|
||||||
IF not exist build/ (
|
IF not exist build/ (
|
||||||
echo This script needs to be run from the directory above build/
|
echo This script needs to be run from the directory above build/
|
||||||
goto END
|
goto END
|
||||||
)
|
)
|
||||||
|
|
||||||
echo Removing the build directory
|
echo Removing the build directory
|
||||||
del /s /q build
|
del /s /q build
|
||||||
rd /s /q build
|
rd /s /q build
|
||||||
mkdir build
|
mkdir build
|
||||||
|
|
||||||
:END
|
:END
|
||||||
@ -1,7 +1,7 @@
|
|||||||
@echo off
|
@echo off
|
||||||
REM This script expects to be run from the parent directory
|
REM This script expects to be run from the parent directory
|
||||||
REM ex. scripts/cmconfig.bat
|
REM ex. scripts/cmconfig.bat
|
||||||
@echo off
|
@echo off
|
||||||
|
|
||||||
|
|
||||||
cmake -Wno-dev -B build/ -S . -G "Visual Studio 17 2022" -A x64
|
cmake -Wno-dev -B build/ -S . -G "Visual Studio 17 2022" -A x64
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -1,268 +1,268 @@
|
|||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* File - CmdArgParser.cpp
|
* File - CmdArgParser.cpp
|
||||||
* Author - Joey Pollack
|
* Author - Joey Pollack
|
||||||
* Date - 2018/09/27 (y/m/d)
|
* Date - 2018/09/27 (y/m/d)
|
||||||
* Mod Date - 2018/10/15 (y/m/d)
|
* Mod Date - 2018/10/15 (y/m/d)
|
||||||
* Description - Parses the program's command line arguments and makes
|
* Description - Parses the program's command line arguments and makes
|
||||||
* them easily available.
|
* them easily available.
|
||||||
*
|
*
|
||||||
* Code should work on windows and *nix
|
* Code should work on windows and *nix
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "CmdArgParser.h"
|
#include "CmdArgParser.h"
|
||||||
#include "StringManip.h"
|
#include "StringManip.h"
|
||||||
|
|
||||||
namespace jpUtils
|
namespace jpUtils
|
||||||
{
|
{
|
||||||
const CmdArgParser::Argument CmdArgParser::InvalidArg;
|
const CmdArgParser::Argument CmdArgParser::InvalidArg;
|
||||||
|
|
||||||
CmdArgParser::CmdArgParser(int argc, char ** argv, std::string programDesc, char prefixChar)
|
CmdArgParser::CmdArgParser(int argc, char ** argv, std::string programDesc, char prefixChar)
|
||||||
: mArgc(argc), mArgv(argv), mPrefixChar(prefixChar), mUsageText(""), mErrorMessage(""), mProgramDesc(programDesc)
|
: mArgc(argc), mArgv(argv), mPrefixChar(prefixChar), mUsageText(""), mErrorMessage(""), mProgramDesc(programDesc)
|
||||||
{
|
{
|
||||||
// TODO: Add -h arg?
|
// TODO: Add -h arg?
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CmdArgParser::ContainsOption(const char * option) const
|
bool CmdArgParser::ContainsOption(const char * option) const
|
||||||
{
|
{
|
||||||
return mOptionalArgs.find(option) != mOptionalArgs.end();
|
return mOptionalArgs.find(option) != mOptionalArgs.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
const CmdArgParser::Argument& CmdArgParser::GetPositionalArg(int pos) const
|
const CmdArgParser::Argument& CmdArgParser::GetPositionalArg(int pos) const
|
||||||
{
|
{
|
||||||
if (pos < 0 || pos >= (signed)mPositionalArgs.size())
|
if (pos < 0 || pos >= (signed)mPositionalArgs.size())
|
||||||
return CmdArgParser::InvalidArg;
|
return CmdArgParser::InvalidArg;
|
||||||
|
|
||||||
return mPositionalArgs[pos];
|
return mPositionalArgs[pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<CmdArgParser::Argument> CmdArgParser::GetAllPosArgs() const
|
const std::vector<CmdArgParser::Argument> CmdArgParser::GetAllPosArgs() const
|
||||||
{
|
{
|
||||||
return mPositionalArgs;
|
return mPositionalArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CmdArgParser::Argument& CmdArgParser::GetOptionValue(const char * option) const
|
const CmdArgParser::Argument& CmdArgParser::GetOptionValue(const char * option) const
|
||||||
{
|
{
|
||||||
auto iter = mOptionalArgs.find(std::string(option));
|
auto iter = mOptionalArgs.find(std::string(option));
|
||||||
|
|
||||||
if (iter == mOptionalArgs.end())
|
if (iter == mOptionalArgs.end())
|
||||||
return CmdArgParser::InvalidArg;
|
return CmdArgParser::InvalidArg;
|
||||||
|
|
||||||
return iter->second;
|
return iter->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CmdArgParser::Parse()
|
bool CmdArgParser::Parse()
|
||||||
{
|
{
|
||||||
mOptionalArgs.clear();
|
mOptionalArgs.clear();
|
||||||
mPositionalArgs.clear();
|
mPositionalArgs.clear();
|
||||||
|
|
||||||
std::vector<std::string> tempPosValues;
|
std::vector<std::string> tempPosValues;
|
||||||
|
|
||||||
mErrorMessage = "";
|
mErrorMessage = "";
|
||||||
for (int i = 1; i < mArgc; i++)
|
for (int i = 1; i < mArgc; i++)
|
||||||
{
|
{
|
||||||
// If this is an optional arg
|
// If this is an optional arg
|
||||||
if (mArgv[i][0] == mPrefixChar)
|
if (mArgv[i][0] == mPrefixChar)
|
||||||
{
|
{
|
||||||
// Optional args must occur before or after all positional args
|
// Optional args must occur before or after all positional args
|
||||||
if (mPositionalArgs.size() != 0 && mPositionalArgs.size() < mExpectedPosArgs.size())
|
if (mPositionalArgs.size() != 0 && mPositionalArgs.size() < mExpectedPosArgs.size())
|
||||||
{
|
{
|
||||||
mErrorMessage += "\nMissing Required Arguments";
|
mErrorMessage += "\nMissing Required Arguments";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string temp = mArgv[i];
|
std::string temp = mArgv[i];
|
||||||
auto iter = mExpectedOptArgs.find(temp);
|
auto iter = mExpectedOptArgs.find(temp);
|
||||||
if (iter == mExpectedOptArgs.end())
|
if (iter == mExpectedOptArgs.end())
|
||||||
{
|
{
|
||||||
mErrorMessage += "\nUknown Argument: " + std::string(mArgv[i]);
|
mErrorMessage += "\nUknown Argument: " + std::string(mArgv[i]);
|
||||||
continue; // Non fatal error
|
continue; // Non fatal error
|
||||||
}
|
}
|
||||||
|
|
||||||
const ArgDesc& arg = (ArgDesc)(*iter).second;
|
const ArgDesc& arg = (ArgDesc)(*iter).second;
|
||||||
|
|
||||||
if (mOptionalArgs.find(arg.name) != mOptionalArgs.end())
|
if (mOptionalArgs.find(arg.name) != mOptionalArgs.end())
|
||||||
{
|
{
|
||||||
mErrorMessage += "\nDuplicate Argument: " + std::string(mArgv[i]);
|
mErrorMessage += "\nDuplicate Argument: " + std::string(mArgv[i]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Argument theArg;
|
Argument theArg;
|
||||||
theArg.name = arg.name;
|
theArg.name = arg.name;
|
||||||
|
|
||||||
for (int j = 0; j < arg.numExpectedValues; j++)
|
for (int j = 0; j < arg.numExpectedValues; j++)
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
if (i >= mArgc)
|
if (i >= mArgc)
|
||||||
{
|
{
|
||||||
mErrorMessage += "\nNot enough values given for option argument: " + theArg.name;
|
mErrorMessage += "\nNot enough values given for option argument: " + theArg.name;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mArgv[i][0] == mPrefixChar)
|
if (mArgv[i][0] == mPrefixChar)
|
||||||
{
|
{
|
||||||
mErrorMessage += "\nNot enough values given for option argument: " + theArg.name;
|
mErrorMessage += "\nNot enough values given for option argument: " + theArg.name;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
theArg.values.push_back(std::string(mArgv[i]));
|
theArg.values.push_back(std::string(mArgv[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
mOptionalArgs.insert(std::pair<std::string, Argument>(theArg.name, theArg));
|
mOptionalArgs.insert(std::pair<std::string, Argument>(theArg.name, theArg));
|
||||||
}
|
}
|
||||||
// If this is a positional arg
|
// If this is a positional arg
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tempPosValues.push_back(std::string(mArgv[i]));
|
tempPosValues.push_back(std::string(mArgv[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (mPositionalArgs.size() > mExpectedPosArgs.size())
|
//if (mPositionalArgs.size() > mExpectedPosArgs.size())
|
||||||
//{
|
//{
|
||||||
// mErrorMessage += "\nToo many Arguments given";
|
// mErrorMessage += "\nToo many Arguments given";
|
||||||
// return true; // non fatal error
|
// return true; // non fatal error
|
||||||
//}
|
//}
|
||||||
|
|
||||||
// Split the positional args into lists based on how many values are expected for each
|
// Split the positional args into lists based on how many values are expected for each
|
||||||
int numArgs = mExpectedPosArgs.size();
|
int numArgs = mExpectedPosArgs.size();
|
||||||
int numValues = tempPosValues.size();
|
int numValues = tempPosValues.size();
|
||||||
int minNeededValues = 0;
|
int minNeededValues = 0;
|
||||||
int used = 0;
|
int used = 0;
|
||||||
|
|
||||||
// find the min number of values needed to satisfy all arg requirements
|
// find the min number of values needed to satisfy all arg requirements
|
||||||
for (int i = 0; i < (signed)mExpectedPosArgs.size(); i++)
|
for (int i = 0; i < (signed)mExpectedPosArgs.size(); i++)
|
||||||
{
|
{
|
||||||
if (mExpectedPosArgs[i].numExpectedValues > 0)
|
if (mExpectedPosArgs[i].numExpectedValues > 0)
|
||||||
minNeededValues += mExpectedPosArgs[i].numExpectedValues;
|
minNeededValues += mExpectedPosArgs[i].numExpectedValues;
|
||||||
|
|
||||||
if (mExpectedPosArgs[i].numExpectedValues == -1)
|
if (mExpectedPosArgs[i].numExpectedValues == -1)
|
||||||
minNeededValues += 1;
|
minNeededValues += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numValues < minNeededValues)
|
if (numValues < minNeededValues)
|
||||||
{
|
{
|
||||||
// TODO: Could add logic to print the name of the missing args
|
// TODO: Could add logic to print the name of the missing args
|
||||||
mErrorMessage += "\nNot enough arguments";
|
mErrorMessage += "\nNot enough arguments";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < (signed)mExpectedPosArgs.size(); i++)
|
for (int i = 0; i < (signed)mExpectedPosArgs.size(); i++)
|
||||||
{
|
{
|
||||||
Argument arg;
|
Argument arg;
|
||||||
arg.name = mExpectedPosArgs[i].name;
|
arg.name = mExpectedPosArgs[i].name;
|
||||||
|
|
||||||
// if -1 this arg will accept 1 or more values available
|
// if -1 this arg will accept 1 or more values available
|
||||||
if (-1 == mExpectedPosArgs[i].numExpectedValues)
|
if (-1 == mExpectedPosArgs[i].numExpectedValues)
|
||||||
{
|
{
|
||||||
// How many values can be put in this arg list while still
|
// How many values can be put in this arg list while still
|
||||||
// having enough left over to fill the rest of the args?
|
// having enough left over to fill the rest of the args?
|
||||||
// numUsable should always be at least 1
|
// numUsable should always be at least 1
|
||||||
int numUsable = (tempPosValues.size() - used) - (minNeededValues - 1);
|
int numUsable = (tempPosValues.size() - used) - (minNeededValues - 1);
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
if (numUsable < 1)
|
if (numUsable < 1)
|
||||||
{
|
{
|
||||||
throw "numUsable is < 1!";
|
throw "numUsable is < 1!";
|
||||||
}
|
}
|
||||||
#endif // _DEBUG
|
#endif // _DEBUG
|
||||||
|
|
||||||
// used is the index of the next available value in tempPosValues
|
// used is the index of the next available value in tempPosValues
|
||||||
// numUsable + used is the index past the last value in
|
// numUsable + used is the index past the last value in
|
||||||
// tempPosValues that will fit here
|
// tempPosValues that will fit here
|
||||||
int endIdx = (numUsable + used);
|
int endIdx = (numUsable + used);
|
||||||
for (int j = used; j < endIdx; j++)
|
for (int j = used; j < endIdx; j++)
|
||||||
{
|
{
|
||||||
arg.values.push_back(tempPosValues[j]);
|
arg.values.push_back(tempPosValues[j]);
|
||||||
used++;
|
used++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int endIdx = (mExpectedPosArgs[i].numExpectedValues + used);
|
int endIdx = (mExpectedPosArgs[i].numExpectedValues + used);
|
||||||
for (int j = used; j < endIdx; j++)
|
for (int j = used; j < endIdx; j++)
|
||||||
{
|
{
|
||||||
arg.values.push_back(tempPosValues[j]);
|
arg.values.push_back(tempPosValues[j]);
|
||||||
used++;
|
used++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mPositionalArgs.push_back(arg);
|
mPositionalArgs.push_back(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CmdArgParser::GetErrorMessage() const
|
std::string CmdArgParser::GetErrorMessage() const
|
||||||
{
|
{
|
||||||
return mErrorMessage;
|
return mErrorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CmdArgParser::AddArg(ArgDesc desc)
|
bool CmdArgParser::AddArg(ArgDesc desc)
|
||||||
{
|
{
|
||||||
// With new args the usage text needs to be regenerated
|
// With new args the usage text needs to be regenerated
|
||||||
// Making it empty will force it to be regenerated when GetUsageText() is called
|
// Making it empty will force it to be regenerated when GetUsageText() is called
|
||||||
mUsageText = "";
|
mUsageText = "";
|
||||||
|
|
||||||
// argument names must not contain spaces
|
// argument names must not contain spaces
|
||||||
// so remove anything after the first space
|
// so remove anything after the first space
|
||||||
if (desc.name.length() > 0)
|
if (desc.name.length() > 0)
|
||||||
desc.name = StringManip::Split(desc.name)[0];
|
desc.name = StringManip::Split(desc.name)[0];
|
||||||
|
|
||||||
if (desc.optional)
|
if (desc.optional)
|
||||||
{
|
{
|
||||||
if (mExpectedOptArgs.find(desc.name) != mExpectedOptArgs.end())
|
if (mExpectedOptArgs.find(desc.name) != mExpectedOptArgs.end())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
mExpectedOptArgs.insert(std::pair<std::string, ArgDesc>(desc.name, desc));
|
mExpectedOptArgs.insert(std::pair<std::string, ArgDesc>(desc.name, desc));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mExpectedPosArgs.push_back(desc);
|
mExpectedPosArgs.push_back(desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string CmdArgParser::GetUsageText()
|
std::string CmdArgParser::GetUsageText()
|
||||||
{
|
{
|
||||||
if ("" == mUsageText)
|
if ("" == mUsageText)
|
||||||
GenerateUsageText();
|
GenerateUsageText();
|
||||||
|
|
||||||
return mUsageText;
|
return mUsageText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CmdArgParser::GenerateUsageText()
|
void CmdArgParser::GenerateUsageText()
|
||||||
{
|
{
|
||||||
// TODO: GenerateUsageText()
|
// TODO: GenerateUsageText()
|
||||||
mUsageText = "";
|
mUsageText = "";
|
||||||
|
|
||||||
std::string programName = StringManip::GetFileNameFromPath(std::string(mArgv[0]), false);
|
std::string programName = StringManip::GetFileNameFromPath(std::string(mArgv[0]), false);
|
||||||
|
|
||||||
mUsageText = programName;
|
mUsageText = programName;
|
||||||
mUsageText += ": " + mProgramDesc;
|
mUsageText += ": " + mProgramDesc;
|
||||||
mUsageText += "\n\nUsage: ";
|
mUsageText += "\n\nUsage: ";
|
||||||
mUsageText += programName;
|
mUsageText += programName;
|
||||||
mUsageText += " [OPTIONS] ";
|
mUsageText += " [OPTIONS] ";
|
||||||
|
|
||||||
for (EPITER iter = mExpectedPosArgs.begin(); iter != mExpectedPosArgs.end(); iter++)
|
for (EPITER iter = mExpectedPosArgs.begin(); iter != mExpectedPosArgs.end(); iter++)
|
||||||
{
|
{
|
||||||
mUsageText += (*iter).name + " ";
|
mUsageText += (*iter).name + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
mUsageText += "\n\nOPTIONS:";
|
mUsageText += "\n\nOPTIONS:";
|
||||||
for (EOITER iter = mExpectedOptArgs.begin(); iter != mExpectedOptArgs.end(); iter++)
|
for (EOITER iter = mExpectedOptArgs.begin(); iter != mExpectedOptArgs.end(); iter++)
|
||||||
{
|
{
|
||||||
mUsageText += "\n\t" + (*iter).first;
|
mUsageText += "\n\t" + (*iter).first;
|
||||||
mUsageText += " " + (*iter).second.helpText;
|
mUsageText += " " + (*iter).second.helpText;
|
||||||
}
|
}
|
||||||
|
|
||||||
mUsageText += "\n\nREQUIRED ARGS:";
|
mUsageText += "\n\nREQUIRED ARGS:";
|
||||||
for (EPITER iter = mExpectedPosArgs.begin(); iter != mExpectedPosArgs.end(); iter++)
|
for (EPITER iter = mExpectedPosArgs.begin(); iter != mExpectedPosArgs.end(); iter++)
|
||||||
{
|
{
|
||||||
mUsageText += "\n\t" + (*iter).name + ": " + (*iter).helpText;
|
mUsageText += "\n\t" + (*iter).name + ": " + (*iter).helpText;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,115 +1,115 @@
|
|||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* File - CmdArgParser.h
|
* File - CmdArgParser.h
|
||||||
* Author - Joey Pollack
|
* Author - Joey Pollack
|
||||||
* Date - 2018/09/27 (y/m/d)
|
* Date - 2018/09/27 (y/m/d)
|
||||||
* Mod Date - 2018/10/15 (y/m/d)
|
* Mod Date - 2018/10/15 (y/m/d)
|
||||||
* Description - Parses the program's command line arguments and makes
|
* Description - Parses the program's command line arguments and makes
|
||||||
* them easily available.
|
* them easily available.
|
||||||
*
|
*
|
||||||
* Code should work on windows and *nix
|
* Code should work on windows and *nix
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#ifndef CMD_ARG_PARSER_H_
|
#ifndef CMD_ARG_PARSER_H_
|
||||||
#define CMD_ARG_PARSER_H_
|
#define CMD_ARG_PARSER_H_
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace jpUtils
|
namespace jpUtils
|
||||||
{
|
{
|
||||||
class CmdArgParser
|
class CmdArgParser
|
||||||
{
|
{
|
||||||
|
|
||||||
// TODO: Possibly add error codes
|
// TODO: Possibly add error codes
|
||||||
// TODO: Add support for --arguments
|
// TODO: Add support for --arguments
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct Argument
|
struct Argument
|
||||||
{
|
{
|
||||||
std::string name = "INVALID";
|
std::string name = "INVALID";
|
||||||
std::vector<std::string> values;
|
std::vector<std::string> values;
|
||||||
|
|
||||||
bool operator==(const Argument& rhs)
|
bool operator==(const Argument& rhs)
|
||||||
{
|
{
|
||||||
return this->name == rhs.name;
|
return this->name == rhs.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const Argument InvalidArg;
|
static const Argument InvalidArg;
|
||||||
|
|
||||||
struct ArgDesc
|
struct ArgDesc
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
bool optional;
|
bool optional;
|
||||||
|
|
||||||
// -1 for 1 or more args (if optional, 0 or more args)
|
// -1 for 1 or more args (if optional, 0 or more args)
|
||||||
int numExpectedValues;
|
int numExpectedValues;
|
||||||
std::string helpText;
|
std::string helpText;
|
||||||
|
|
||||||
ArgDesc(std::string _name, bool _optional, int _numExpectedValues, std::string _helpText)
|
ArgDesc(std::string _name, bool _optional, int _numExpectedValues, std::string _helpText)
|
||||||
: name(_name), optional(_optional), numExpectedValues(_numExpectedValues), helpText(_helpText)
|
: name(_name), optional(_optional), numExpectedValues(_numExpectedValues), helpText(_helpText)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private: // currently unused
|
private: // currently unused
|
||||||
enum ValueType { VTYPE_STRING, VTYPE_INT, VTYPE_DOUBLE, VTYPE_BOOL, VTYPE_INVALID };
|
enum ValueType { VTYPE_STRING, VTYPE_INT, VTYPE_DOUBLE, VTYPE_BOOL, VTYPE_INVALID };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CmdArgParser(int argc, char** argv, std::string programDesc, char prefixChar = '-');
|
CmdArgParser(int argc, char** argv, std::string programDesc, char prefixChar = '-');
|
||||||
|
|
||||||
bool Parse();
|
bool Parse();
|
||||||
|
|
||||||
// If the returned string is not empty errors occured when processing
|
// If the returned string is not empty errors occured when processing
|
||||||
// the arguments. The string contains the generated error messages.
|
// the arguments. The string contains the generated error messages.
|
||||||
std::string GetErrorMessage() const;
|
std::string GetErrorMessage() const;
|
||||||
|
|
||||||
// Returns false if the arg cant be added - this would probably
|
// Returns false if the arg cant be added - this would probably
|
||||||
// happen if a given arg already exists
|
// happen if a given arg already exists
|
||||||
bool AddArg(ArgDesc desc);
|
bool AddArg(ArgDesc desc);
|
||||||
|
|
||||||
std::string GetUsageText();
|
std::string GetUsageText();
|
||||||
|
|
||||||
bool ContainsOption(const char* option) const;
|
bool ContainsOption(const char* option) const;
|
||||||
const CmdArgParser::Argument& GetPositionalArg(int pos) const;
|
const CmdArgParser::Argument& GetPositionalArg(int pos) const;
|
||||||
const std::vector<Argument> GetAllPosArgs() const;
|
const std::vector<Argument> GetAllPosArgs() const;
|
||||||
const Argument& GetOptionValue(const char* option) const;
|
const Argument& GetOptionValue(const char* option) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int mArgc;
|
int mArgc;
|
||||||
char** mArgv;
|
char** mArgv;
|
||||||
|
|
||||||
std::string mUsageText;
|
std::string mUsageText;
|
||||||
std::string mErrorMessage;
|
std::string mErrorMessage;
|
||||||
std::string mProgramDesc;
|
std::string mProgramDesc;
|
||||||
|
|
||||||
// can be set to '-' or '/'
|
// can be set to '-' or '/'
|
||||||
char mPrefixChar;
|
char mPrefixChar;
|
||||||
|
|
||||||
// Expected Positional Arguments
|
// Expected Positional Arguments
|
||||||
std::vector<ArgDesc> mExpectedPosArgs;
|
std::vector<ArgDesc> mExpectedPosArgs;
|
||||||
typedef std::vector<ArgDesc>::iterator EPITER;
|
typedef std::vector<ArgDesc>::iterator EPITER;
|
||||||
|
|
||||||
// Positional args found
|
// Positional args found
|
||||||
std::vector<Argument> mPositionalArgs;
|
std::vector<Argument> mPositionalArgs;
|
||||||
typedef std::vector<std::string>::iterator PITER;
|
typedef std::vector<std::string>::iterator PITER;
|
||||||
|
|
||||||
// Expected Optional args
|
// Expected Optional args
|
||||||
std::map<std::string, ArgDesc> mExpectedOptArgs;
|
std::map<std::string, ArgDesc> mExpectedOptArgs;
|
||||||
typedef std::map<std::string, ArgDesc>::iterator EOITER;
|
typedef std::map<std::string, ArgDesc>::iterator EOITER;
|
||||||
|
|
||||||
// Optional args found
|
// Optional args found
|
||||||
std::map<std::string, Argument> mOptionalArgs;
|
std::map<std::string, Argument> mOptionalArgs;
|
||||||
typedef std::map<std::string, Argument>::iterator OITER;
|
typedef std::map<std::string, Argument>::iterator OITER;
|
||||||
|
|
||||||
private: // HELPER METHODS
|
private: // HELPER METHODS
|
||||||
|
|
||||||
void GenerateUsageText();
|
void GenerateUsageText();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif // CMD_ARG_PARSER_H_
|
#endif // CMD_ARG_PARSER_H_
|
||||||
@ -1,178 +1,178 @@
|
|||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* File - StringManip.cpp
|
* File - StringManip.cpp
|
||||||
* Author - Joey Pollack
|
* Author - Joey Pollack
|
||||||
* Date - 2018/10/12 (y/m/d)
|
* Date - 2018/10/12 (y/m/d)
|
||||||
* Mod Date - 2018/10/12 (y/m/d)
|
* Mod Date - 2018/10/12 (y/m/d)
|
||||||
* Description - Functions for working with std::string objects
|
* Description - Functions for working with std::string objects
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "StringManip.h"
|
#include "StringManip.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
|
||||||
namespace jpUtils
|
namespace jpUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
std::string StringManip::ToUpper(std::string str)
|
std::string StringManip::ToUpper(std::string str)
|
||||||
{
|
{
|
||||||
std::string result = "";
|
std::string result = "";
|
||||||
for (int i = 0; i < (signed)str.length(); i++)
|
for (int i = 0; i < (signed)str.length(); i++)
|
||||||
{
|
{
|
||||||
if (str[i] >= 97 && str[i] <= 122)
|
if (str[i] >= 97 && str[i] <= 122)
|
||||||
{
|
{
|
||||||
result += str[i] - 32;
|
result += str[i] - 32;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result += str[i];
|
result += str[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string StringManip::ToLower(std::string str)
|
std::string StringManip::ToLower(std::string str)
|
||||||
{
|
{
|
||||||
std::string result = "";
|
std::string result = "";
|
||||||
for (int i = 0; i < (signed)str.length(); i++)
|
for (int i = 0; i < (signed)str.length(); i++)
|
||||||
{
|
{
|
||||||
if (str[i] >= 65 && str[i] <= 90)
|
if (str[i] >= 65 && str[i] <= 90)
|
||||||
{
|
{
|
||||||
result += str[i] + 32;
|
result += str[i] + 32;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result += str[i];
|
result += str[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> StringManip::Split(std::string str, char delim, int maxSplits)
|
std::vector<std::string> StringManip::Split(std::string str, char delim, int maxSplits)
|
||||||
{
|
{
|
||||||
std::vector<std::string> splits;
|
std::vector<std::string> splits;
|
||||||
|
|
||||||
int startPos = 0;
|
int startPos = 0;
|
||||||
for (int i = 0; i < (signed)str.length(); i++)
|
for (int i = 0; i < (signed)str.length(); i++)
|
||||||
{
|
{
|
||||||
if (str[i] == delim)
|
if (str[i] == delim)
|
||||||
{
|
{
|
||||||
if (startPos == i)
|
if (startPos == i)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
std::string s = str.substr(startPos, i - startPos);
|
std::string s = str.substr(startPos, i - startPos);
|
||||||
splits.push_back(s);
|
splits.push_back(s);
|
||||||
startPos = i + 1;
|
startPos = i + 1;
|
||||||
|
|
||||||
if (maxSplits > 0 && (signed)splits.size() >= (maxSplits - 1))
|
if (maxSplits > 0 && (signed)splits.size() >= (maxSplits - 1))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string s = str.substr(startPos);
|
std::string s = str.substr(startPos);
|
||||||
splits.push_back(s);
|
splits.push_back(s);
|
||||||
return splits;
|
return splits;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string StringManip::Trim(std::string str, std::string delims)
|
std::string StringManip::Trim(std::string str, std::string delims)
|
||||||
{
|
{
|
||||||
str = TrimStart(str, delims);
|
str = TrimStart(str, delims);
|
||||||
str = TrimEnd(str, delims);
|
str = TrimEnd(str, delims);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string StringManip::TrimStart(std::string str, std::string delims)
|
std::string StringManip::TrimStart(std::string str, std::string delims)
|
||||||
{
|
{
|
||||||
bool isDelim = true;
|
bool isDelim = true;
|
||||||
while (isDelim && str.length() > 0)
|
while (isDelim && str.length() > 0)
|
||||||
{
|
{
|
||||||
isDelim = false;
|
isDelim = false;
|
||||||
for (int i = 0; i < (signed)delims.length(); i++)
|
for (int i = 0; i < (signed)delims.length(); i++)
|
||||||
{
|
{
|
||||||
if (str[0] == delims[i])
|
if (str[0] == delims[i])
|
||||||
{
|
{
|
||||||
isDelim = true;
|
isDelim = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDelim)
|
if (isDelim)
|
||||||
str.erase(str.begin());
|
str.erase(str.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string StringManip::TrimEnd(std::string str, std::string delims)
|
std::string StringManip::TrimEnd(std::string str, std::string delims)
|
||||||
{
|
{
|
||||||
bool isDelim = true;
|
bool isDelim = true;
|
||||||
while (isDelim && str.length() > 0)
|
while (isDelim && str.length() > 0)
|
||||||
{
|
{
|
||||||
isDelim = false;
|
isDelim = false;
|
||||||
for (int i = 0; i < (signed)delims.length(); i++)
|
for (int i = 0; i < (signed)delims.length(); i++)
|
||||||
{
|
{
|
||||||
if (*(str.rbegin()) == delims[i])
|
if (*(str.rbegin()) == delims[i])
|
||||||
{
|
{
|
||||||
isDelim = true;
|
isDelim = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDelim)
|
if (isDelim)
|
||||||
str.erase((str.rbegin() + 1).base());
|
str.erase((str.rbegin() + 1).base());
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string StringManip::GetFileNameFromPath(std::string path, bool includeExt)
|
std::string StringManip::GetFileNameFromPath(std::string path, bool includeExt)
|
||||||
{
|
{
|
||||||
if (path.find("\\") != std::string::npos || path.find("/") != std::string::npos)
|
if (path.find("\\") != std::string::npos || path.find("/") != std::string::npos)
|
||||||
{
|
{
|
||||||
path.erase(path.begin(), std::find_if(path.rbegin(), path.rend(), [](int ch) { return ch == '\\' || ch == '/'; }).base());
|
path.erase(path.begin(), std::find_if(path.rbegin(), path.rend(), [](int ch) { return ch == '\\' || ch == '/'; }).base());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!includeExt && path.find(".") != std::string::npos)
|
if (!includeExt && path.find(".") != std::string::npos)
|
||||||
{
|
{
|
||||||
path.erase(std::find_if(path.rbegin(), path.rend(), [](int ch) { return ch == '.'; }).base(), path.end());
|
path.erase(std::find_if(path.rbegin(), path.rend(), [](int ch) { return ch == '.'; }).base(), path.end());
|
||||||
path.erase(path.begin() + path.size() - 1);
|
path.erase(path.begin() + path.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string StringManip::TrimFileNameFromPath(std::string path)
|
std::string StringManip::TrimFileNameFromPath(std::string path)
|
||||||
{
|
{
|
||||||
path.erase(std::find_if(path.rbegin(), path.rend(), [](int ch) { return ch == '\\' || ch == '/'; }).base(), path.end());
|
path.erase(std::find_if(path.rbegin(), path.rend(), [](int ch) { return ch == '\\' || ch == '/'; }).base(), path.end());
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string StringManip::GetFileExtension(std::string filename)
|
std::string StringManip::GetFileExtension(std::string filename)
|
||||||
{
|
{
|
||||||
filename.erase(filename.begin(), std::find_if(filename.begin(), filename.end(), [](int ch) { return ch == '.'; }));
|
filename.erase(filename.begin(), std::find_if(filename.begin(), filename.end(), [](int ch) { return ch == '.'; }));
|
||||||
filename.erase(filename.begin());
|
filename.erase(filename.begin());
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int StringManip::AsInt(std::string value)
|
int StringManip::AsInt(std::string value)
|
||||||
{
|
{
|
||||||
return atoi(value.c_str());
|
return atoi(value.c_str());
|
||||||
}
|
}
|
||||||
double StringManip::AsDouble(std::string value)
|
double StringManip::AsDouble(std::string value)
|
||||||
{
|
{
|
||||||
return atof(value.c_str());
|
return atof(value.c_str());
|
||||||
}
|
}
|
||||||
bool StringManip::AsBool(std::string value)
|
bool StringManip::AsBool(std::string value)
|
||||||
{
|
{
|
||||||
return value == std::string("true");
|
return value == std::string("true");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,58 +1,58 @@
|
|||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* File - StringManip.h
|
* File - StringManip.h
|
||||||
* Author - Joey Pollack
|
* Author - Joey Pollack
|
||||||
* Date - 2018/10/12 (y/m/d)
|
* Date - 2018/10/12 (y/m/d)
|
||||||
* Mod Date - 2018/10/12 (y/m/d)
|
* Mod Date - 2018/10/12 (y/m/d)
|
||||||
* Description - Functions for working with std::string objects
|
* Description - Functions for working with std::string objects
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#ifndef STRING_MANIP_H_
|
#ifndef STRING_MANIP_H_
|
||||||
#define STRING_MANIP_H_
|
#define STRING_MANIP_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
namespace jpUtils
|
namespace jpUtils
|
||||||
{
|
{
|
||||||
class StringManip
|
class StringManip
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Generic string helpers
|
// Generic string helpers
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
static std::string ToUpper(std::string str);
|
static std::string ToUpper(std::string str);
|
||||||
static std::string ToLower(std::string str);
|
static std::string ToLower(std::string str);
|
||||||
|
|
||||||
// Splits the string based on the given delimiter,
|
// Splits the string based on the given delimiter,
|
||||||
// maxSplit = -1 for unlimited number of splits
|
// maxSplit = -1 for unlimited number of splits
|
||||||
static std::vector<std::string> Split(std::string str, char delim = ' ', int maxSplits = -1);
|
static std::vector<std::string> Split(std::string str, char delim = ' ', int maxSplits = -1);
|
||||||
|
|
||||||
// Trim given delimiters from start and end of string
|
// Trim given delimiters from start and end of string
|
||||||
static std::string Trim(std::string str, std::string delims = " \r\n\t");
|
static std::string Trim(std::string str, std::string delims = " \r\n\t");
|
||||||
|
|
||||||
// Trim given delimiters from start of string
|
// Trim given delimiters from start of string
|
||||||
static std::string TrimStart(std::string str, std::string delims = " \r\n\t");
|
static std::string TrimStart(std::string str, std::string delims = " \r\n\t");
|
||||||
|
|
||||||
// Trim given delimiters from end of string
|
// Trim given delimiters from end of string
|
||||||
static std::string TrimEnd(std::string str, std::string delims);
|
static std::string TrimEnd(std::string str, std::string delims);
|
||||||
|
|
||||||
|
|
||||||
// File path helpers
|
// File path helpers
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
static std::string GetFileNameFromPath(std::string path, bool includeExt = true);
|
static std::string GetFileNameFromPath(std::string path, bool includeExt = true);
|
||||||
static std::string TrimFileNameFromPath(std::string path);
|
static std::string TrimFileNameFromPath(std::string path);
|
||||||
static std::string GetFileExtension(std::string filename);
|
static std::string GetFileExtension(std::string filename);
|
||||||
|
|
||||||
// Type Conversion
|
// Type Conversion
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
static int AsInt(std::string value);
|
static int AsInt(std::string value);
|
||||||
static double AsDouble(std::string value);
|
static double AsDouble(std::string value);
|
||||||
static bool AsBool(std::string value);
|
static bool AsBool(std::string value);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // STRING_MANIP_H_
|
#endif // STRING_MANIP_H_
|
||||||
Loading…
Reference in New Issue