[sword-cvs] sword/src/utilfuns utilweb.cpp,1.2,1.3
sword@www.crosswire.org
sword@www.crosswire.org
Fri, 6 Jun 2003 11:25:58 -0700
Update of /usr/local/cvsroot/sword/src/utilfuns
In directory www:/tmp/cvs-serv10529/src/utilfuns
Modified Files:
utilweb.cpp
Log Message:
filter fixes, encodeURL fixes
Index: utilweb.cpp
===================================================================
RCS file: /usr/local/cvsroot/sword/src/utilfuns/utilweb.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** utilweb.cpp 3 Jun 2003 23:00:47 -0000 1.2
--- utilweb.cpp 6 Jun 2003 18:25:56 -0000 1.3
***************
*** 1,5 ****
-
#include <utilxml.h>
- #include <ctype.h>
#include <string>
#include <map>
--- 1,3 ----
***************
*** 9,36 ****
using std::string;
using std::map;
- using std::pair;
! typedef pair<string,string> DataPair;
! typedef map<string,string> DataMap;
const std::string encodeURL( const std::string& url ) {
! string buf( url );
!
! DataMap m;
! m[" "] = "+";
! m[":"] = "%3A";
!
! DataMap::iterator it;
! for (it = m.begin(); it != m.end(); ++it) {
! string search = it->first;
! string replace = it->second;
! while (true) {
! string::size_type idx = buf.find(search);
! if (idx == string::npos)
! break;
! buf.replace(idx, search.length(), replace);
! }
}
--- 7,31 ----
using std::string;
using std::map;
! typedef map<unsigned char,string> DataMap;
const std::string encodeURL( const std::string& url ) {
! DataMap m;
! for (unsigned short int c = 32; c <= 255; ++c) { //first set all encoding chars
! if ( (c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9') || strchr("-_.!~*'()", c)) {
! continue; //we don't need an encoding for this char
! }
! char s[3];
! snprintf(s, 3, "%-.2X", c); //left-aligned, 2 digits, uppercase hex
! m[c] = string("%") + s; //encoded char is "% + 2 digit hex code of char"
! }
! //the special encodings for certain chars
! m[' '] = '+';
! string buf;
! for (int i = 0; i <= url.length(); i++) { //fill "buf"
! const char c = url[i];
! buf += m[c].empty() ? string(1,c) : m[c];
}