SNAP Library 3.0, User Reference  2016-07-20 17:56:49
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TUrl Class Reference

#include <url.h>

Public Member Functions

 TUrl (const TStr &_RelUrlStr, const TStr &_BaseUrlStr=TStr())
 
 ~TUrl ()
 
 TUrl (TSIn &)
 
void Save (TSOut &)
 
bool IsOk (const TUrlScheme _Scheme=usUndef) const
 
TUrlScheme GetScheme ()
 
TStr GetUrlStr () const
 
TStr GetRelUrlStr () const
 
bool IsBaseUrl ()
 
TStr GetBaseUrlStr () const
 
TStr GetSchemeNm () const
 
TStr GetHostNm () const
 
TStr GetDmNm (const int &MxDmSegs=-1) const
 
bool IsPortOk () const
 
TStr GetPortStr () const
 
int GetPortN () const
 
TStr GetPathStr () const
 
int GetPathSegs () const
 
TStr GetPathSeg (const int &PathSegN) const
 
TStr GetSearchStr () const
 
TStr GetFragIdStr () const
 
bool IsIpNum () const
 
void PutIpNum (const TStr &_IpNum)
 
TStr GetIpNum () const
 
TStr GetIpNumOrHostNm () const
 
bool IsDefFinalUrl () const
 
TStr GetFinalUrlStr () const
 
TStr GetAsFinalUrlStr () const
 
TStr GetFinalHostNm () const
 
TStr GetAsFinalHostNm () const
 
void DefUrlAsFinal ()
 
void DefFinalUrl (const TStr &_FinalHostNm)
 
void PutHttpRqStr (const TStr &_HttpRqStr)
 
TStr GetHttpRqStr () const
 
bool IsHttpRqStr () const
 
void ChangeHttpRqStr (const TStr &SrcStr, const TStr &DstStr)
 
bool IsInHost (const TStr &_HostNm) const
 
bool IsInPath (const TStr &_PathStr) const
 
void ToLcPath ()
 

Static Public Member Functions

static PUrl New (const TStr &RelUrlStr, const TStr &BaseUrlStr=TStr())
 
static PUrl Load (TSIn &)
 
static bool IsAbs (const TStr &UrlStr)
 
static bool IsScript (const TStr &UrlStr)
 
static bool IsSite (const TStr &UrlStr)
 
static PUrl GetUrlFromShortcut (const TStr &ShortcutUrlStr, const TStr &DfHostNmPrefix, const TStr &DfHostNmSufix)
 
static TStr GetUrlSearchStr (const TStr &Str)
 
static TStr EncodeUrlStr (const TStr &Str)
 
static TStr DecodeUrlStr (const TStr &UrlStr)
 
static TStr GetDocStrFromUrlStr (const TStr &UrlStr, const int &Copies=1)
 
static TStr GetTopDownDocNm (const TStr &UrlStr, const int &MxLen=-1, const bool &HostOnlyP=false)
 

Private Member Functions

void GetAbs (const TStr &AbsUrlStr)
 
void GetAbsFromBase (const TStr &RelUrlStr, const TStr &BaseUrlStr)
 
 UndefDefaultCopyAssign (TUrl)
 

Private Attributes

TCRef CRef
 
TUrlScheme Scheme
 
TStr UrlStr
 
TStr RelUrlStr
 
TStr BaseUrlStr
 
TStr SchemeNm
 
TStr HostNm
 
TStr PortStr
 
TStr PathStr
 
TStr SearchStr
 
TStr FragIdStr
 
int PortN
 
TStrV PathSegV
 
TStr IpNum
 
TStr FinalUrlStr
 
TStr FinalHostNm
 
TStr HttpRqStr
 

Static Private Attributes

static const TStr UrlHttpPrefixStr ="http:"
 
static const TStr UrlHttpAbsPrefixStr ="http://"
 

Friends

class TPt< TUrl >
 

Detailed Description

Definition at line 7 of file url.h.

Constructor & Destructor Documentation

TUrl::TUrl ( const TStr _RelUrlStr,
const TStr _BaseUrlStr = TStr() 
)

Definition at line 228 of file url.cpp.

