Code

Tweak to use Glib::ustring. Remove warnings.
authorishmal <ishmal@users.sourceforge.net>
Sat, 22 Apr 2006 10:48:46 +0000 (10:48 +0000)
committerishmal <ishmal@users.sourceforge.net>
Sat, 22 Apr 2006 10:48:46 +0000 (10:48 +0000)
src/dom/cssparser.cpp
src/dom/dom.h
src/dom/domimpl.cpp
src/dom/lsimpl.cpp
src/dom/svg/svgparser.cpp
src/dom/uri.cpp
src/dom/uri.h
src/dom/util/ziptool.cpp
src/dom/xmlreader.cpp
src/dom/xpathparser.cpp

index 2dc342704f8faa556a42dd3f41e05228045620a9..8f245c06dfa90d0d9f3cee647e8ab9aa05f4229a 100644 (file)
@@ -135,7 +135,7 @@ bool CssParser::match(int pos, char *str)
 {
     while (*str)
        {
-       if (get(pos++) != *str++)
+       if (get(pos++) != (XMLCh) *str++)
            return false;
        }
    return true;
@@ -1622,7 +1622,7 @@ bool CssParser::parseFile(const DOMString &fileName)
         int ch = fgetc(f);
         if (ch<0)
             break;
-        str.push_back(ch);
+        str.push_back((XMLCh)ch);
         }
     fclose(f);
 
index d533a7dca6a721be28fb85822e1401282b0dc57b..2248ad61f0512a2ca0892e66e71a2ddbf24bbb4d 100644 (file)
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <string>
 #include <vector>
 
-#define OWN_STRING
+#define DOM_STRING_GLIBMM
 
-#ifdef OWN_STRING
+#ifdef DOM_STRING_OWN
 #include "domstring.h"
 #else
+#ifdef DOM_STRING_GLIBMM
 #include <glibmm.h>
-typedef Glib::ustring DOMString
+#else
+#include <string>
+#endif
 #endif
 
 #define XMLNSNAME "http://www.w3.org/2000/xmlns/"
@@ -52,10 +54,17 @@ namespace dom
 
 
 
-#ifndef OWN_STRING
-typedef unsigned short XMLCh;
+#ifdef DOM_STRING_OWN
+#else
+#ifdef DOM_STRING_GLIBMM
+typedef Glib::ustring DOMString;
+typedef gunichar XMLCh;
+#else
 typedef std::string DOMString;
+typedef unsigned short XMLCh;
 #endif
+#endif
+
 
 /**
  *
index b3197c94805dfe5f69c517b4b84b0a13ac98236f..e9da6291fb3dadec082bb97ef7b639c2b90f47e1 100644 (file)
@@ -862,7 +862,7 @@ void NodeImpl::setNodeName(const DOMString &qualifiedName)
             }
         else
             {
-            localName.push_back(ch);
+            localName.push_back((XMLCh)ch);
             }
         }
 }
index 636dc6750d5f679ac4ee9f18a8423b61c60afa61..65807cc459ea4ca088fc2bea6e65d863d94e45ba 100644 (file)
@@ -76,7 +76,7 @@ Document *LSParserImpl::parse(const LSInput &input)
             int ch = lsreader->get();
             if (ch < 0)
                 break;
-            buf.push_back(ch);
+            buf.push_back((XMLCh)ch);
             }
         XmlReader reader;
         Document *doc = reader.parse(buf);
@@ -92,7 +92,7 @@ Document *LSParserImpl::parse(const LSInput &input)
             int ch = inputStream->get();
             if (ch < 0)
                 break;
-            buf.push_back(ch);
+            buf.push_back((XMLCh)ch);
             }
         XmlReader reader;
         Document *doc = reader.parse(buf);
@@ -176,7 +176,7 @@ bool LSSerializerImpl::write(
 {
     outbuf = "";
     indent = 0;
-    
+
     writeNode(nodeArg);
 
     //## Check in order specified in the L&S specs
index df0470045f041b747eeac74510de3c5ec46a85b4..d2da3150c668ad6be2d6d0e58f0b8fb4aefa44ef 100644 (file)
@@ -93,7 +93,7 @@ bool SvgParser::match(int pos, char *str)
 {
     while (*str)
        {
-       if (get(pos++) != *str++)
+       if (get(pos++) != (XMLCh) *str++)
            return false;
        }
    return true;
index 8f5cf976d9ee92c7b4fb200d496e715b8e1bf8e5..286857e4177c7c87bb160991f90fd613f3f5f729 100644 (file)
@@ -108,14 +108,18 @@ URI::URI(const char *str)
 URI::URI(const URI &other)
 {
     init();
-    scheme    = other.scheme;
-    schemeStr = other.schemeStr;
-    authority = other.authority;
-    port      = other.port;
-    path      = other.path;
-    absolute  = other.absolute;
-    query     = other.query;
-    fragment  = other.fragment;
+    assign(other);
+}
+
+
+/**
+ *
+ */
+URI &URI::operator=(const URI &other)
+{
+    init();
+    assign(other);
+    return *this;
 }
 
 
