1#include <tqstringlist.h>
11 :m_rurl(rurl), m_type(type)
16Name::Name(
const char * rurl,
const Type type )
17 :m_rurl(rurl), m_type(type)
26 m_rurl = m_rurl.mid(1);
30 if (m_rurl.endsWith(
"/"))
31 m_rurl = m_rurl.mid(0, m_rurl.length()-1);
34 if (!m_rurl.endsWith(
"/"))
38 if (m_rurl.endsWith(
"/"))
56 if (temp.endsWith(
"/"))
57 temp = temp.mid(0, temp.length()-1);
60 if (!temp.endsWith(
"/"))
94 bool wasSlash =
false;
95 for (
unsigned int i = 0; i <
rurl.length(); ++i)
97 if (wasSlash && (
rurl[i] ==
'/'))
116 return temp.mid(temp.find(
'.')+1);
118 return temp.mid(temp.findRev(
'.')+1);
126 return m_rurl.section(
'/', -1);
132 if ( (m_type ==
File) && (m_rurl.findRev(
'/') == -1) )
135 return m_rurl.mid(0, m_rurl.findRev(
'/')+1);
140 return m_type ==
File;
148bool Name::operator ==(
const Name & rname )
150 return rname.
rurl() == m_rurl;
153bool Name::operator !=(
const Name & rname )
155 return rname.rurl() != m_rurl;
160 if (m_rurl.startsWith(
"/"))
162 if (m_rurl.contains(
"//"))
164 if ( (m_rurl.endsWith(
"/")) && (m_type ==
File) )
166 if ( (!m_rurl.endsWith(
"/")) && (m_type ==
Directory) )
186 TQString dirUrl = base;
187 TQString fileUrl = url;
189 if (dirUrl.isEmpty() || (dirUrl ==
"/"))
190 return Name(fileUrl);
192 TQStringList dir = TQStringList::split(
"/", dirUrl,
false);
193 TQStringList file = TQStringList::split(
"/", fileUrl,
false);
195 TQString resFileName = file.last();
196 if (url.endsWith(
"/"))
198 file.remove(file.last());
201 while ( (i < dir.count()) && (i < (file.count())) && (dir[i] == file[i]) )
205 TQString result_down;
210 i >= dir.count() ? currDir =
"" : currDir = dir[i];
211 i >= file.count() ? currFile =
"" : currFile = file[i];
213 if (currDir.isEmpty() && currFile.isEmpty())
215 else if (currDir.isEmpty())
216 result_down += file[i] +
"/";
217 else if (currFile.isEmpty())
221 result_down += file[i] +
"/";
226 while ( (!currDir.isEmpty()) || (!currFile.isEmpty()) );
228 return result_up + result_down + resFileName;
236 :
Name(
Name::relativeName(base.path(), url.path()).rurl(), type), m_base(base)
240URL::URL( KURL base, TQString url,
bool isUrlRelative, Type type )
241 :
Name(isUrlRelative ? url :
Name::relativeName(base.path(), url).rurl(), type), m_base(base)
264 return m_base.path(1);
285 return url.path(mod);
293 return url.directory(
false,
false);
311bool Relative::URL::operator ==(
const URL & url )
313 return (m_base == url.
base()) && (rurl() == url.
rurl());
316bool Relative::URL::operator !=(
const URL & url )
318 return (m_base != url.base()) || (rurl() != url.rurl());
325Directory::Directory( KURL base, KURL url )
330Directory::Directory( KURL base, TQString url,
bool isRelativeUrl )
349File::File( KURL base, KURL url )
354File::File( KURL base, TQString url,
bool isRelativeUrl )
void setRURL(TQString rurl)
Works as URL::setRURL(TQString), only implies Name::Directory mode.
void setRURL(TQString rurl)
Works as URL::setRURL(TQString), only implies Name::File mode.
Relative name of a file or directory.
void addPath(const TQString &addendum)
Adds addendum to the directory path.
static TQString correctName(const TQString &rurl, const Type type=Auto)
Corrects rurl according to the given type and returns corrected url.
static Name relativeName(const TQString &base, const TQString &url)
Creates and returns relative name between base and url.
TQString fileName() const
Returns the name of the file without the path or TQString() for directories.
static TQString cleanName(const TQString &rurl)
Cleans rurl by removing extra slashes.
Name(const TQString &rurl, const Type type=Auto)
Constructor takes the relative name of a directory or file.
TQString extension(bool complete=true) const
Returns the extension of a file or TQString() for directories.
bool isDirectory() const
Returns true if the type of RName is directory.
bool isValid() const
Checks if RName is valid.
void setRURL(const TQString &rurl, const Type type)
Sets the relative name.
TQString rurl() const
Gets the relative name in form dir/dir/ -> directory or dir/dir/file -> file.
void setType(const Type type)
Sets a type of the relative name - file or directory.
void correct()
Corrects m_rurl and m_type according to the relative name storing policy, i.e.
Type type() const
Returns a type of the relative name - file or directory.
TQString directory() const
Returns the name of the directory or TQString() if there are no dirs in path.
bool isFile() const
Returns true if the type of RName is file.
void cleanRURL()
Removes "//" from the name.
Relative name of file or directory to some base location.
TQString urlPath() const
Returns a path of a complete url to the location.
URL relativeTo(KURL base)
Returns a new URL that is relative to given base.
TQString basePath() const
Returns a path of a base KURL (using KURL::path()).
static URL relativeURL(KURL base, KURL url)
Returns a new relative URL constructed from base and given url.
void setBase(const KURL &base)
Sets a new base for a RURL.
TQString urlDirectory() const
Returns a directory of a complete url to the location.
KURL base() const
Returns RURL base.
URL(KURL base, KURL url, Type type=Auto)
Evaluates the relative path between url and base and creates RURL object.
KURL url() const
Returns a complete url to the RURL location.
Classes and functions to work with relative URLs.
Classes and functions to work with relative URLs.