From: Gerd v. Egidy Date: Wed, 25 Aug 2004 09:01:49 +0000 (+0000) Subject: libi2ncommon: (gerd) merge escape into stringfunc X-Git-Tag: v2.6~255 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=47c07fbac542e7492549118b96b449c68605c38f;p=libi2ncommon libi2ncommon: (gerd) merge escape into stringfunc --- diff --git a/aclocal.m4 b/aclocal.m4 index 55aea75..cd168bd 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -1,4 +1,4 @@ -dnl ./aclocal.m4 generated automatically by aclocal 1.4-p5 +dnl aclocal.m4 generated automatically by aclocal 1.4-p5 dnl Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation diff --git a/libi2ncommon.kdevelop b/libi2ncommon.kdevelop index b97b7e9..a7908ae 100644 --- a/libi2ncommon.kdevelop +++ b/libi2ncommon.kdevelop @@ -1,25 +1,26 @@ - + - - Gerd v. Egidy - info@intra2net.com - 0.1 - KDevAutoProject - C++ - - C++ - Code - - - - src/libi2ncommon - debug + Gerd v. Egidy + info@intra2net.com + 0.1 + KDevAutoProject + C++ + + C++ + Code + - - src/libi2ncommon - true - + + + src/libi2ncommon + debug + + + src/libi2ncommon + true + executable + optimized @@ -37,8 +38,14 @@ -O0 -g3 - - + + + + + + + + ada ada_bugs_gcc @@ -83,17 +90,38 @@ KDE Libraries (Doxygen) - - - - - - - - + + + + + + + + + false + false - + + *.o,*.lo,CVS + false + + + + + + true + true + true + false + true + true + true + 250 + 400 + 250 + + diff --git a/src/Makefile.am b/src/Makefile.am index 27e72a3..0f5bc55 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,8 +4,8 @@ INCLUDES = -I$(top_srcdir)/src @LIBGETTEXT_CFLAGS@ $(all_includes) # the library search path. lib_LTLIBRARIES = libi2ncommon.la -include_HEADERS = escape.hxx insocketstream.hxx oftmpstream.hxx pipestream.hxx filefunc.hxx stringfunc.hxx timefunc.hxx ipfunc.hxx -libi2ncommon_la_SOURCES = oftmpstream.cpp escape.cpp ipfunc.cpp timefunc.cpp filefunc.cpp stringfunc.cpp +include_HEADERS = insocketstream.hxx oftmpstream.hxx pipestream.hxx filefunc.hxx stringfunc.hxx timefunc.hxx ipfunc.hxx +libi2ncommon_la_SOURCES = oftmpstream.cpp ipfunc.cpp timefunc.cpp filefunc.cpp stringfunc.cpp # Note: If you specify a:b:c as the version in the next line, # the library that is made has version (a-c).c.b. In this diff --git a/src/escape.cpp b/src/escape.cpp deleted file mode 100644 index 04a3407..0000000 --- a/src/escape.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/*************************************************************************** - escape.cpp - escaping of strings - ------------------- - begin : Sun Nov 14 1999 - copyright : (C) 1999 by Intra2net AG - email : info@intra2net.com - ***************************************************************************/ - -#include -#include -#include - -using namespace std; - -string escape(const string &s) -{ - string out(s); - string::size_type p; - - p=0; - while ((p=out.find_first_of("\"\\",p))!=out.npos) - { - out.insert(p,"\\"); - p+=2; - } - - p=0; - while ((p=out.find_first_of("\r",p))!=out.npos) - { - out.replace(p,1,"\\r"); - p+=2; - } - - p=0; - while ((p=out.find_first_of("\n",p))!=out.npos) - { - out.replace(p,1,"\\n"); - p+=2; - } - - out='"'+out+'"'; - - return out; -} - -string descape(const string &s, int startpos, int &endpos) -{ - string out; - - if (s.at(startpos) != '"') - throw out_of_range("value not type escaped string"); - - out=s.substr(startpos+1); - string::size_type p=0; - - // search for the end of the string - while((p=out.find("\"",p))!=out.npos) - { - int e=p-1; - bool escaped=false; - - // the " might be escaped with a backslash - while(e>=0 && out.at(e)=='\\') - { - if (escaped == false) - escaped=true; - else - escaped=false; - - e--; - } - - if (escaped==false) - break; - else - p++; - } - - // we now have the end of the string - out=out.substr(0,p); - - // tell calling prog about the endposition - endpos=startpos+p+1; - - // descape all \ stuff inside the string now - p=0; - while((p=out.find_first_of("\\",p))!=out.npos) - { - switch(out.at(p+1)) - { - case 'r': - out.replace(p,2,"\r"); - break; - case 'n': - out.replace(p,2,"\n"); - break; - default: - out.erase(p,1); - } - p++; - } - - return out; -} - -string escape_shellarg(const string &input) -{ - if (!input.size()) - return ""; - - string output = "'"; - string::const_iterator it, it_end = input.end(); - for (it = input.begin(); it != it_end; it++) { - if ((*it) == '\'') - output += "'\\'"; - - output += *it; - } - - output += "'"; - return output; -} diff --git a/src/escape.hxx b/src/escape.hxx deleted file mode 100644 index 8ab22f3..0000000 --- a/src/escape.hxx +++ /dev/null @@ -1,25 +0,0 @@ -/*************************************************************************** - escape.hxx - escaping of strings - ------------------- - begin : Sun Nov 14 1999 - copyright : (C) 1999 by Intra2net AG - email : info@intra2net.com - ***************************************************************************/ - -#ifndef __ESCAPE_HXX -#define __ESCAPE_HXX - -#include - -std::string escape(const std::string &s); - -std::string descape(const std::string &s, int startpos, int &endpos); -std::string descape(const std::string &s) -{ - int endpos; - return descape(s,0,endpos); -} - -std::string escape_shellarg(const std::string &input); - -#endif diff --git a/src/stringfunc.cpp b/src/stringfunc.cpp index ae53e36..8f6e14a 100644 --- a/src/stringfunc.cpp +++ b/src/stringfunc.cpp @@ -197,4 +197,111 @@ string nice_unit_format (int input) { return out.str(); } +string escape(const string &s) +{ + string out(s); + string::size_type p; + + p=0; + while ((p=out.find_first_of("\"\\",p))!=out.npos) + { + out.insert(p,"\\"); + p+=2; + } + + p=0; + while ((p=out.find_first_of("\r",p))!=out.npos) + { + out.replace(p,1,"\\r"); + p+=2; + } + + p=0; + while ((p=out.find_first_of("\n",p))!=out.npos) + { + out.replace(p,1,"\\n"); + p+=2; + } + + out='"'+out+'"'; + + return out; +} + +string descape(const string &s, int startpos, int &endpos) +{ + string out; + + if (s.at(startpos) != '"') + throw out_of_range("value not type escaped string"); + + out=s.substr(startpos+1); + string::size_type p=0; + + // search for the end of the string + while((p=out.find("\"",p))!=out.npos) + { + int e=p-1; + bool escaped=false; + + // the " might be escaped with a backslash + while(e>=0 && out.at(e)=='\\') + { + if (escaped == false) + escaped=true; + else + escaped=false; + + e--; + } + + if (escaped==false) + break; + else + p++; + } + + // we now have the end of the string + out=out.substr(0,p); + + // tell calling prog about the endposition + endpos=startpos+p+1; + + // descape all \ stuff inside the string now + p=0; + while((p=out.find_first_of("\\",p))!=out.npos) + { + switch(out.at(p+1)) + { + case 'r': + out.replace(p,2,"\r"); + break; + case 'n': + out.replace(p,2,"\n"); + break; + default: + out.erase(p,1); + } + p++; + } + + return out; +} +string escape_shellarg(const string &input) +{ + if (!input.size()) + return ""; + + string output = "'"; + string::const_iterator it, it_end = input.end(); + for (it = input.begin(); it != it_end; it++) { + if ((*it) == '\'') + output += "'\\'"; + + output += *it; + } + + output += "'"; + return output; +} diff --git a/src/stringfunc.hxx b/src/stringfunc.hxx index d2dd417..bacaff1 100644 --- a/src/stringfunc.hxx +++ b/src/stringfunc.hxx @@ -24,4 +24,15 @@ std::string iso_to_utf8(const std::string& isostring); std::string utf8_to_iso(const std::string& utf8string); std::string iso_to_html(const std::string& isostring); +std::string escape(const std::string &s); + +std::string descape(const std::string &s, int startpos, int &endpos); +std::string descape(const std::string &s) +{ + int endpos; + return descape(s,0,endpos); +} + +std::string escape_shellarg(const std::string &input); + #endif diff --git a/stamp-h.in b/stamp-h.in index e69de29..9788f70 100644 --- a/stamp-h.in +++ b/stamp-h.in @@ -0,0 +1 @@ +timestamp