Logo Search packages:      
Sourcecode: inkscape version File versions  Download package

char const* sp_relative_path_from_path ( char const *const   path,
char const *const   base 
)

Returns a form of path relative to base if that is easy to construct (e.g. if path appears to be in the directory specified by base), otherwise returns path.

N.B. The return value is a pointer into the path string.

base is expected to be either NULL or the absolute path of a directory.

path is expected to be an absolute path.

See also:
inkscape_abs2rel for a more sophisticated version.

prepend_current_dir_if_relative.

Definition at line 29 of file dir-util.cpp.

Referenced by Inkscape::XML::rebase_href_attrs(), and Inkscape::XML::rebase_hrefs().

{
      if (base == NULL || path == NULL) {
            return path;
      }

      size_t base_len = strlen(base);
      while (base_len != 0
             && (base[base_len - 1] == G_DIR_SEPARATOR))
      {
            --base_len;
      }

      if ((memcmp(path, base, base_len) == 0)
          && (path[base_len] == G_DIR_SEPARATOR))
      {
            char const *ret = path + base_len + 1;
            while (*ret == G_DIR_SEPARATOR) {
                  ++ret;
            }
            if (*ret != '\0') {
                  return ret;
            }
      }

      return path;
}


Generated by  Doxygen 1.6.0   Back to index