228  :
229  Scheme(usUndef),
230  UrlStr(), RelUrlStr(_RelUrlStr), BaseUrlStr(_BaseUrlStr),
231  SchemeNm(), HostNm(),
232  PortStr(), PathStr(), SearchStr(), FragIdStr(),
233  PortN(-1), PathSegV(),
234  IpNum(),
236  HttpRqStr(){
237  RelUrlStr.ToTrunc();
238  RelUrlStr.ChangeStrAll(" ", "%20");
239  try {
240  if (IsAbs(RelUrlStr)){
241  GetAbs(RelUrlStr);
242  } else
243  if (IsAbs(BaseUrlStr)){
245  } else {
246  Scheme=usUndef;
247  }
248  }
249  catch (PExcept&){Scheme=usUndef;}
250 
251  //** old version
252  /*
253  PUrl BaseUrl;
254  if (!BaseUrlStr.Empty()){ // must be outside try-block (CBuilder3.0 bug)
255  BaseUrl=TUrl::New(BaseUrlStr);}
256  try {
257  if (!BaseUrlStr.Empty()){
258  EAssertR(BaseUrl->IsOk(), "");}
259  if (IsAbs(RelUrlStr)){
260  GetAbs(RelUrlStr);
261  } else {
262  GetAbsFromBase(RelUrlStr, BaseUrlStr);
263  }
264  }
265  catch (PExcept&){Scheme=usUndef;}
266  */
267 }
void GetAbs(const TStr &AbsUrlStr)
Definition: url.cpp:154
int PortN
Definition: url.h:15
TStr HttpRqStr
Definition: url.h:19
TStr IpNum
Definition: url.h:17
static bool IsAbs(const TStr &UrlStr)
Definition: url.cpp:324
Definition: url.h:5
int ChangeStrAll(const TStr &SrcStr, const TStr &DstStr, const bool &FromStartP=false)
Definition: dt.cpp:1141
TStr FragIdStr
Definition: url.h:14
TStr PortStr
Definition: url.h:14
TStr RelUrlStr
Definition: url.h:12
TStr FinalUrlStr
Definition: url.h:18
TStr HostNm
Definition: url.h:13
TStr FinalHostNm
Definition: url.h:18
TStr & ToTrunc()
Definition: dt.cpp:770
TUrlScheme Scheme
Definition: url.h:11
Definition: bd.h:196
TStrV PathSegV
Definition: url.h:16
TStr SearchStr
Definition: url.h:14
void GetAbsFromBase(const TStr &RelUrlStr, const TStr &BaseUrlStr)
Definition: url.cpp:182
TStr BaseUrlStr
Definition: url.h:12
TStr PathStr
Definition: url.h:14
TStr SchemeNm
Definition: url.h:13
TStr UrlStr
Definition: url.h:12
TUrl::~TUrl ( )
inline

Definition at line 27 of file url.h.

27 {}
TUrl::TUrl ( TSIn )
inline

Definition at line 28 of file url.h.

28 {Fail;}
#define Fail
Definition: bd.h:238

Member Function Documentation

void TUrl::ChangeHttpRqStr ( const TStr SrcStr,
const TStr DstStr 
)
inline

Definition at line 75 of file url.h.

75  {
76  HttpRqStr.ChangeStr(SrcStr, DstStr);}
TStr HttpRqStr
Definition: url.h:19
int ChangeStr(const TStr &SrcStr, const TStr &DstStr, const int &BChN=0)
Definition: dt.cpp:1130
TStr TUrl::DecodeUrlStr ( const TStr UrlStr)
static

Definition at line 386 of file url.cpp.

386  {
387  TChA InChA=UrlStr; TChA OutChA;
388  for (int ChN=0; ChN<InChA.Len(); ChN++){
389  char Ch=InChA[ChN];
390  if (Ch=='+'){
391  OutChA+=' ';
392  } else if (Ch=='%') {
393  ChN++; if (ChN==InChA.Len()) { break; }
394  char FirstCh = InChA[ChN];
395  if (!TCh::IsHex(FirstCh)) { break; }
396  ChN++; if (ChN==InChA.Len()) { break; }
397  char SecondCh = InChA[ChN];
398  if (!TCh::IsHex(SecondCh)) { break; }
399  OutChA+=char(TCh::GetHex(FirstCh)*16 + TCh::GetHex(SecondCh));
400  } else {
401  OutChA+=Ch;
402  }
403  }
404  return OutChA;
405 }
static bool IsHex(const char &Ch)
Definition: dt.h:977
static int GetHex(const char &Ch)
Definition: dt.h:979
int Len() const
Definition: dt.h:259
Definition: dt.h:201
TStr UrlStr
Definition: url.h:12
void TUrl::DefFinalUrl ( const TStr _FinalHostNm)

Definition at line 284 of file url.cpp.

284  {
285  EAssert(IsOk(usHttp));
287  FinalHostNm=_FinalHostNm.GetLc();
288  if (HostNm==FinalHostNm){
290  } else {
291  TChA FinalUrlChA;
292  FinalUrlChA+=SchemeNm; FinalUrlChA+="://";
293  FinalUrlChA+=FinalHostNm;
294  if (!PortStr.Empty()){
295  FinalUrlChA+=":"; FinalUrlChA+=PortStr;}
296  FinalUrlChA+=PathStr;
297  FinalUrlChA+=SearchStr;
298  FinalUrlStr=FinalUrlChA;
299  }
300 }
Definition: url.h:5
bool IsOk(const TUrlScheme _Scheme=usUndef) const
Definition: url.h:32
TStr GetLc() const
Definition: dt.h:499
TStr PortStr
Definition: url.h:14
TStr FinalUrlStr
Definition: url.h:18
TStr HostNm
Definition: url.h:13
TStr FinalHostNm
Definition: url.h:18
Definition: dt.h:201
#define EAssert(Cond)
Definition: bd.h:280
bool Empty() const
Definition: dt.h:488
bool IsDefFinalUrl() const
Definition: url.h:57
TStr SearchStr
Definition: url.h:14
TStr PathStr
Definition: url.h:14
TStr SchemeNm
Definition: url.h:13
TStr UrlStr
Definition: url.h:12
void TUrl::DefUrlAsFinal ( )
inline

