28 #ifndef __ETL__STRINGF_H
29 #define __ETL__STRINGF_H
44 #ifndef ETL_STRPRINTF_MAX_LENGTH
45 #define ETL_STRPRINTF_MAX_LENGTH (800)
49 #define POPEN_BINARY_READ_TYPE "rb"
50 #define POPEN_BINARY_WRITE_TYPE "wb"
52 #define POPEN_BINARY_READ_TYPE "r"
53 #define POPEN_BINARY_WRITE_TYPE "w"
60 #if defined(__APPLE__) || defined(__CYGWIN__) || defined(_WIN32)
63 #define ETL_NO_THROW throw()
69 #ifdef HAVE_VASPRINTF // This is the preferred method
71 extern int vasprintf(
char **,
const char *,va_list)
ETL_NO_THROW;
75 # ifdef HAVE_VSNPRINTF // This is the secondary method
77 extern int vsnprintf(
char *,
size_t,
const char*,va_list)ETL_NO_THROW;
85 extern int vsscanf(
const char *,
const char *,va_list)ETL_NO_THROW;
88 #define ETL_NO_VSTRSCANF
91 extern int sscanf(
const char *buf,
const char *format, ...)ETL_NO_THROW;
107 #ifdef HAVE_VASPRINTF // This is the preferred method (and safest)
110 int i=vasprintf(&buffer,format,args);
118 #ifdef HAVE_VSNPRINTF // This is the secondary method (Safe, but bulky)
119 #warning etl::vstrprintf() has a maximum size of ETL_STRPRINTF_MAX_LENGTH in this configuration.
120 #ifdef ETL_THREAD_SAFE
125 vsnprintf(buffer,
sizeof(buffer),format,args);
127 #else // This is the worst method (UNSAFE, but "works")
128 #warning Potential for Buffer-overflow bug using vsprintf
129 #define ETL_UNSAFE_STRPRINTF (true)
132 #ifdef ETL_THREAD_SAFE
137 vsprintf(buffer,format,args);
147 va_start(args,format);
151 #ifndef ETL_NO_VSTRSCANF
153 vstrscanf(
const std::string &data,
const char*format, va_list args)
155 return vsscanf(data.c_str(),format,args);
159 strscanf(
const std::string &data,
const char*format, ...)
162 va_start(args,format);
163 return vstrscanf(data, format,args);
168 #define strscanf(data,format,...) sscanf(data.c_str(),format,__VA_ARGS__)
173 #define stratof(X) (atof((X).c_str()))
174 #define stratoi(X) (atoi((X).c_str()))
184 std::string::const_iterator iter;
194 for(;iter!=str.begin();iter--)
202 return std::string(iter,str.end()-1);
204 return std::string(iter,str.end());
210 std::string::const_iterator iter;
220 for(;iter!=str.begin();iter--)
224 if(iter==str.begin())
232 return std::string(str.begin(),iter);
240 std::string::size_type pos = base.find_last_of(
'.');
241 if (pos == std::string::npos)
return std::string();
242 return base.substr(pos);
250 std::string::size_type pos = base.find_last_of(
'.');
251 if (pos == std::string::npos)
return str;
252 std::string dir =
dirname(str);
253 if (dir ==
".")
return base.substr(0,pos);
261 if(path.size()>=3 && path[1]==
':' &&
is_separator(path[2]))
273 std::string::const_iterator iter;
274 for(iter=path.begin();iter!=path.end();iter++)
294 std::string ret(getcwd(dir,
sizeof(dir)));
302 std::string::const_iterator iter;
304 for(iter=path.begin();iter!=path.end();++iter)
322 path.erase(path.begin());
325 path.erase(path.begin());
340 if((dir.size() == 3 && dir[0] ==
'.' && dir[1] ==
'.' &&
is_separator(dir[2])) && ret.size())
346 else if((dir!=
"./" && dir!=
".\\") && dir!=
".")
350 if (ret.size()==0)ret+=
'.';
354 ret.erase(ret.begin()+ret.size()-1);
388 if(dest_path.size()>=3 && dest_path[1]==
':' && dest_path[0]!=curr_path[0])
392 if(curr_path==
dirname(dest_path))
401 while(!curr_path.empty())