diff options
| author | Bob Jamison <ishmalius@gmail.com> | 2006-04-22 10:48:46 +0000 |
|---|---|---|
| committer | ishmal <ishmal@users.sourceforge.net> | 2006-04-22 10:48:46 +0000 |
| commit | 3c678ae341f853e426a9716f6999dcf2bf1a7c99 (patch) | |
| tree | 3dfa0291a5df614d7271331e8cbed248709ede30 /src | |
| parent | minor speedup (diff) | |
| download | inkscape-3c678ae341f853e426a9716f6999dcf2bf1a7c99.tar.gz inkscape-3c678ae341f853e426a9716f6999dcf2bf1a7c99.zip | |
Tweak to use Glib::ustring. Remove warnings.
(bzr r565)
Diffstat (limited to 'src')
| -rw-r--r-- | src/dom/cssparser.cpp | 4 | ||||
| -rw-r--r-- | src/dom/dom.h | 21 | ||||
| -rw-r--r-- | src/dom/domimpl.cpp | 2 | ||||
| -rw-r--r-- | src/dom/lsimpl.cpp | 6 | ||||
| -rw-r--r-- | src/dom/svg/svgparser.cpp | 2 | ||||
| -rw-r--r-- | src/dom/uri.cpp | 132 | ||||
| -rw-r--r-- | src/dom/uri.h | 27 | ||||
| -rw-r--r-- | src/dom/util/ziptool.cpp | 59 | ||||
| -rw-r--r-- | src/dom/xmlreader.cpp | 14 | ||||
| -rw-r--r-- | src/dom/xpathparser.cpp | 14 |
10 files changed, 216 insertions, 65 deletions
diff --git a/src/dom/cssparser.cpp b/src/dom/cssparser.cpp index 2dc342704..8f245c06d 100644 --- a/src/dom/cssparser.cpp +++ b/src/dom/cssparser.cpp @@ -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); diff --git a/src/dom/dom.h b/src/dom/dom.h index d533a7dca..2248ad61f 100644 --- a/src/dom/dom.h +++ b/src/dom/dom.h @@ -29,16 +29,18 @@ * 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 + /** * diff --git a/src/dom/domimpl.cpp b/src/dom/domimpl.cpp index b3197c948..e9da6291f 100644 --- a/src/dom/domimpl.cpp +++ b/src/dom/domimpl.cpp @@ -862,7 +862,7 @@ void NodeImpl::setNodeName(const DOMString &qualifiedName) } else { - localName.push_back(ch); + localName.push_back((XMLCh)ch); } } } diff --git a/src/dom/lsimpl.cpp b/src/dom/lsimpl.cpp index 636dc6750..65807cc45 100644 --- a/src/dom/lsimpl.cpp +++ b/src/dom/lsimpl.cpp @@ -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 diff --git a/src/dom/svg/svgparser.cpp b/src/dom/svg/svgparser.cpp index df0470045..d2da3150c 100644 --- a/src/dom/svg/svgparser.cpp +++ b/src/dom/svg/svgparser.cpp @@ -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; diff --git a/src/dom/uri.cpp b/src/dom/uri.cpp index 8f5cf976d..286857e41 100644 --- a/src/dom/uri.cpp +++ b/src/dom/uri.cpp @@ -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 { @@ -234,6 +260,80 @@ DOMString URI::getFragment() const } +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 +{ + + + + + + +} + + //######################################################################### //# M E S S A G E S @@ -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++; } diff --git a/src/dom/uri.h b/src/dom/uri.h index 722205036..0de5420ed 100644 --- a/src/dom/uri.h +++ b/src/dom/uri.h @@ -85,6 +85,11 @@ public: URI(const URI &other); /** + * Assignment + */ + URI &URI::operator=(const URI &other); + + /** * */ virtual ~URI(); @@ -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; diff --git a/src/dom/util/ziptool.cpp b/src/dom/util/ziptool.cpp index b3c5ec9b0..99df889d9 100644 --- a/src/dom/util/ziptool.cpp +++ b/src/dom/util/ziptool.cpp @@ -869,6 +869,8 @@ private: void encodeLiteralStatic(unsigned int ch);
unsigned char windowBuf[32768];
+ //assume 32-bit ints
+ unsigned int windowHashBuf[32768];
};
@@ -1268,14 +1270,22 @@ void Deflater::encodeDistStatic(unsigned int len, unsigned int dist) */
bool Deflater::compressWindow()
{
+ windowPos = 0;
unsigned int windowSize = window.size();
//### Compress as much of the window as possible
- int i=0;
- std::vector<unsigned char>::iterator iter;
- for (iter=window.begin() ; iter!=window.end() ; iter++)
- windowBuf[i++] = *iter;
- while (windowPos < windowSize)
+ unsigned int hash = 0;
+ //Have each value be a long with the byte at this position,
+ //plus the 3 bytes after it in the window
+ for (int i=windowSize-1 ; i>=0 ; i--)
+ {
+ unsigned char ch = window[i];
+ windowBuf[i] = ch;
+ hash = ((hash<<8) & 0xffffff00) | ch;
+ windowHashBuf[i] = hash;
+ }
+
+ while (windowPos < windowSize - 3)
{
//### Find best match, if any
unsigned int bestMatchLen = 0;
@@ -1284,27 +1294,28 @@ bool Deflater::compressWindow() {
for (unsigned int lookBack=0 ; lookBack<windowPos-4 ; lookBack++)
{
- unsigned int lookAhead=0;
- unsigned char *wp = &(windowBuf[windowPos]);
- unsigned char *lb = &(windowBuf[lookBack]);
- //Check first char, before continuing with string
- if (*lb++ == *wp++)
+ //Check 4-char hashes first, before continuing with string
+ if (windowHashBuf[lookBack] == windowHashBuf[windowPos])
{
- unsigned int lookAheadMax = windowSize - windowPos;
- if (lookBack + lookAheadMax >= windowPos)
- lookAheadMax = windowPos - lookBack;
+ unsigned int lookAhead=4;
+ unsigned int lookAheadMax = windowSize - 4 - windowPos;
+ if (lookBack + lookAheadMax >= windowPos -4 )
+ lookAheadMax = windowPos - 4 - lookBack;
if (lookAheadMax > 258)
lookAheadMax = 258;
- for (lookAhead = 1 ; lookAhead<lookAheadMax ; lookAhead++)
+ unsigned char *wp = &(windowBuf[windowPos+4]);
+ unsigned char *lb = &(windowBuf[lookBack+4]);
+ while (lookAhead<lookAheadMax)
{
if (*lb++ != *wp++)
break;
+ lookAhead++;
+ }
+ if (lookAhead > bestMatchLen)
+ {
+ bestMatchLen = lookAhead;
+ bestMatchDist = windowPos - lookBack;
}
- }
- if (lookAhead > bestMatchLen)
- {
- bestMatchLen = lookAhead;
- bestMatchDist = windowPos - lookBack;
}
}
}
@@ -1333,6 +1344,9 @@ bool Deflater::compressWindow() }
}
+ while (windowPos < windowSize)
+ encodeLiteralStatic(windowBuf[windowPos++]);
+
encodeLiteralStatic(256);
return true;
}
@@ -1350,14 +1364,15 @@ bool Deflater::compress() for (iter = uncompressed.begin(); iter != uncompressed.end() ; )
{
total += windowPos;
- //trace("total:%ld", total);
+ trace("total:%ld", total);
+ if (windowPos > window.size())
+ windowPos = window.size();
window.erase(window.begin() , window.begin()+windowPos);
while (window.size() < 32768 && iter != uncompressed.end())
{
window.push_back(*iter);
iter++;
}
- windowPos = 0;
if (window.size() >= 32768)
putBits(0x00, 1); //0 -- more blocks
else
@@ -2636,7 +2651,7 @@ bool ZipFile::readFileData() if (uncompressedSize != uncompBuf.size())
{
- error("Size mismatch. Received %ld, received %ld",
+ error("Size mismatch. Expected %ld, received %ld",
uncompressedSize, uncompBuf.size());
return false;
}
diff --git a/src/dom/xmlreader.cpp b/src/dom/xmlreader.cpp index 218a71b6f..c36eec961 100644 --- a/src/dom/xmlreader.cpp +++ b/src/dom/xmlreader.cpp @@ -211,7 +211,7 @@ int XmlReader::getWord(int p, DOMString &result) int b = get(p);
if (b<=' ' || b=='/' || b=='>' || b=='=')
break;
- result.push_back(b);
+ result.push_back((XMLCh)b);
p++;
}
return p;
@@ -234,7 +234,7 @@ int XmlReader::getPrefixedWord(int p, DOMString &prefix, shortWord = "";
}
else
- shortWord.push_back(b);
+ shortWord.push_back((XMLCh)b);
p++;
}
if (prefix.size() > 0)
@@ -274,7 +274,7 @@ int XmlReader::getQuoted(int p0, DOMString &result) }
else
{
- buf.push_back(b);
+ buf.push_back((XMLCh)b);
}
}
@@ -448,7 +448,7 @@ int XmlReader::parseComment(int p0, Comment *comment) break;
}
int ch = get(p++);
- buf.push_back(ch);
+ buf.push_back((XMLCh)ch);
}
comment->setNodeValue(buf);
@@ -483,7 +483,7 @@ int XmlReader::parseCDATA(int p0, CDATASection *cdata) break;
}
int ch = get(p++);
- buf.push_back(ch);
+ buf.push_back((XMLCh)ch);
}
/*printf("Got CDATA:%s\n",buf.c_str());*/
@@ -519,7 +519,7 @@ int XmlReader::parseText(int p0, Text *text) else
{
int ch = get(p++);
- buf.push_back(ch);
+ buf.push_back((XMLCh)ch);
}
}
@@ -929,7 +929,7 @@ XmlReader::loadFile(char *fileName) int ch = fgetc(f);
if (ch<0)
break;
- buf.push_back(ch);
+ buf.push_back((XMLCh)ch);
}
fclose(f);
diff --git a/src/dom/xpathparser.cpp b/src/dom/xpathparser.cpp index b7d118d45..6baaea9c5 100644 --- a/src/dom/xpathparser.cpp +++ b/src/dom/xpathparser.cpp @@ -195,7 +195,7 @@ int XPathParser::getword(int p0, DOMString &str) if (!isLetterOrDigit(ch))
break;
ch = get(p++);
- str.push_back(ch);
+ str.push_back((XMLCh)ch);
}
return p;
}
@@ -264,7 +264,7 @@ int XPathParser::getNumber(int p0, double &dresult) }
else if (!isDigit(ch))
break;
- num.push_back(ch);
+ num.push_back((XMLCh)ch);
i++;
}
@@ -318,7 +318,7 @@ int XPathParser::getLiteral(int p0, DOMString &result) ch = peek(p);
if (ch == quotechar)
break;
- result.push_back(ch);
+ result.push_back((XMLCh)ch);
p++;
}
p++; //skip over closing "
@@ -333,7 +333,7 @@ int XPathParser::getNCName(int p0, DOMString &result) if (ch != '_' && !isLetter(ch))
return p0;
- result.push_back(ch);
+ result.push_back((XMLCh)ch);
p++;
while (p < parselen)
{
@@ -343,7 +343,7 @@ int XPathParser::getNCName(int p0, DOMString &result) isExtender(ch) ||
ch == '.' || ch == '-' || ch == '_' )
{
- result.push_back(ch);
+ result.push_back((XMLCh)ch);
p++;
}
else
@@ -358,7 +358,7 @@ int XPathParser::getNameTest(int p0, DOMString &result) int ch = peek(p);
if (ch == '*')
{
- result.push_back(ch);
+ result.push_back((XMLCh)ch);
p++;
return p;
}
@@ -386,7 +386,7 @@ int XPathParser::getNameTest(int p0, DOMString &result) ch = peek(p);
if (ch == '*')
{
- result.push_back(ch);
+ result.push_back((XMLCh)ch);
p++;
return p;
}
|
