diff --git a/.gitmodules b/.gitmodules index 90e3bc2..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "3rdparty/vcpkg"] - path = 3rdparty/vcpkg - url = https://github.com/microsoft/vcpkg diff --git a/3rdparty/vcpkg b/3rdparty/vcpkg deleted file mode 160000 index f14984a..0000000 --- a/3rdparty/vcpkg +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f14984af3738e69f197bf0e647a8dca12de92996 diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 74563ea..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -cmake_minimum_required(VERSION 3.18.4) - -if(NOT DEFINED VCPKG_ROOT_PATH) - set(VCPKG_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/vcpkg) -endif() - -if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) - set(TOOLCHAIN_PATH ${VCPKG_ROOT_PATH}/scripts/buildsystems/vcpkg.cmake) - - set(CMAKE_TOOLCHAIN_FILE - "${TOOLCHAIN_PATH}" - CACHE STRING "Vcpkg toolchain file") - - message("Using default toolchain file") -endif() - - -project(clean_files CXX) - - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) - -find_package(nlohmann_json CONFIG REQUIRED) - - -add_executable(clean_files src/main.cpp) -target_link_libraries(clean_files PRIVATE nlohmann_json nlohmann_json::nlohmann_json) diff --git a/clean_file.sln b/clean_file.sln deleted file mode 100644 index d28a507..0000000 --- a/clean_file.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.2.32630.192 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "clean_file", "clean_file.vcxproj", "{27781E3A-B63A-4158-A915-7A4A9DA6D187}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {27781E3A-B63A-4158-A915-7A4A9DA6D187}.Debug|x64.ActiveCfg = Debug|x64 - {27781E3A-B63A-4158-A915-7A4A9DA6D187}.Debug|x64.Build.0 = Debug|x64 - {27781E3A-B63A-4158-A915-7A4A9DA6D187}.Debug|x86.ActiveCfg = Debug|Win32 - {27781E3A-B63A-4158-A915-7A4A9DA6D187}.Debug|x86.Build.0 = Debug|Win32 - {27781E3A-B63A-4158-A915-7A4A9DA6D187}.Release|x64.ActiveCfg = Release|x64 - {27781E3A-B63A-4158-A915-7A4A9DA6D187}.Release|x64.Build.0 = Release|x64 - {27781E3A-B63A-4158-A915-7A4A9DA6D187}.Release|x86.ActiveCfg = Release|Win32 - {27781E3A-B63A-4158-A915-7A4A9DA6D187}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {FD15EEA8-C66D-4B6F-A98D-227633B840D6} - EndGlobalSection -EndGlobal diff --git a/clean_file.vcxproj b/clean_file.vcxproj deleted file mode 100644 index 928ca22..0000000 --- a/clean_file.vcxproj +++ /dev/null @@ -1,115 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 17.0 - {27781E3A-B63A-4158-A915-7A4A9DA6D187} - Win32Proj - - - - Application - true - v143 - - - Application - false - v143 - - - Application - true - v143 - - - Application - false - v143 - - - - - - - - - - - - - - - - - - - - - true - - - true - - - $(ProjectDir)inculde;$(ProjectDir);$(IncludePath) - - - $(ProjectDir)inculde;$(ProjectDir);$(IncludePath) - - - - WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - MultiThreadedDebugDLL - Level3 - ProgramDatabase - Disabled - - - MachineX86 - true - Windows - - - - - WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - MultiThreadedDLL - Level3 - ProgramDatabase - - - MachineX86 - true - Windows - true - true - - - - - - - - - - - - \ No newline at end of file diff --git a/include/number_parser.hpp b/include/number_parser.hpp deleted file mode 100644 index 0315e5d..0000000 --- a/include/number_parser.hpp +++ /dev/null @@ -1,232 +0,0 @@ -#ifndef NUMBER_PARSER_H_ -#define NUMBER_PARSER_H_ - -#include -#include -#include -#include -#include -#include - -#include "nlohmann/json.hpp" - - -namespace parser -{ - -class some_object -{ -public: - some_object() = default; - some_object(std::string value) : - value(value) - { - } - - ~some_object() = default; - - std::string value; -private: -}; - - -template -class number_parser -{ -public: - number_parser(const std::string &filepath) : - filepath(filepath) - { } - - template> - Con file_dump() - { - Con container; - - std::fstream file(this->filepath.c_str(), std::ios::in); - - if (!file.is_open()) - { - std::cout << "File is not openned...\n"; - std::cout << "Openning file: " << this->filepath << "\n"; - file.open(filepath.c_str()); - } - - std::string line; - int i = 0; - - while (std::getline(file, line)) - { - if (line.size() > 1) - { - container.push_back(line); - } - } - - file.close(); - - return container; - } - - template> - Con update_values(const Con &values) - { - Con container; - std::vector remove_chars; - remove_chars.reserve(4); - remove_chars.push_back(')'); - remove_chars.push_back('('); - remove_chars.push_back(32); - remove_chars.push_back('-'); - - auto prefix = "+1"; - std::string parsed; - - for (const auto &item : values) - { - parsed.assign(item.value); - - if (parsed.size() < 2) - { - std::cout << parsed << " is an invalid number. Continuing with the next number\n"; - continue; - } - - auto pars = remove_some_data(parsed, remove_chars); - parsed.clear(); - parsed.assign(pars); - - add_prefix(parsed); - - container.push_back(parsed); - parsed.clear(); - } - - return container; - } - - template> - void remove_duplicates(Con &container) - { - std::set tmpContainer; - - auto act = [&](Obj& ob) - { - tmpContainer.emplace(ob.value); - }; - - std::for_each(container.begin(), container.end(), act); - container.clear(); - - auto actReplace = [&](std::string value) - { - Obj o(value); - container.emplace_back(o); - }; - - std::for_each(tmpContainer.begin(), tmpContainer.end(), actReplace); - } - - template> - void save_file(const Con container) - { - std::set my_set; - - const std::string filepath("my_file.json");; - - for (const auto &s : container) - { - my_set.insert(s.value); - } - - - nlohmann::json j(my_set); - - std::cout << "Saving data to file: " << filepath << "\n"; - - std::fstream output(filepath.c_str(), std::ios::out); - output << j.dump(4); - - output.close(); - - std::cout << "The file has been saved\n"; - } - - template> - void print_values(const Con container) - { - if (!(container.size() > 0)) - { - std::cout << "Empty container\n"; - return; - } - - std::cout << "Printing values\n"; - - for (const auto &item : container) - { - std::cout << "Value: " << item.value << "\n"; - } - } -private: - std::string remove_some_data(const std::string &unparsed, const std::vector &remove_chars) - { - std::string parsed; - - std::cout << "Unparsed: " << unparsed << "\n"; - - for (auto i = 0; i < unparsed.size(); ++i) - { - char c = unparsed.at(i); - - if (std::isdigit(c)) - { - parsed.append(std::to_string(c-48)); - } - } - - std::cout << "Parsed: " << parsed << "\n"; - - return parsed; - } - - void add_prefix(std::string &parsed) - { - auto last_char = parsed.at(parsed.size() - 1); - auto first_char = parsed.at(0); - auto second_char = parsed.at(1); - - - if (first_char == '1') - { - parsed.insert(0, "+"); - } - else if (first_char != '+') - { - if (second_char != '1') - { - parsed.insert(0, "+1"); - } - else - { - parsed.insert(0, "+1"); - } - } - } - - int add_prefix_if_not_found(std::string &parsed, const std::string &prefixes) - { - auto prefix_size = prefixes.size(); - auto parsed_beginning = parsed.substr(0, prefix_size); - - return 0; - } - - - std::string filepath; -}; - -} - - -#endif diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index f3edfde..0000000 --- a/src/main.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "number_parser.hpp" - -using std::cout; -using std::string; -using std::vector; -using std::fstream; -using std::stringstream; - - -int main(int argc, char **argv) -{ - cout << "clean_files\n"; - - if (argc < 2) - { - cout << "Provide path to file\n"; - - return -1; - } - - const string filepath(argv[1]); - parser::number_parser file_parser(filepath); - auto raw_values = file_parser.file_dump(); - - auto parsed_values = file_parser.update_values(raw_values); - file_parser.remove_duplicates(parsed_values); - - file_parser.print_values(parsed_values); - file_parser.save_file(parsed_values); - - - return 0; -}