CAD工具之家's Archivers

From boitboy on 2013-09-01 13:09:44

把URL转换成绝对地址

// // ../表示向上一层 // ./表示同级目录下 // /表示根目录下的 // XX.htm表示当前目录下的 //把URL转换成绝对地址 //sURL,源地址 //str_fafURL,相对地址 //返回:绝对地址 CString OnConversionURL(CString sURL,CString str_fafURL) {  if(sURL.Find(_T("/"),8)<0)  {   sURL +=_T("/");  }  CString str_activeURL;  int int_j = 0;  int i=0;  str_activeURL = str_fafURL;  if(str_fafURL.Find(_T("../"),0)!=-1&&str_fafURL[0]!='/')  {   while( i<=str_fafURL.GetLength() )   {    if( str_fafURL[i] == '.' && str_fafURL[i+1] == '.' && str_fafURL[i+2] == '/' )    {     int_j++;    }    i++;   }   //int_j,../的首位置   if(str_fafURL[0]=='/')   {    str_fafURL.Delete(0,1);   }   str_fafURL.Replace(_T("../"),_T(""));   //设置为同级目录下没有意义   str_fafURL.Replace(_T("./"),_T(""));   i=0;   int int_i=0;   while( i <= sURL.GetLength() )   {    if( sURL[i]=='/' )    {     int_i++;    }    i++;   }   int_i -= int_j;   if( int_i<3 )   {    int_i = 3;   }   int int_cour=0;   for( i=0; i<=sURL.GetLength(); i++)   {    if( sURL[i]=='/' )    {     int_cour++;    }    if( int_cour==int_i )    {        sURL= sURL.Left(i+1);     break;    }   }   //容错处理   if( sURL[sURL.GetLength()-1]!='/' )   {     sURL +="/";   }   sURL += str_fafURL;   return sURL;  }  else if(str_fafURL.Find(_T("./"),0)!=-1&&str_fafURL[0]!='/')  {   while( i<=str_fafURL.GetLength() )   {    if( str_fafURL[i] == '.' && str_fafURL[i+1] == '/')    {     int_j++;    }    i++;   }   if(str_fafURL[0]=='/')   {    str_fafURL.Delete(0,1);   }   str_fafURL.Replace(_T("./"),_T(""));   i=0;   int int_i=0;   while( i <= sURL.GetLength() )   {    if( sURL[i]=='/' )    {     int_i++;    }    i++;   }   //int_i -= int_j;   if( int_i<3 )   {    int_i = 3;   }   int int_cour=0;   for( i=0; i<=sURL.GetLength(); i++)   {    if( sURL[i]=='/' )    {     int_cour++;    }    if( int_cour==int_i+1 )    {        sURL= sURL.Left(i+1);     break;    }   }   //容错处理   if( sURL[sURL.GetLength()-1]!='/' )   {     sURL +="/";   }   sURL += str_fafURL;   return sURL;  }  else  {   if( str_fafURL[0] =='/' )   {    int int_b = 0 ;    for( int a=0; int_b<3 && a<sURL.GetLength(); a++)    {     if( sURL[a]=='/' )     {      int_b++;     }     if( int_b==3 )     {      sURL = sURL.Left(a);      break;     }    }    sURL += str_fafURL;   }   else   {    for( int i=sURL.GetLength() ; i> 0 ; i-- )    {     if( sURL[i] =='/' )     {      sURL = sURL.Left( i+1 );      break;     }    }    sURL += str_fafURL;   }   return sURL;  } }

查看完整版本: 把URL转换成绝对地址

Tags: URL, 相对地址, 绝对地址


©CAD工具之家
创办于:2013年5月24日