@@ -143,11 +147,28 @@ void URI::init()
     authority = "";
     path      = "";
     absolute  = false;
+    opaque    = false;
     query     = "";
     fragment  = "";
 }
 
 
+/**
+ *
+ */
+void URI::assign(const URI &other)
+{
+    scheme    = other.scheme;
+    schemeStr = other.schemeStr;
+    authority = other.authority;
+    port      = other.port;
+    path      = other.path;
+    absolute  = other.absolute;
+    opaque    = other.opaque;
+    query     = other.query;
+    fragment  = other.fragment;
+}
+
 
 //#########################################################################
 //#A T T R I B U T E S
@@ -216,11 +237,16 @@ DOMString URI::getPath() const
 }
 
 
-bool URI::getIsAbsolute() const
+bool URI::isAbsolute() const
 {
     return absolute;
 }
 
+bool URI::isOpaque() const
+{
+    return opaque;
+}
+
 
 DOMString URI::getQuery() const
 {
@@ -231,6 +257,80 @@ DOMString URI::getQuery() const
 DOMString URI::getFragment() const
 {
     return fragment;
+}
+
+
+URI URI::resolve(const URI &other) const
+{
+    //### According to w3c, this is handled in 3 cases
+
+    //## 1
+    if (opaque || other.isAbsolute())
+        return other;
+
+    //## 2
+    if (other.fragment.size()  >  0 &&
+        other.path.size()      == 0 &&
+        other.scheme           == SCHEME_NONE &&
+        other.authority.size() == 0 &&
+        other.query.size()     == 0 )
+        {
+        URI fragUri = *this;
+        fragUri.fragment = other.fragment;
+        return fragUri;
+        }
+
+    //## 3 http://www.ietf.org/rfc/rfc2396.txt, section 5.2
+    URI newUri;
+    //# 3.1
+    newUri.scheme    = scheme;
+    newUri.schemeStr = schemeStr;
+    newUri.query     = other.query;
+    newUri.fragment  = other.fragment;
+    if (other.authority.size() > 0)
+        {
+        //# 3.2
+        if (absolute || other.absolute)
+            newUri.absolute = true;
+        newUri.authority = other.authority;
+        newUri.port      = other.port;//part of authority
+        newUri.path      = other.path;
+        }
+    else
+        {
+        //# 3.3
+        if (other.absolute)
+            {
+            newUri.absolute = true;
+            newUri.path     = other.path;
+            }
+        else
+            {
+            unsigned int pos = path.rfind('/');
+            if (pos != path.npos)
+                {
+                DOMString tpath = path.substr(pos);
+                tpath.append(other.path);
+                newUri.path = tpath;
+                newUri.normalize();
+                }
+            }
+        }
+    return newUri;
+}
+
+
+/**
+ *
+ */
+void URI::normalize() const
+{
+
+
+
+
+
+
 }
 
 
@@ -335,9 +435,9 @@ int URI::parseHierarchicalPart(int p0)
             else if (ch == ':')
                 portSpecified = true;
             else if (portSpecified)
-                portStr.push_back(ch);
+                portStr.push_back((XMLCh)ch);
             else
-                authority.push_back(ch);
+                authority.push_back((XMLCh)ch);
             p++;
             }
         if (portStr.size() > 0)
