1 #include <tqstringlist.h> 11 :m_rurl(rurl), m_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;
148 bool Name::operator ==(
const Name & rname )
150 return rname.
rurl() == m_rurl;
153 bool 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;
264 return m_base.path(1);
285 return url.path(mod);
293 return url.directory(
false,
false);
303 return URL(base, url);
308 return URL(base, url, isUrlRelative);
311 bool Relative::URL::operator ==(
const URL &
url )
313 return (m_base == url.
base()) && (
rurl() == url.
rurl());
316 bool Relative::URL::operator !=(
const URL & url )
318 return (m_base != url.
base()) || (
rurl() != url.
rurl());
void setRURL(TQString rurl)
Works as URL::setRURL(TQString), only implies Name::File mode.
void addPath(const TQString &addendum)
Adds addendum to the directory path.
KURL url() const
Returns a complete url to the RURL location.
Type type() const
Returns a type of the relative name - file or directory.
void setRURL(const TQString &rurl, const Type type)
Sets the relative name.
TQString extension(bool complete=true) const
Returns the extension of a file or TQString() for directories.
Name(const TQString &rurl, const Type type=Auto)
Constructor takes the relative name of a directory or file.
void setRURL(TQString rurl)
Works as URL::setRURL(TQString), only implies Name::Directory mode.
Relative name of file or directory to some base location.
bool isFile() const
Returns true if the type of RName is file.
TQString urlDirectory() const
Returns a directory of a complete url to the location.
Classes and functions to work with relative URLs.
static TQString correctName(const TQString &rurl, const Type type=Auto)
Corrects rurl according to the given type and returns corrected url.
Classes and functions to work with relative URLs.
static Name relativeName(const TQString &base, const TQString &url)
Creates and returns relative name between base and url.
Relative name of a file or directory.
void correct()
Corrects m_rurl and m_type according to the relative name storing policy, i.e.
TQString basePath() const
Returns a path of a base KURL (using KURL::path()).
void setType(const Type type)
Sets a type of the relative name - file or directory.
TQString rurl() const
Gets the relative name in form dir/dir/ -> directory or dir/dir/file -> file.
TQString directory() const
Returns the name of the directory or TQString() if there are no dirs in path.
void cleanRURL()
Removes "//" from the name.
static TQString cleanName(const TQString &rurl)
Cleans rurl by removing extra slashes.
bool isDirectory() const
Returns true if the type of RName is directory.
URL relativeTo(KURL base)
Returns a new URL that is relative to given base.
TQString fileName() const
Returns the name of the file without the path or TQString() for directories.
KURL base() const
Returns RURL base.
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.
URL(KURL base, KURL url, Type type=Auto)
Evaluates the relative path between url and base and creates RURL object.
bool isValid() const
Checks if RName is valid.
File(KURL base, KURL url)
Works as URL::URL(KURL, KURL), only implies Name::File mode.
Directory(KURL base, KURL url)
Works as URL::URL(KURL, KURL), only implies Name::Directory mode.
TQString urlPath() const
Returns a path of a complete url to the location.