Definition at line 67 of file url.h.

67  {
Definition: url.h:5
bool IsOk(const TUrlScheme _Scheme=usUndef) const
Definition: url.h:32
TStr FinalUrlStr
Definition: url.h:18
TStr HostNm
Definition: url.h:13
TStr FinalHostNm
Definition: url.h:18
#define EAssert(Cond)
Definition: bd.h:280
bool IsDefFinalUrl() const
Definition: url.h:57
TStr UrlStr
Definition: url.h:12
static TStr TUrl::EncodeUrlStr ( const TStr Str)
inlinestatic

Definition at line 91 of file url.h.

91 {return GetUrlSearchStr(Str);}
static TStr GetUrlSearchStr(const TStr &Str)
Definition: url.cpp:368
void TUrl::GetAbs ( const TStr AbsUrlStr)
private

Definition at line 154 of file url.cpp.

154  {
155  EAssertR(IsAbs(AbsUrlStr), AbsUrlStr);
156  TUrlLx Lx(AbsUrlStr); TChA Str;
157  Str+=SchemeNm=Lx.GetScheme(); Str+=Lx.GetCh(':');
158  if (SchemeNm=="http"){
159  Scheme=usHttp;
160  const char *DbSlashStr="//";
161  Str+=Lx.GetStr(DbSlashStr);
162  Str+=Lx.GetHostPort(HostNm, PortStr, PortN);
163  if (PortN==-1){PortN=THttp::DfPortN; PortStr.Clr();}
164  else if (PortN==THttp::DfPortN){PortStr.Clr();}
165  //**if (!PortStr.Empty()){Str+=':'; Str+=PortStr;}
166  if (Lx.PeekCh()=='/'){
167  PathStr=Lx.GetCh('/'); PathStr+=Lx.GetHPath(PathSegV); Str+=PathStr;}
168  if (PathStr.Empty()){PathStr="/"; Str+=PathStr;}
169  if (Lx.PeekCh()=='?'){
170  SearchStr=Lx.GetCh('?'); SearchStr+=Lx.GetSearch(); Str+=SearchStr;}
171  } else {
172  Scheme=usOther; Str+=Lx.GetToCh();
173  }
174  while (Lx.PeekCh()==' '){Lx.GetCh();}
175  if (Lx.PeekCh()=='#'){
176  FragIdStr=Lx.GetCh('#'); FragIdStr+=Lx.GetToCh();
177  }
178  EAssertR(Lx.Eof(), "");
179  UrlStr=Str;
180 }
static const int DfPortN
Definition: http.h:46
int PortN
Definition: url.h:15
Definition: url.h:5
void Clr()
Definition: dt.h:486
static bool IsAbs(const TStr &UrlStr)
Definition: url.cpp:324
TStr FragIdStr
Definition: url.h:14
TStr PortStr
Definition: url.h:14
char GetCh(const int &ChN) const
Definition: dt.h:483
char GetCh(const int &ChN) const
Definition: dt.h:280
TStr HostNm
Definition: url.h:13
Definition: dt.h:201
Definition: url.h:5
bool Empty() const
Definition: dt.h:488
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
TUrlScheme Scheme
Definition: url.h:11
TStrV PathSegV
Definition: url.h:16
TStr SearchStr
Definition: url.h:14
Definition: url.cpp:76
TStr PathStr
Definition: url.h:14
TStr SchemeNm
Definition: url.h:13
TStr UrlStr
Definition: url.h:12
void TUrl::GetAbsFromBase ( const TStr RelUrlStr,
const TStr BaseUrlStr 
)
private

Definition at line 182 of file url.cpp.

182  {
183  EAssertR(!BaseUrlStr.Empty(), "");
184  PUrl Url=TUrl::New(BaseUrlStr); EAssertR(Url->IsOk(), "");
185  EAssertR(IsAbs(BaseUrlStr), "");
186  TStr AbsUrlStr=BaseUrlStr;
187  TStr NrRelUrlStr=RelUrlStr;
188  if (NrRelUrlStr.GetLc().IsPrefix(UrlHttpPrefixStr)){
189  NrRelUrlStr.DelSubStr(0, UrlHttpPrefixStr.Len()-1);}
190  if (NrRelUrlStr.Len()>0){
191  if (NrRelUrlStr[0]=='/'){
192  TStr SlashStr; int SlashChN=0;
193  while ((SlashChN<NrRelUrlStr.Len())&&(NrRelUrlStr[SlashChN]=='/')){
194  SlashChN++; SlashStr+="/";}
195  int ChN=0; bool Found=false;
196  while ((!Found)&&((ChN=AbsUrlStr.SearchStr(SlashStr, ChN))!=-1)){
197  TStr Str=AbsUrlStr.GetSubStr(ChN-1, ChN+SlashStr.Len()-1+1);
198  Found=((ChN==0)||(Str[0]!='/'))&&
199  ((ChN+SlashStr.Len()-1==AbsUrlStr.Len()-1)||(Str[Str.Len()-1]!='/'));
200  if (!Found){ChN++;}
201  }
202  if (Found){
203  AbsUrlStr.DelSubStr(ChN, AbsUrlStr.Len()-1);
204  AbsUrlStr+=NrRelUrlStr;
205  }
206  } else {
207  int ChN=AbsUrlStr.Len()-1;
208  while ((ChN>=0)&&(AbsUrlStr[ChN]!='/')){ChN--;}
209  AbsUrlStr.DelSubStr(ChN+1, AbsUrlStr.Len()-1);
210  AbsUrlStr+=NrRelUrlStr;
211  }
212  }
213 
214  const char *PrevDirStr="/../";
215  {int ChN;
216  while ((ChN=AbsUrlStr.SearchStr(PrevDirStr))!=-1){
217  int BChN=ChN; int EChN=ChN+(int) strlen(PrevDirStr)-1;
218  while ((BChN-1>=0)&&(AbsUrlStr[BChN-1]!='/')){BChN--;}
219  AbsUrlStr.DelSubStr(BChN, EChN);
220  }}
221 
222  const char *CurDirStr="/.";
223  while (AbsUrlStr.DelStr(CurDirStr)){}
224 
225  GetAbs(AbsUrlStr);
226 }
int Len() const
Definition: dt.h:487
void GetAbs(const TStr &AbsUrlStr)
Definition: url.cpp:154
bool IsPrefix(const char *Str) const
Definition: dt.cpp:1081
static PUrl New(const TStr &RelUrlStr, const TStr &BaseUrlStr=TStr())
Definition: url.h:25
TStr GetSubStr(const int &BChN, const int &EChN) const
Definition: dt.cpp:811
bool DelStr(const TStr &Str)
Definition: dt.cpp:863
static bool IsAbs(const TStr &UrlStr)
Definition: url.cpp:324
static const TStr UrlHttpPrefixStr
Definition: url.h:9
int SearchStr(const TStr &Str, const int &BChN=0) const
Definition: dt.cpp:1065
TStr GetLc() const
Definition: dt.h:499
TStr RelUrlStr
Definition: url.h:12
void DelSubStr(const int &BChN, const int &EChN)
Definition: dt.cpp:850
Definition: dt.h:412
bool Empty() const
Definition: dt.h:488
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
Definition: bd.h:196
TStr BaseUrlStr
Definition: url.h:12
TStr TUrl::GetAsFinalHostNm ( ) const
inline

Definition at line 65 of file url.h.

65  {
66  if (IsDefFinalUrl()){return FinalHostNm;} else {return HostNm;}}
TStr HostNm
Definition: url.h:13
TStr FinalHostNm
Definition: url.h:18
bool IsDefFinalUrl() const
Definition: url.h:57
TStr TUrl::GetAsFinalUrlStr ( ) const
inline

Definition at line 61 of file url.h.

61  {
62  if (IsDefFinalUrl()){return FinalUrlStr;} else {return UrlStr;}}
TStr FinalUrlStr
Definition: url.h:18
bool IsDefFinalUrl() const
Definition: url.h:57
TStr UrlStr
Definition: url.h:12
TStr TUrl::GetBaseUrlStr ( ) const
inline

Definition at line 39 of file url.h.

39 {return BaseUrlStr;}
TStr BaseUrlStr
Definition: url.h:12
TStr TUrl::GetDmNm ( const int &  MxDmSegs = -1) const

Definition at line 269 of file url.cpp.

269  {
270  EAssert(IsOk());
271  TChA DmChA; int DmSegs=0;
272  for (int ChN=HostNm.Len()-1; ChN>=0; ChN--){
273  if (HostNm[ChN]=='.'){
274  DmSegs++;
275  if (DmSegs==MxDmSegs){break;} else {DmChA+='.';}
276  } else {
277  DmChA+=HostNm[ChN];
278  }
279  }
280  DmChA.Reverse();
281  return DmChA;
282 }
int Len() const
Definition: dt.h:487
bool IsOk(const TUrlScheme _Scheme=usUndef) const
Definition: url.h:32
void Reverse()
Definition: dt.cpp:440
TStr HostNm
Definition: url.h:13
Definition: dt.h:201
#define EAssert(Cond)
Definition: bd.h:280
TStr TUrl::GetDocStrFromUrlStr ( const TStr UrlStr,
const int &  Copies = 1 
)
static

Definition at line 407 of file url.cpp.

407  {
408  TStrV StrV; UrlStr.SplitOnNonAlNum(StrV);
409  TChA DocChA;
410  for (int StrN=0; StrN<StrV.Len(); StrN++){
411  TStr UcStr=StrV[StrN].GetUc();
412  if ((UcStr.Len()>3)&&(UcStr!="HTTP")&&(UcStr!="HTML")&&(UcStr!="INDEX")&&(UcStr!="DEFAULT")){
413  for (int CopyN=0; CopyN<Copies; CopyN++){
414  if (!DocChA.Empty()){DocChA+=' ';} DocChA+=StrV[StrN];
415  }
416  }
417  }
418  return DocChA;
419 }
int Len() const
Definition: dt.h:487
bool Empty() const
Definition: dt.h:260
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
Definition: dt.h:201
void SplitOnNonAlNum(TStrV &StrV) const
Definition: dt.cpp:990
Definition: dt.h:412
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:429
TStr TUrl::GetFinalHostNm ( ) const
inline

Definition at line 63 of file url.h.

63  {
64  EAssert(IsDefFinalUrl()); return FinalHostNm;}
TStr FinalHostNm
Definition: url.h:18
#define EAssert(Cond)
Definition: bd.h:280
bool IsDefFinalUrl() const
Definition: url.h:57
TStr TUrl::GetFinalUrlStr ( ) const
inline

Definition at line 59 of file url.h.

59  {
60  EAssert(IsDefFinalUrl()); return FinalUrlStr;}
TStr FinalUrlStr
Definition: url.h:18
#define EAssert(Cond)
Definition: bd.h:280
bool IsDefFinalUrl() const
Definition: url.h:57
TStr TUrl::GetFragIdStr ( ) const
inline

Definition at line 50 of file url.h.

50 {EAssert(IsOk()); return FragIdStr;}
bool IsOk(const TUrlScheme _Scheme=usUndef) const
Definition: url.h:32
TStr FragIdStr
Definition: url.h:14
#define EAssert(Cond)
Definition: bd.h:280
TStr TUrl::GetHostNm ( ) const
inline

Definition at line 41 of file url.h.

41 {EAssert(IsOk()); return HostNm;}
bool IsOk(const TUrlScheme _Scheme=usUndef) const
Definition: url.h:32
TStr HostNm
Definition: url.h:13
#define EAssert(Cond)
Definition: bd.h:280
TStr TUrl::GetHttpRqStr ( ) const
inline

Definition at line 73 of file url.h.

73 {return HttpRqStr;}
TStr HttpRqStr
Definition: url.h:19
TStr TUrl::GetIpNum ( ) const
inline

Definition at line 54 of file url.h.

54 {EAssert(IsIpNum()); return IpNum;}
TStr IpNum
Definition: url.h:17
bool IsIpNum() const
Definition: url.h:52
#define EAssert(Cond)
Definition: bd.h:280
TStr TUrl::GetIpNumOrHostNm ( ) const
inline

Definition at line 55 of file url.h.

55 {return IsIpNum() ? GetIpNum() : GetHostNm();}
TStr GetIpNum() const
Definition: url.h:54
bool IsIpNum() const
Definition: url.h:52
TStr GetHostNm() const
Definition: url.h:41
TStr TUrl::GetPathSeg ( const int &  PathSegN) const
inline

Definition at line 48 of file url.h.

48 {return PathSegV[PathSegN];}
TStrV PathSegV
Definition: url.h:16
int TUrl::GetPathSegs ( ) const
inline

Definition at line 47 of file url.h.

47 {return PathSegV.Len();}
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TStrV PathSegV
Definition: url.h:16
TStr TUrl::GetPathStr ( ) const
inline

Definition at line 46 of file url.h.

46 {EAssert(IsOk()); return PathStr;}
bool IsOk(const TUrlScheme _Scheme=usUndef) const
Definition: url.h:32
#define EAssert(Cond)
Definition: bd.h:280
TStr PathStr
Definition: url.h:14
int TUrl::GetPortN ( ) const
inline

Definition at line 45 of file url.h.

45 {EAssert(IsOk()&&(PortN!=-1)); return PortN;}
int PortN
Definition: url.h:15
bool IsOk(const TUrlScheme _Scheme=usUndef) const
Definition: url.h:32
#define EAssert(Cond)
Definition: bd.h:280
TStr TUrl::GetPortStr ( ) const
inline

Definition at line 44 of file url.h.

44 {EAssert(IsOk()); return PortStr;}
bool IsOk(const TUrlScheme _Scheme=usUndef) const
Definition: url.h:32
TStr PortStr
Definition: url.h:14
#define EAssert(Cond)
Definition: bd.h:280
TStr TUrl::GetRelUrlStr ( ) const
inline

Definition at line 37 of file url.h.

37 {return RelUrlStr;}
TStr RelUrlStr
Definition: url.h:12
TUrlScheme TUrl::GetScheme ( )
inline

Definition at line 35 of file url.h.

35 {return Scheme;}
TUrlScheme Scheme
Definition: url.h:11
TStr TUrl::GetSchemeNm ( ) const
inline

Definition at line 40 of file url.h.

40 {EAssert(IsOk()); return SchemeNm;}
bool IsOk(const TUrlScheme _Scheme=usUndef) const
Definition: url.h:32
#define EAssert(Cond)
Definition: bd.h:280
TStr SchemeNm
Definition: url.h:13
TStr TUrl::GetSearchStr ( ) const
inline

Definition at line 49 of file url.h.

49 {EAssert(IsOk()); return SearchStr;}
bool IsOk(const TUrlScheme _Scheme=usUndef) const
Definition: url.h:32
#define EAssert(Cond)
Definition: bd.h:280
TStr SearchStr
Definition: url.h:14
TStr TUrl::GetTopDownDocNm ( const TStr UrlStr,
const int &  MxLen = -1,
const bool &  HostOnlyP = false 
)
static

Definition at line 421 of file url.cpp.

422  {
423  PUrl Url=TUrl::New(UrlStr);
424  TChA DocNm;
425  if (Url->IsOk()){
426  TStr HostNm=Url->GetHostNm().GetLc();
427  TStrV HostNmSegV; HostNm.SplitOnAllCh('.', HostNmSegV, false);
428  for (int HostNmSegN=0; HostNmSegN<HostNmSegV.Len(); HostNmSegN++){
429  if (HostNmSegN>0){DocNm+='.';}
430  DocNm+=HostNmSegV[HostNmSegV.Len()-HostNmSegN-1];
431  }
432  if (!HostOnlyP){
433  DocNm+=Url->GetPathStr().GetLc();
434  }
435  } else {
436  DocNm=UrlStr.GetLc();
437  }
438  if (MxLen!=-1){
439  DocNm.Trunc(MxLen);}
440  return DocNm;
441 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
static PUrl New(const TStr &RelUrlStr, const TStr &BaseUrlStr=TStr())
Definition: url.h:25
TStr GetLc() const
Definition: dt.h:499
void Trunc()
Definition: dt.cpp:420
TStr HostNm
Definition: url.h:13
Definition: dt.h:201
Definition: dt.h:412
void SplitOnAllCh(const char &SplitCh, TStrV &StrV, const bool &SkipEmpty=true) const
Definition: dt.cpp:926
Definition: bd.h:196
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:429
PUrl TUrl::GetUrlFromShortcut ( const TStr ShortcutUrlStr,
const TStr DfHostNmPrefix,
const TStr DfHostNmSufix 
)
static

Definition at line 343 of file url.cpp.

344  {
345  // shortcut is already correct url
346  TStr UrlStr=ShortcutUrlStr;
347  PUrl Url=TUrl::New(UrlStr);
348  if (Url->IsOk()){return Url;}
349  // add 'http://' to shortcut (if shortcut is from more segments)
350  if (ShortcutUrlStr.IsChIn('.')){
351  UrlStr=TUrl::UrlHttpAbsPrefixStr+ShortcutUrlStr;
352  Url=TUrl::New(UrlStr);
353  if (Url->IsOk()){return Url;}
354  }
355  // add 'http://' and '/' to shortcut (if shortcut is from more segments)
356  if (ShortcutUrlStr.IsChIn('.')){
357  UrlStr=TUrl::UrlHttpAbsPrefixStr+ShortcutUrlStr+"/";
358  Url=TUrl::New(UrlStr);
359  if (Url->IsOk()){return Url;}
360  }
361  // add 'http://', prefix, postfix and '/' to shortcut
362  UrlStr=UrlHttpAbsPrefixStr+
363  DfHostNmPrefix+"."+ShortcutUrlStr+"."+DfHostNmSufix+"/";
364  Url=TUrl::New(UrlStr);
365  return Url;
366 }
static PUrl New(const TStr &RelUrlStr, const TStr &BaseUrlStr=TStr())
Definition: url.h:25
Definition: dt.h:412
bool IsChIn(const char &Ch) const
Definition: dt.h:553
Definition: bd.h:196
static const TStr UrlHttpAbsPrefixStr
Definition: url.h:10
TStr UrlStr
Definition: url.h:12
TStr TUrl::GetUrlSearchStr ( const TStr Str)
static

Definition at line 368 of file url.cpp.

368  {
369  TChA InChA=Str; TChA OutChA;
370  for (int ChN=0; ChN<InChA.Len(); ChN++){
371  char Ch=InChA[ChN];
372  if (Ch==' '){
373  OutChA+='+';
374  } else
375  if ((' '<Ch)&&(Ch<='~')&&(Ch!='+')&&(Ch!='&')&&(Ch!='%')){
376  OutChA+=Ch;
377  } else {
378  OutChA+='%';
379  OutChA+=TInt::GetHexStr(uchar(Ch)/16);
380  OutChA+=TInt::GetHexStr(uchar(Ch)%16);
381  }
382  }
383  return OutChA;
384 }
static TStr GetHexStr(const int &Val)
Definition: dt.h:1124
int Len() const
Definition: dt.h:259
unsigned char uchar
Definition: bd.h:10
Definition: dt.h:201
TStr TUrl::GetUrlStr ( ) const
inline

Definition at line 36 of file url.h.

36 {return UrlStr;}
TStr UrlStr
Definition: url.h:12
bool TUrl::IsAbs ( const TStr UrlStr)
static

Definition at line 324 of file url.cpp.

324  {
325  if (UrlStr.GetLc().IsPrefix(UrlHttpPrefixStr)){
326  return UrlStr.GetLc().IsPrefix(UrlHttpAbsPrefixStr);
327  } else {
328  int ColonChN=UrlStr.SearchCh(':'); int SlashChN=UrlStr.SearchCh('/');
329  return (ColonChN!=-1)&&((SlashChN==-1)||((SlashChN!=-1)&&(ColonChN<SlashChN)));
330  }
331 }
int SearchCh(const char &Ch, const int &BChN=0) const
Definition: dt.cpp:1043
bool IsPrefix(const char *Str) const
Definition: dt.cpp:1081
static const TStr UrlHttpPrefixStr
Definition: url.h:9
TStr GetLc() const
Definition: dt.h:499
static const TStr UrlHttpAbsPrefixStr
Definition: url.h:10
bool TUrl::IsBaseUrl ( )
inline

Definition at line 38 of file url.h.

38 {return !BaseUrlStr.Empty();}
bool Empty() const
Definition: dt.h:488
TStr BaseUrlStr
Definition: url.h:12
bool TUrl::IsDefFinalUrl ( ) const
inline

Definition at line 57 of file url.h.

57  {
58  EAssert(IsOk(usHttp)); return !FinalUrlStr.Empty();}
Definition: url.h:5
bool IsOk(const TUrlScheme _Scheme=usUndef) const
Definition: url.h:32
TStr FinalUrlStr
Definition: url.h:18
#define EAssert(Cond)
Definition: bd.h:280
bool Empty() const
Definition: dt.h:488
bool TUrl::IsHttpRqStr ( ) const
inline

Definition at line 74 of file url.h.

74 {return !HttpRqStr.Empty();}
TStr HttpRqStr
Definition: url.h:19
bool Empty() const
Definition: dt.h:488
bool TUrl::IsInHost ( const TStr _HostNm) const
inline

Definition at line 78 of file url.h.

78  {
79  EAssert(IsOk()); return HostNm.GetUc().IsSuffix(_HostNm.GetUc());}
TStr GetUc() const
Definition: dt.h:493
bool IsOk(const TUrlScheme _Scheme=usUndef) const
Definition: url.h:32
bool IsSuffix(const char *Str) const
Definition: dt.cpp:1093
TStr HostNm
Definition: url.h:13
#define EAssert(Cond)
Definition: bd.h:280
bool TUrl::IsInPath ( const TStr _PathStr) const
inline

Definition at line 80 of file url.h.

80  {
81  EAssert(IsOk()); return PathStr.GetUc().IsPrefix(_PathStr.GetUc());}
bool IsPrefix(const char *Str) const
Definition: dt.cpp:1081
TStr GetUc() const
Definition: dt.h:493
bool IsOk(const TUrlScheme _Scheme=usUndef) const
Definition: url.h:32
#define EAssert(Cond)
Definition: bd.h:280
TStr PathStr
Definition: url.h:14
bool TUrl::IsIpNum ( ) const
inline

Definition at line 52 of file url.h.

52 {return !IpNum.Empty();}
TStr IpNum
Definition: url.h:17
bool Empty() const
Definition: dt.h:488
bool TUrl::IsOk ( const TUrlScheme  _Scheme = usUndef) const
inline

Definition at line 32 of file url.h.

32  {
33  if (_Scheme==usUndef){return Scheme!=usUndef;}
34  else {return Scheme==_Scheme;}}
Definition: url.h:5
TUrlScheme Scheme
Definition: url.h:11
bool TUrl::IsPortOk ( ) const
inline

Definition at line 43 of file url.h.

43 { EAssert(IsOk()); return (PortN > 0); }
int PortN
Definition: url.h:15
bool IsOk(const TUrlScheme _Scheme=usUndef) const
Definition: url.h:32
#define EAssert(Cond)
Definition: bd.h:280
bool TUrl::IsScript ( const TStr UrlStr)
static

Definition at line 333 of file url.cpp.

333  {
334  return UrlStr.IsChIn('?');
335 }
bool IsChIn(const char &Ch) const
Definition: dt.h:553
bool TUrl::IsSite ( const TStr UrlStr)
static

Definition at line 337 of file url.cpp.

337  {
338  PUrl Url=TUrl::New(UrlStr);
339  return Url->IsOk(usHttp) && (Url->GetPathStr()=="/") &&
340  Url->GetSearchStr().Empty() && Url->GetFragIdStr().Empty();
341 }
Definition: url.h:5
bool Empty() const
Definition: bd.h:501
static PUrl New(const TStr &RelUrlStr, const TStr &BaseUrlStr=TStr())
Definition: url.h:25
Definition: bd.h:196
static PUrl TUrl::Load ( TSIn )
inlinestatic

Definition at line 29 of file url.h.

29 {Fail; return NULL;}
#define Fail
Definition: bd.h:238
static PUrl TUrl::New ( const TStr RelUrlStr,
const TStr BaseUrlStr = TStr() 
)
inlinestatic

Definition at line 25 of file url.h.

25  {
26  return PUrl(new TUrl(RelUrlStr, BaseUrlStr));}
TUrl(const TStr &_RelUrlStr, const TStr &_BaseUrlStr=TStr())
Definition: url.cpp:228
TPt< TUrl > PUrl
Definition: url.h:7
void TUrl::PutHttpRqStr ( const TStr _HttpRqStr)
inline

Definition at line 72 of file url.h.

72 {HttpRqStr=_HttpRqStr;}
TStr HttpRqStr
Definition: url.h:19
void TUrl::PutIpNum ( const TStr _IpNum)
inline

Definition at line 53 of file url.h.

53 {IpNum=_IpNum;}
TStr IpNum
Definition: url.h:17
void TUrl::Save ( TSOut )
inline

Definition at line 30 of file url.h.

30 {Fail;}
#define Fail
Definition: bd.h:238
void TUrl::ToLcPath ( )

Definition at line 302 of file url.cpp.

302  {
303  // test if the conversion is needed
304  if (!PathStr.IsLc()){
305  // convert path strings to lower-case
306  PathStr.ToLc();
307  for (int PathSegN=0; PathSegN<PathSegV.Len(); PathSegN++){
308  PathSegV[PathSegN].ToLc();}
309  // recompose url
310  TChA UrlChA;
311  UrlChA+=SchemeNm; UrlChA+="://";
312  UrlChA+=HostNm;
313  if (!PortStr.Empty()){
314  UrlChA+=":"; UrlChA+=PortStr;}
315  UrlChA+=PathStr;
316  UrlChA+=SearchStr;
317  UrlStr=UrlChA;
318  // recompose final-url
319  if (IsDefFinalUrl()){
321  }
322 }
bool IsLc() const
Definition: dt.h:497
void DefFinalUrl(const TStr &_FinalHostNm)
Definition: url.cpp:284
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
void Clr()
Definition: dt.h:486
TStr & ToLc()
Definition: dt.cpp:758
TStr PortStr
Definition: url.h:14
TStr FinalUrlStr
Definition: url.h:18
TStr HostNm
Definition: url.h:13
TStr FinalHostNm
Definition: url.h:18
Definition: dt.h:201
bool Empty() const
Definition: dt.h:488
bool IsDefFinalUrl() const
Definition: url.h:57
TStrV PathSegV
Definition: url.h:16
TStr SearchStr
Definition: url.h:14
TStr PathStr
Definition: url.h:14
TStr SchemeNm
Definition: url.h:13
TStr UrlStr
Definition: url.h:12
TUrl::UndefDefaultCopyAssign ( TUrl  )
private

Friends And Related Function Documentation

friend class TPt< TUrl >
friend

Definition at line 7 of file url.h.

Member Data Documentation

TStr TUrl::BaseUrlStr
private

Definition at line 12 of file url.h.

TCRef TUrl::CRef
private

Definition at line 7 of file url.h.

TStr TUrl::FinalHostNm
private

Definition at line 18 of file url.h.

TStr TUrl::FinalUrlStr
private

Definition at line 18 of file url.h.

TStr TUrl::FragIdStr
private

Definition at line 14 of file url.h.

TStr TUrl::HostNm
private

Definition at line 13 of file url.h.

TStr TUrl::HttpRqStr
private

Definition at line 19 of file url.h.

TStr TUrl::IpNum
private

Definition at line 17 of file url.h.

TStrV TUrl::PathSegV
private

Definition at line 16 of file url.h.

TStr TUrl::PathStr
private

Definition at line 14 of file url.h.

int TUrl::PortN
private

Definition at line 15 of file url.h.

TStr TUrl::PortStr
private

Definition at line 14 of file url.h.

TStr TUrl::RelUrlStr
private

Definition at line 12 of file url.h.

TUrlScheme TUrl::Scheme
private

Definition at line 11 of file url.h.

TStr TUrl::SchemeNm
private

Definition at line 13 of file url.h.

TStr TUrl::SearchStr
private

Definition at line 14 of file url.h.

const TStr TUrl::UrlHttpAbsPrefixStr ="http://"
staticprivate

Definition at line 10 of file url.h.

const TStr TUrl::UrlHttpPrefixStr ="http:"
staticprivate

Definition at line 9 of file url.h.

TStr TUrl::UrlStr
private

Definition at line 12 of file url.h.


The documentation for this class was generated from the following files: