summaryrefslogtreecommitdiff
path: root/src/utilfuns/url.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/utilfuns/url.cpp')
-rw-r--r--src/utilfuns/url.cpp38
1 files changed, 23 insertions, 15 deletions
diff --git a/src/utilfuns/url.cpp b/src/utilfuns/url.cpp
index 3a50e2c..549c283 100644
--- a/src/utilfuns/url.cpp
+++ b/src/utilfuns/url.cpp
@@ -1,7 +1,7 @@
/******************************************************************************
* url.cpp - code for an URL parser utility class
*
-* $Id: url.cpp 2013 2006-11-25 22:01:04Z dglassey $
+* $Id: url.cpp 2250 2009-02-14 05:48:58Z scribe $
*
* Copyright 2003 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
@@ -31,6 +31,27 @@
SWORD_NAMESPACE_START
+namespace {
+ typedef std::map< unsigned char, SWBuf > DataMap;
+ DataMap m;
+ static class __init {
+ public:
+ __init() {
+ 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
+ }
+
+ SWBuf buf;
+ buf.setFormatted("%%%-.2X", c);
+ m[c] = buf;
+ }
+ //the special encodings for certain chars
+ m[' '] = '+';
+ }
+ } ___init;
+}
+
/**
* Constructors/Destructors
*/
@@ -197,24 +218,11 @@ void URL::parse () {
}
}
+
const SWBuf URL::encode(const char *urlText) {
/*static*/ SWBuf url;
url = urlText;
- typedef std::map< unsigned char, SWBuf > DataMap;
- 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
- }
-
- SWBuf buf;
- buf.setFormatted("%%%-.2X", c);
- m[c] = buf;
- }
- //the special encodings for certain chars
- m[' '] = '+';
-
SWBuf buf;
const int length = url.length();
for (int i = 0; i < length; i++) { //fill "buf"