diff --git a/src/replaceStr/main.cpp b/src/replaceStr/main.cpp index cd001da..60530c0 100644 --- a/src/replaceStr/main.cpp +++ b/src/replaceStr/main.cpp @@ -1,47 +1,42 @@ -#include -#include +#include +#include +#include -template -void print(const Args&...args){ - std::stringstream ss; - ((ss< -class Range{ -private: - T _start,_end,_step; -public: - Range(const T start,const T end){Range(start,end,1);} - Range(const T start,const T end,const T step):_start(start),_end(end),_step(step){} - - struct Iterator{ - T current; - T step; - Iterator()=delete; - Iterator(const T start)noexcept{Iterator(start,1);} - Iterator(const T start,const T step)noexcept:current(start),step(step){} - bool operator!=(const Iterator &other)const noexcept{ - return current \n","\t\t-By Zengtudor\n"); + }else{ + print_help(); + } + }else if(argc==4){ + std::string_view be_replaced(argv[2]),to_replace(argv[3]); + if(be_replaced.size()!=to_replace.size()){ + goto end; + } + for(auto i: zt::Range((size_t)0,argv1.size())){ + if(argv1[i]==be_replaced[0]){ + for(auto j: zt::Range((size_t)0,be_replaced.size())){ + if(argv1[i+j]!=be_replaced[j]){ + goto out_of_match; + } + } + for(auto j:zt::Range((size_t)0,be_replaced.size())){ + argv1[i+j]=to_replace[j]; + } + } + out_of_match:; + } + }else{ + print_help(); } - print("\n"); + + zt::print(argv1,"\n"); + + end:; } \ No newline at end of file diff --git a/src/tools/tools.hpp b/src/tools/tools.hpp new file mode 100644 index 0000000..423340c --- /dev/null +++ b/src/tools/tools.hpp @@ -0,0 +1,50 @@ +#pragma once + +#include +#include + +#define NAME_VALUE(v)#v," : ",(v) + +namespace zt { + template + class Range{ + private: + T _start,_end,_step; + public: + // constexpr Range()=delete; + constexpr Range(const T start,const T end,const T step)noexcept:_start(start),_end(end),_step(step){} + constexpr Range(const T start,const T end)noexcept:Range(start,end,1){} + constexpr Range(const T end)noexcept:Range(1,end,1){} + + struct Iterator{ + T current,step; + constexpr Iterator()=delete; + constexpr Iterator(const T start,const T step)noexcept:current(start),step(step){} + constexpr bool operator!=(const Iterator &other)const noexcept{ + return current + void print(const Args&...args){ + std::stringstream ss; + ((ss<