Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.0 KiB

  1. // Link.cpp: implementation of the CLink class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "NxtLnk.h"
  6. #include "Link.h"
  7. #include "NextLink.h"
  8. //////////////////////////////////////////////////////////////////////
  9. // Construction/Destruction
  10. //////////////////////////////////////////////////////////////////////
  11. CLink::CLink(
  12. const String& strLink,
  13. const String& strDesc )
  14. : m_strLink( strLink, false ), // set case sensitive to false
  15. m_strDesc( strDesc, false ) // set case sensitive to false
  16. {
  17. m_urlType = UrlType( m_strLink );
  18. }
  19. CLink::~CLink()
  20. {
  21. }
  22. bool
  23. CLink::IsEqual(
  24. const String& strLink ) const
  25. {
  26. bool rc = false;
  27. switch ( m_urlType )
  28. {
  29. case urlType_LocalAbsolute:
  30. {
  31. rc = ( strLink == m_strLink );
  32. } break;
  33. case urlType_Relative:
  34. {
  35. String strRel(strLink,false); // set case sensitive to false
  36. String::size_type p = strLink.find_last_of( _T('/') );
  37. if ( p != String::npos )
  38. {
  39. strRel = strLink.substr( p + 1, strLink.length() );
  40. }
  41. else
  42. {
  43. p = strLink.find_last_of( _T('\\') );
  44. if ( p != String::npos )
  45. {
  46. strRel = strLink.substr( p + 1, strLink.length() );
  47. }
  48. }
  49. if ( strRel == m_strLink )
  50. {
  51. rc = true;
  52. }
  53. } break;
  54. case urlType_Absolute:
  55. {
  56. CNextLink::RaiseException( IDS_ERROR_CANT_MATCH_ABSOLUTE_URLS );
  57. } break;
  58. default:
  59. {
  60. } break;
  61. }
  62. return rc;
  63. }
  64. int
  65. CLink::UrlType(
  66. const String& strUrl )
  67. {
  68. int urlType;
  69. const String slashSlash = _T("//");
  70. const String bslashBslash = _T("\\\\");
  71. if ( ( strUrl.compare( 0, 2, slashSlash ) == 0 ) ||
  72. ( strUrl.compare( 0, 2, bslashBslash ) == 0 ) )
  73. {
  74. urlType = urlType_Absolute;
  75. }
  76. else if ( ( strUrl[0] == _T('\\') ) || ( strUrl[0] == _T('/') ) )
  77. {
  78. urlType = urlType_LocalAbsolute;
  79. }
  80. else
  81. {
  82. if ( strUrl.find( _T(':') ) != String::npos )
  83. {
  84. urlType = urlType_Absolute;
  85. }
  86. else
  87. {
  88. urlType = urlType_Relative;
  89. }
  90. }
  91. return urlType;
  92. }