gdNetNames.cpp

Go to the documentation of this file.
00001 // gdNetNames.cpp -- Version 0.1
00002 
00003 #include "gdNetNames.h"
00004 // HOW-TO URIs:
00005 //
00006 // Consider the following URI:
00007 //      http://pt.freescosoft.net/images/background.jpg
00008 //      GetDomainStr()="pt.freescosoft.net", same as Str()
00009 //      GetPathStr()="/images/background.jpg"
00010 //      GetRelativePathStr()="images/background.jpg" (same as GetPathStr except leading slashes)
00011 //      GetDomainAndPathStr()="pt.freescosoft.net/images/"
00012 //      GetPathNameStr()="background.jpg"
00013 // .
00014 ////////////////////////////////////////////////////////////
00015 gdURI::gdURI (char* strURI)
00016 {
00017  if ( strURI!=nil )  SetString( strURI );
00018 }
00019 
00020 gdURI::gdURI (gURI::eScheme aScheme, char* strURI)
00021     : gURI( aScheme )
00022 {
00023  ASSERTION(strURI!=nil,"strURI!=nil");
00024  SetString( strURI );
00025 }
00026 
00027 gdURI::~gdURI ()
00028 {
00029 }
00030 
00031 bool gdURI::IsOk ()
00032 {
00033  bool isOk;
00034 
00035  // This IsOk is far less relaxed than gURI
00036  isOk = IsValidDomain();
00037 
00038  //printf("DBG: [[[DOMAIN:%s]]]:valid?%d,gURI::IsOk()?%d, SCHEME_INVALID?%d\n",GetDomainStr(),isOk,gURI::IsOk(),GetScheme()==e_invalid);
00039  ;
00040  return isOk && IsOkScheme() && gURI::IsOk();  // True if domain and scheme are o.k.
00041 }
00042 
00043 bool gdURI::IsValidDomain ()
00044 {
00045  bool isOk = gURI::IsValidDomain();
00046  gString sDomain( GetDomainStr() );
00047 
00048  if ( isOk==false ) return false;
00049  isOk = sDomain.FindExcept(
00050      "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-." )==0;
00051 
00052  return isOk;
00053 }
00054 
00055 char* gdURI::GetPathStr ()
00056 {
00057  return gURI::GetPathStr();
00058  // ...repeated in a dummy way: would not be redefined.
00059 }
00060 
00061 char* gdURI::GetRelativePathStr (eSwift aSwift)
00062 {
00063  unsigned pos;
00064  gString sTemp( GetPathStr() );
00065  pos = sTemp.FindExcept( "/" );
00066  // If there would be well-behaved URLs, we would only compute the pad as:
00067  //     sPad.CopyFromTo( sTemp, 1+(sTemp[1]=='/') )
00068  // but we want to be relaxed with URLs, and allow multiple leading-slashes:
00069  sPad.CopyFromTo( sTemp, pos );
00070  // Note: pos=0 is interpreted as equal to pos=1, see gString...
00071  ASSERTION(aSwift==e_URI_NormalSwift,"TODO other 'swift's");
00072  return sPad.Str();
00073 }
00074 
00075 char* gdURI::GetDomainAndPathStr (eSwift aSwift)
00076 {
00077  unsigned pos;
00078  gString sTemp( GetDomainStr() );
00079  gString sRelative( GetRelativePathStr() );
00080 
00081  sPad.SetEmpty();
00082  pos = sRelative.FindBack( "/" );
00083 
00084  if ( pos>0 ) {
00085      sPad.CopyFromTo( sRelative, 1, pos-1 );
00086  }
00087 
00088  if ( sTemp.IsEmpty()==false ) {
00089      gString sDomain( sTemp );
00090      sDomain.Add( "/" );
00091      sPad.Insert( sDomain, 1 );
00092  }
00093 
00094  return sPad.Str();
00095 }
00096 
00097 char* gdURI::GetPathNameStr (eSwift aSwift)
00098 {
00099  unsigned pos;
00100  gString sPathFind( GetPathStr() );
00101  gString sComp( Str() );
00102 
00103  sPad.SetEmpty();
00104 
00105  pos = sComp.FindBack( sPathFind );
00106  sPathFind.CopyFromTo( sComp, pos+1 );
00107  if ( sPathFind.IsEmpty() ) return sPad.Str();
00108 
00109  sPad = sPathFind;
00110  pos = sPad.FindBack( "/" );
00111  if ( pos==0 ) {
00112      return sPad.Str();
00113  }
00114 
00115  sPad.CopyFromTo( sPathFind, pos+1 );
00116 
00117  return sPad.Str();
00118 }
00119 
00120 bool gdURI::Update ()
00121 {
00122  if ( IsOk() ) return false;  // No update
00123  // URI is fairly o.k., but e_invalid means no prefix 'http://' was given.
00124  // We try to recover situations like: 'file://abc/def'
00125  return true;
00126 }
00127 ////////////////////////////////////////////////////////////
00128 

Generated on Sat Aug 18 02:40:52 2007 for xpfweb_v2x lib by  doxygen 1.4.2