@@ -355,7 +455,9 @@ int URI::parseHierarchicalPart(int p0)
     if (ch == '/')
         {
         absolute = true;
-        path.push_back(ch);
+        if (p>p0) //in other words, if '/' is not the first char
+            opaque = true;
+        path.push_back((XMLCh)ch);
         p++;
         }
 
@@ -364,7 +466,7 @@ int URI::parseHierarchicalPart(int p0)
         ch = peek(p);
         if (ch == '?' || ch == '#')
             break;
-        path.push_back(ch);
+        path.push_back((XMLCh)ch);
         p++;
         }
 
@@ -384,7 +486,7 @@ int URI::parseQuery(int p0)
         ch = peek(p);
         if (ch == '#')
             break;
-        query.push_back(ch);
+        query.push_back((XMLCh)ch);
         p++;
         }
 
@@ -406,7 +508,7 @@ int URI::parseFragment(int p0)
         ch = peek(p);
         if (ch == '?')
             break;
-        fragment.push_back(ch);
+        fragment.push_back((XMLCh)ch);
         p++;
         }
 
index 722205036f6190d022d289c2c21d599bac092ee3..0de5420edcd1cea7222b8d426d74865593e8ebe0 100644 (file)
@@ -84,6 +84,11 @@ public:
      */
     URI(const URI &other);
 
+    /**
+     *  Assignment
+     */
+    URI &URI::operator=(const URI &other);
+
     /**
      *
      */
@@ -133,7 +138,12 @@ public:
     /**
      *
      */
-    virtual bool getIsAbsolute() const;
+    virtual bool isAbsolute() const;
+
+    /**
+     *
+     */
+    virtual bool isOpaque() const;
 
     /**
      *
@@ -145,10 +155,23 @@ public:
      */
     virtual DOMString getFragment() const;
 
+    /**
+     *
+     */
+    virtual URI resolve(const URI &other) const;
+
+    /**
+     *
+     */
+    virtual void normalize() const;
+
 private:
 
     void init();
 
+    //assign values of other to this. used by copy constructor
+    void assign(const URI &other);
+
     int scheme;
 
     DOMString schemeStr;
@@ -163,6 +186,8 @@ private:
 
     bool absolute;
 
+    bool opaque;
+
     DOMString query;
 
     DOMString fragment;
index b3c5ec9b0f31462190ed882696e595a0a988521f..99df889d9e3c98b1ea86ad045d3b6dfb6fa9107e 100644 (file)
@@ -869,6 +869,8 @@ private:
     void encodeLiteralStatic(unsigned int ch);\r
 \r
     unsigned char windowBuf[32768];\r
+    //assume 32-bit ints\r
+    unsigned int windowHashBuf[32768];\r
 };\r
 \r
 \r
