Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » U++ Esc Interpreter, Esc Macros and templates » add more robust mid and some file funcs?
add more robust mid and some file funcs? [message #48560] Tue, 25 July 2017 19:56
luoganda is currently offline  luoganda
Messages: 203
Registered: November 2016
Experienced Member
void SIC_Mid(EscEscape& e){
	String arg0=(String)e[0];
	int arg1=e[1].GetInt(); if(arg1<0)arg1=arg0.GetCount()-abs(arg1); if(arg1>=arg0.GetCount())e.ThrowError("'mid': arg1 out of bounds");
	int arg2=e[2].GetInt(); if(arg2==-pow(2,31))arg2=arg0.GetCount()-arg1; if(arg2<0)arg2=arg0.GetCount()-abs(arg2); if(arg1+arg2>arg0.GetCount())arg2=arg0.GetCount()-arg1; //if(arg1<0){errline("esc: mid: arg1<0");e.ret_val=String::GetVoid();return;}
	e.ret_val=arg0.Mid(arg1,arg2);
}
void SIC_Find(EscEscape& e){
	e.CheckArray(0);
	e.CheckArray(1);
	e.CheckNumber(2);
	e.ret_val=((String)e[0]).Find((String)e[1],e[2].GetInt());
}
void SIC_FileExists(EscEscape& e){
	e.CheckArray(0);
	e.ret_val=FileExists((String)e[0])?1:0;
}
void SIC_FileCopy(EscEscape& e){
	e.CheckArray(0);e.CheckArray(1);
	String arg0=(String)e[0];
	String arg1=(String)e[1];
	if(!arg0.GetCount()||!arg1.GetCount())e.ThrowError("empty string in 'filecopy'");
	if(arg1[arg1.GetCount()-1]=='\\'||arg1[arg1.GetCount()-1]=='/')arg1<<GetFileName(arg0);
	e.ret_val=FileCopy(arg0,arg1)?1:0;
}
void SIC_FileDelete(EscEscape& e){
	e.CheckArray(0);
	e.ret_val=FileDelete((String)e[0])?1:0;
}

//from:<0MeansFromEnd,num:-pow(2,31) means till end, eg mid(txt,-4) - note,from/num may be both negative
Escape(escglobal,"mid(text,from,num=-pow(2,31))",SIC_Mid);
Escape(escglobal,"find(text,find,from=0)",SIC_Find);
Escape(escglobal,"fileexists(fname)",SIC_FileExists);
//dest may end with ".../dir/" so this can be used: filecopy("c:/files/main.txt","c:/backup/");
Escape(escglobal,"filecopy(src,dest)",SIC_FileCopy);
Escape(escglobal,"filedelete(fname)",SIC_FileDelete);


If adding these, check prev post in this thread too

[Updated on: Tue, 25 July 2017 20:00]

Report message to a moderator

Previous Topic: adding to_number(hex) and find?
Next Topic: continue bug
Goto Forum:
  


Current Time: Sun Jun 16 18:27:04 CEST 2024

Total time taken to generate the page: 0.01351 seconds