update
This commit is contained in:
parent
d7ede1e333
commit
0b5338d157
@ -1,45 +0,0 @@
|
||||
#include <tools.hpp>
|
||||
#include <string_view>
|
||||
|
||||
void print_help(){
|
||||
zt::print("if you want help please add \"-h\"\n");
|
||||
}
|
||||
|
||||
int main(const int argc,const char *argv[]){
|
||||
if(argc==1){
|
||||
print_help();
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
std::string argv1(argv[1]);
|
||||
if(argc==2){
|
||||
if(argv1=="-h"){
|
||||
zt::print("help:\n","\tThis is a simple string replacer to replace characters of the same length.\n","\t<string> <character to be replaced> <character to replace>\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()){
|
||||
zt::eprint("The length of last two characters are not same!\n");
|
||||
exit(-1);
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
zt::print(argv1,"\n");
|
||||
}
|
50
src/repstr/main.cpp
Normal file
50
src/repstr/main.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#include <stdexcept>
|
||||
#include <tools.hpp>
|
||||
#include <string_view>
|
||||
|
||||
void print_help_exit(){
|
||||
throw std::runtime_error("if you want help please add \"-h\"\n");
|
||||
}
|
||||
|
||||
int main(const int argc,const char *argv[]){
|
||||
try{
|
||||
if(argc==1){
|
||||
print_help_exit();
|
||||
}
|
||||
|
||||
std::string argv1(argv[1]);
|
||||
if(argc==2){
|
||||
if(argv1=="-h"){
|
||||
zt::print("help:\n","\tThis is a simple string replacer to replace characters of the same length.\n","\t<string> <character to be replaced> <character to replace>\n","\t\t-By Zengtudor\n");
|
||||
return 0;
|
||||
}else{
|
||||
print_help_exit();
|
||||
}
|
||||
}else if(argc==4){
|
||||
std::string_view be_replaced(argv[2]),to_replace(argv[3]);
|
||||
if(be_replaced.size()!=to_replace.size()){
|
||||
throw std::runtime_error("The length of last two characters are not same!\n");
|
||||
}
|
||||
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_exit();
|
||||
}
|
||||
|
||||
zt::print(argv1,"\n");
|
||||
|
||||
}catch(std::runtime_error &e){
|
||||
zt::eprint("caught an error because:\n","\te.what(): ",e.what(),"\n");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user