@@ -1268,14 +1270,22 @@ void Deflater::encodeDistStatic(unsigned int len, unsigned int dist)
  */\r
 bool Deflater::compressWindow()\r
 {\r
+    windowPos = 0;\r
     unsigned int windowSize = window.size();\r
     //### Compress as much of the window as possible\r
-    int i=0;\r
-    std::vector<unsigned char>::iterator iter;\r
-    for (iter=window.begin() ; iter!=window.end() ; iter++)\r
-        windowBuf[i++] = *iter;\r
 \r
-    while (windowPos < windowSize)\r
+    unsigned int hash = 0;\r
+    //Have each value be a long with the byte at this position,\r
+    //plus the 3 bytes after it in the window\r
+    for (int i=windowSize-1 ; i>=0 ; i--)\r
+        {\r
+        unsigned char ch = window[i];\r
+        windowBuf[i] = ch;\r
+        hash = ((hash<<8) & 0xffffff00) | ch;\r
+        windowHashBuf[i] = hash;\r
+        }\r
+\r
+    while (windowPos < windowSize - 3)\r
         {\r
         //### Find best match, if any\r
         unsigned int bestMatchLen  = 0;\r
@@ -1284,27 +1294,28 @@ bool Deflater::compressWindow()
             {\r
             for (unsigned int lookBack=0 ; lookBack<windowPos-4 ; lookBack++)\r
                 {\r
-                unsigned int lookAhead=0;\r
-                unsigned char *wp = &(windowBuf[windowPos]);\r
-                unsigned char *lb = &(windowBuf[lookBack]);\r
-                //Check first char, before continuing with string\r
-                if (*lb++ == *wp++)\r
+                //Check 4-char hashes first, before continuing with string\r
+                if (windowHashBuf[lookBack] == windowHashBuf[windowPos])\r
                     {\r
-                    unsigned int lookAheadMax = windowSize - windowPos;\r
-                    if (lookBack + lookAheadMax >= windowPos)\r
-                        lookAheadMax = windowPos - lookBack;\r
+                    unsigned int lookAhead=4;\r
+                    unsigned int lookAheadMax = windowSize - 4 - windowPos;\r
+                    if (lookBack + lookAheadMax >= windowPos -4 )\r
+                        lookAheadMax = windowPos - 4 - lookBack;\r
                     if (lookAheadMax > 258)\r
                         lookAheadMax = 258;\r
-                    for (lookAhead = 1 ; lookAhead<lookAheadMax ; lookAhead++)\r
+                    unsigned char *wp = &(windowBuf[windowPos+4]);\r
+                    unsigned char *lb = &(windowBuf[lookBack+4]);\r
+                    while (lookAhead<lookAheadMax)\r
                         {\r
                         if (*lb++ != *wp++)\r
                             break;\r
+                        lookAhead++;\r
+                        }\r
+                    if (lookAhead > bestMatchLen)\r
+                        {\r
+                        bestMatchLen  = lookAhead;\r
+                        bestMatchDist = windowPos - lookBack;\r
                         }\r
-                    }\r
-                if (lookAhead > bestMatchLen)\r
-                    {\r
-                    bestMatchLen  = lookAhead;\r
-                    bestMatchDist = windowPos - lookBack;\r
                     }\r
                 }\r
             }\r
@@ -1333,6 +1344,9 @@ bool Deflater::compressWindow()
             }\r
         }\r
 \r
+    while (windowPos < windowSize)\r
+        encodeLiteralStatic(windowBuf[windowPos++]);\r
+\r
     encodeLiteralStatic(256);\r
     return true;\r
 }\r
@@ -1350,14 +1364,15 @@ bool Deflater::compress()
     for (iter = uncompressed.begin(); iter != uncompressed.end() ; )\r
         {\r
         total += windowPos;\r
-        //trace("total:%ld", total);\r
+        trace("total:%ld", total);\r
+        if (windowPos > window.size())\r
+            windowPos = window.size();\r
         window.erase(window.begin() , window.begin()+windowPos);\r
         while (window.size() < 32768 && iter != uncompressed.end())\r
             {\r
             window.push_back(*iter);\r
             iter++;\r
             }\r
-        windowPos = 0;\r
         if (window.size() >= 32768)\r
             putBits(0x00, 1); //0  -- more blocks\r
         else\r
@@ -2636,7 +2651,7 @@ bool ZipFile::readFileData()
 \r
         if (uncompressedSize != uncompBuf.size())\r
             {\r
-            error("Size mismatch.  Received %ld, received %ld",\r
+            error("Size mismatch.  Expected %ld, received %ld",\r
                 uncompressedSize, uncompBuf.size());\r
             return false;\r
             }\r
index 218a71b6fe209e0a8d6cb7784fc1a48f172478c9..c36eec961c7dbd05e7a4f9dddc2042cc2d10e796 100644 (file)
@@ -211,7 +211,7 @@ int XmlReader::getWord(int p, DOMString &result)
         int b = get(p);\r
         if (b<=' ' || b=='/' || b=='>' || b=='=')\r
             break;\r
-        result.push_back(b);\r
+        result.push_back((XMLCh)b);\r
         p++;\r
         }\r
     return p;\r
@@ -234,7 +234,7 @@ int XmlReader::getPrefixedWord(int p, DOMString &prefix,
             shortWord = "";\r
             }\r
         else\r
-            shortWord.push_back(b);\r
+            shortWord.push_back((XMLCh)b);\r
         p++;\r
         }\r
     if (prefix.size() > 0)\r
