[Ante-cvs] SF.net SVN: ante: [490] trunk/ant/skills/include
Brought to you by:
roguestar191
|
From: <rog...@us...> - 2007-08-15 06:24:51
|
Revision: 490
http://ante.svn.sourceforge.net/ante/?rev=490&view=rev
Author: roguestar191
Date: 2007-08-14 23:24:49 -0700 (Tue, 14 Aug 2007)
Log Message:
-----------
Added missing strhelp files
Added Paths:
-----------
trunk/ant/skills/include/strhelp.cpp
trunk/ant/skills/include/strhelp.h
Added: trunk/ant/skills/include/strhelp.cpp
===================================================================
--- trunk/ant/skills/include/strhelp.cpp (rev 0)
+++ trunk/ant/skills/include/strhelp.cpp 2007-08-15 06:24:49 UTC (rev 490)
@@ -0,0 +1,29 @@
+#include "strhelp.h"
+
+std::string strcpy(std::string &in) {
+ std::string ret;
+ for(size_t x = 0, end = in.size(); x < end; x++) ret += in[x];
+ return ret;
+}
+void trim(std::string&in) {
+ std::string ret;
+ for(size_t x = 0, end = in.size(); x < end; x++) {
+ if(in[x] != '\r' && in[x] != '\n') ret += in[x];
+ }
+ in.erase();
+ in = strcpy(ret);
+}
+
+std::string readResponse() {
+ std::cout.flush();
+ std::string response;
+ char buffer = 0;
+ while((buffer = std::cin.get()) != '\n') {
+ response += buffer;
+ }
+ trim(response);
+ return response;
+};
+
+
+
Added: trunk/ant/skills/include/strhelp.h
===================================================================
--- trunk/ant/skills/include/strhelp.h (rev 0)
+++ trunk/ant/skills/include/strhelp.h 2007-08-15 06:24:49 UTC (rev 490)
@@ -0,0 +1,75 @@
+#ifdef STRHELP_INC
+#else
+#define STRHELP_INC 1
+#include <iostream>
+#include <string>
+#include <vector>
+inline void replaceAll(std::string&in,std::string from, std::string to) {
+ size_t find = in.find(from);
+ while(find != std::string::npos) {
+ in.replace(find, from.size(), to);
+ find = in.find(from, find+to.size());
+ }
+}
+
+std::string strcpy(std::string &in);
+void trim(std::string&in);
+std::string readResponse();
+inline void strcpy(std::string &to, std::string &from) {
+ for(size_t scroller = 0, end = from.size(); scroller != end; scroller++) {
+ to += from[scroller];
+ }
+}
+inline void strcpy2(std::string &to, std::string from) {
+ for(size_t scroller = 0, end = from.size(); scroller != end; scroller++) {
+ to += from[scroller];
+ }
+}
+inline std::vector<std::string> strToVec(std::string &in, bool newl = false, char sep=' ') {
+ std::vector<std::string> strvec;
+ {
+ std::string::const_iterator scroller = in.begin(), end = in.end();
+ //size_t last = 0, next = 0;
+ bool quote = false;
+ bool escape = false;
+ std::string temp;
+ for(scroller = in.begin(); scroller < end; scroller++)
+ {
+ if(escape) {
+ temp += *scroller;
+ escape = false;
+ continue;
+ }
+ if(*scroller == '\\') { escape = true; continue; };
+ if(*scroller=='\"') {
+ if(quote) {
+ quote = false;
+ } else {
+ quote = true;
+ }
+ continue;
+ }
+ if(*scroller==sep && !quote) {
+ if(temp.size() > 0)
+ strvec.push_back(temp);
+ temp.erase();
+ continue;
+ } if( !newl && (*scroller != '\r' && *scroller != '\n'))
+ temp += *scroller;
+ else if(newl){ if(*scroller == '\r') continue; if(*scroller == '\n') { temp.append("\r\n"); continue; } else temp += *scroller;}
+
+ }
+ if(temp.size() > 0) strvec.push_back(temp);
+ }
+ if(strvec.size() == 0) {
+ std::string mpty = "\r\n";
+ strvec.push_back(mpty);
+ }
+ return strvec;
+}
+inline void lower(std::string&what) {
+std::transform(what.begin(), what.end(), what.begin(),static_cast < int(*)(int) > (tolower));
+
+}
+#endif
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|