W3C home > Mailing lists > Public > uri@w3.org > September 2007

Re: URI Reference creation

From: Sebastian Pipping <webmaster@hartwork.org>
Date: Sat, 08 Sep 2007 21:31:14 +0200
Message-ID: <46E2F882.2020000@hartwork.org>
To: uri@w3.org

Updated version with domainRootMode (see example below)
and empty path segment (e.g. abc//def) fix.


== Variables ==
Base - [IN] Base to cut off if possible
A    - [IN] Absolute URI that we would like relative instead
T    - [OUT] Transformation result (relative if possible, absolute if necessary)


== Example ==
BASE = http://ex/x/y/z?one
A    = http://ex/x/r?two

=== domainRootMode ===
T    = /x/r?two

=== not domainRootMode ===
T    = ../r?two


== Algorithm v0.2 ==
if (A.scheme != Base.scheme) then
   T.scheme    = A.scheme;
   T.authority = A.authority;
   T.path      = A.path;
   T.query     = A.query;
   T.fragment  = A.fragment;
else
   undef(T.scheme);
   if (A.authority != Base.authority) then
      T.authority = A.authority;
      T.path      = A.path;
      T.query     = A.query;
      T.fragment  = A.fragment;
   else
      if domainRootMode then
         undef(T.authority);
         T.path      = "/" + A.path;
         T.query     = A.query;
         T.fragment  = A.fragment;
      else
         undef(last(Base.path));
         T.path = "";
         while (first(A.path) == first(Base.path)) do
            A.path++;
            Base.path++;
         endwhile;
         bool pathNaked = true;
         while defined(first(Base.path)) do
            Base.path++;
            T.path += "../";
            pathNaked = false;
         endwhile;
         while defined(first(A.path)) do
            if pathNaked then
               if (first(A.path) contains ":")
                     or (first(A.path) == "") then
                  T.path += "./";
               endif;
            endif;
            T.path += first(A.path);
            pathNaked = false;
            A.path++;
            if defined(first(A.path)) then
               T.path += + "/";
            endif;
         endwhile;
         T.query    = A.query;
         T.fragment = A.fragment;
      endif;
   endif;
endif;


Feedback is highly appreciated.



Sebastian
Received on Saturday, 8 September 2007 19:31:21 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:25:11 UTC