@@ -274,7 +274,7 @@ int XmlReader::getQuoted(int p0, DOMString &result)
             }\r
         else\r
             {\r
-            buf.push_back(b);\r
+            buf.push_back((XMLCh)b);\r
             }\r
         }\r
 \r
@@ -448,7 +448,7 @@ int XmlReader::parseComment(int p0, Comment *comment)
             break;\r
             }\r
         int ch = get(p++);\r
-        buf.push_back(ch);\r
+        buf.push_back((XMLCh)ch);\r
         }\r
 \r
     comment->setNodeValue(buf);\r
@@ -483,7 +483,7 @@ int XmlReader::parseCDATA(int p0, CDATASection *cdata)
             break;\r
             }\r
         int ch = get(p++);\r
-        buf.push_back(ch);\r
+        buf.push_back((XMLCh)ch);\r
         }\r
 \r
     /*printf("Got CDATA:%s\n",buf.c_str());*/\r
@@ -519,7 +519,7 @@ int XmlReader::parseText(int p0, Text *text)
         else\r
             {\r
             int ch = get(p++);\r
-            buf.push_back(ch);\r
+            buf.push_back((XMLCh)ch);\r
             }\r
         }\r
 \r
@@ -929,7 +929,7 @@ XmlReader::loadFile(char *fileName)
         int ch = fgetc(f);\r
         if (ch<0)\r
             break;\r
-        buf.push_back(ch);\r
+        buf.push_back((XMLCh)ch);\r
         }\r
     fclose(f);\r
 \r
index b7d118d455c738c4adbabe84f0f9c0b8893f2562..6baaea9c5946eb3386be9f380f9c8b812fc8c1b6 100644 (file)
@@ -195,7 +195,7 @@ int XPathParser::getword(int p0, DOMString &str)
         if (!isLetterOrDigit(ch))\r
             break;\r
         ch = get(p++);\r
-        str.push_back(ch);\r
+        str.push_back((XMLCh)ch);\r
         }\r
     return p;\r
 }\r
@@ -264,7 +264,7 @@ int XPathParser::getNumber(int p0, double &dresult)
             }\r
         else if (!isDigit(ch))\r
             break;\r
-        num.push_back(ch);\r
+        num.push_back((XMLCh)ch);\r
         i++;\r
         }\r
 \r
@@ -318,7 +318,7 @@ int XPathParser::getLiteral(int p0, DOMString &result)
         ch = peek(p);\r
         if (ch == quotechar)\r
             break;\r
-        result.push_back(ch);\r
+        result.push_back((XMLCh)ch);\r
         p++;\r
         }\r
     p++; //skip over closing "\r
@@ -333,7 +333,7 @@ int XPathParser::getNCName(int p0, DOMString &result)
     if (ch != '_' && !isLetter(ch))\r
         return p0;\r
 \r
-    result.push_back(ch);\r
+    result.push_back((XMLCh)ch);\r
     p++;\r
     while (p < parselen)\r
         {\r
@@ -343,7 +343,7 @@ int XPathParser::getNCName(int p0, DOMString &result)
                isExtender(ch)      ||\r
                ch == '.' || ch == '-' || ch == '_' )\r
            {\r
-           result.push_back(ch);\r
+           result.push_back((XMLCh)ch);\r
            p++;\r
            }\r
        else\r
@@ -358,7 +358,7 @@ int XPathParser::getNameTest(int p0, DOMString &result)
     int ch = peek(p);\r
     if (ch == '*')\r
         {\r
-        result.push_back(ch);\r
+        result.push_back((XMLCh)ch);\r
         p++;\r
         return p;\r
         }\r
@@ -386,7 +386,7 @@ int XPathParser::getNameTest(int p0, DOMString &result)
     ch = peek(p);\r
     if (ch == '*')\r
         {\r
-        result.push_back(ch);\r
+        result.push_back((XMLCh)ch);\r
         p++;\r
         return p;\r
         }\r