gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog libbase/URL.cpp libbase/URL.h t...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog libbase/URL.cpp libbase/URL.h t...
Date: Fri, 01 Sep 2006 10:24:58 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  06/09/01 10:24:58

Modified files:
        .              : ChangeLog 
        libbase        : URL.cpp URL.h 
        testsuite/libbase: URLTest.cpp 

Log message:
                * libbase/URL.{cpp,h}, testsuite/libbase/URLTest.cpp:
                          Added anchor support in URL class (+tests).

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.797&r2=1.798
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/URL.cpp?cvsroot=gnash&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/URL.h?cvsroot=gnash&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/libbase/URLTest.cpp?cvsroot=gnash&r1=1.5&r2=1.6

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.797
retrieving revision 1.798
diff -u -b -r1.797 -r1.798
--- ChangeLog   31 Aug 2006 18:58:44 -0000      1.797
+++ ChangeLog   1 Sep 2006 10:24:58 -0000       1.798
@@ -1,3 +1,8 @@
+2006-09-01 Sandro Santilli  <address@hidden>
+
+       * libbase/URL.{cpp,h}, testsuite/libbase/URLTest.cpp:
+         Added anchor support in URL class (+tests).
+
 2006-08-31  Rob Savoye  <address@hidden>
 
        * gui/images: New directory for images. Patch #5346.

Index: libbase/URL.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/URL.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- libbase/URL.cpp     26 Aug 2006 18:32:57 -0000      1.19
+++ libbase/URL.cpp     1 Sep 2006 10:24:58 -0000       1.20
@@ -103,11 +103,6 @@
 
                // copy hostname
                _host = in.substr(pos, pos1-pos);
-#if 0 // check moved to StreamProvider
-                 if (!host_check(_host)) {
-                     return;
-                 }
-#endif
                 
                // next come path
                _path = in.substr(pos1);
@@ -118,6 +113,9 @@
                _path = in;
        }
 
+       // Extract anchor from path, if any
+       split_anchor_from_path();
+
 #if ! (defined(_WIN32) || defined(WIN32))
        assert ( _path[0] == '/');
        normalize_path(_path);
@@ -218,6 +216,17 @@
 void
 URL::init_relative(const string& relative_url, const URL& baseurl)
 {
+       // If relative url starts with an hash, it's just
+       // an anchor change
+       if ( relative_url[0] == '#' )
+       {
+               _proto = baseurl._proto;
+               _host = baseurl._host;
+               _path = baseurl._path;
+               _anchor = relative_url.substr(1);
+               return;
+       }
+
        // If has a protocol, call absolute_url ctor
        if ( relative_url.find("://") != string::npos )
        {
@@ -289,9 +298,10 @@
                basedir.resize(lpos+1);
 
                // get dirname from basurl path
-               //_path = basedir + relative_url;
                _path = basedir + in;
 
+               split_anchor_from_path();
+
                normalize_path(_path);
 
        }
@@ -306,6 +316,21 @@
        return ret;
 }
 
+/*private*/
+void
+URL::split_anchor_from_path()
+{
+       assert(_anchor == "");
+
+       // Extract anchor from path, if any
+       string::size_type hashpos = _path.find('#');
+       if ( hashpos != string::npos )
+       {
+               _anchor = _path.substr(hashpos+1);
+               _path.erase(hashpos);
+       }
+}
+
 ostream& operator<< (ostream& o, const URL& u)
 {
        return o << u.str();

Index: libbase/URL.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/URL.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- libbase/URL.h       29 Aug 2006 22:12:26 -0000      1.8
+++ libbase/URL.h       1 Sep 2006 10:24:58 -0000       1.9
@@ -88,6 +88,12 @@
        /// Return the 'path' member of this URL, as a string
        std::string path() const { return _path; }
 
+       /// Return the 'anchor' member of this URL, as a string
+       //
+       /// The anchor is the string after the '#' character
+       ///
+       std::string anchor() const { return _anchor; }
+
        /// Return the full absolute URL as a string.
        //
        /// TODO: make output operator and operator+ for strings
@@ -100,6 +106,9 @@
 
        void init_relative(const std::string& relurl, const URL& baseurl);
 
+       /// Extract anchor from path
+       void split_anchor_from_path();
+
        /// Normalize a 'path' component of an url
        //
        /// Normalization currently include removal
@@ -114,6 +123,8 @@
 
        std::string _path;
 
+       std::string _anchor;
+
 };
 
 std::ostream& operator<< (std::ostream&o, const URL& u);

Index: testsuite/libbase/URLTest.cpp
===================================================================
RCS file: /sources/gnash/gnash/testsuite/libbase/URLTest.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- testsuite/libbase/URLTest.cpp       15 May 2006 12:09:53 -0000      1.5
+++ testsuite/libbase/URLTest.cpp       1 Sep 2006 10:24:58 -0000       1.6
@@ -101,6 +101,7 @@
 
        /// Test https url 
        URL u3("https://www.fake.it/path.swf";);
+
        label = "https url";
        check_equals_label(label, u3.protocol(), "https");
        check_equals_label(label, u3.hostname(), "www.fake.it");
@@ -142,6 +143,23 @@
        check_equals (URL("/dir/./file").path(), "/dir/file");
        check_equals (URL("/dir/./1/2/3/../../../...file").path(), 
"/dir/...file");
 
+       /// Test url with anchors
+       URL u9("/the/path#the_anchor");
+       check_equals (u9.path(), "/the/path");
+       check_equals (u9.anchor(), "the_anchor");
+       URL u10("http://host/the/path#the_anchor";);
+       check_equals (u10.hostname(), "host");
+       check_equals (u10.path(), "/the/path");
+       check_equals (u10.anchor(), "the_anchor");
+       URL u11("#another_anchor", u10);
+       check_equals (u11.hostname(), "host");
+       check_equals (u11.path(), "/the/path");
+       check_equals (u11.anchor(), "another_anchor");
+       URL u12("#", u10);
+       check_equals (u12.hostname(), "host");
+       check_equals (u12.path(), "/the/path");
+       check_equals (u12.anchor(), "");
+
        // TODO: Samba paths
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]