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.

72 lines
1.7 KiB

  1. /*---------------------------------------------------------------------------
  2. File: DottedString.cpp
  3. Comments: Utility class used to parse dot-delimited strings
  4. (c) Copyright 1995-1998, Mission Critical Software, Inc., All Rights Reserved
  5. Proprietary and confidential to Mission Critical Software, Inc.
  6. REVISION LOG ENTRY
  7. Revision By: Christy Boles
  8. Revised on 11/19/98 17:23:47
  9. ---------------------------------------------------------------------------
  10. */
  11. #include "stdafx.h"
  12. #include "DotStr.hpp"
  13. /////////////////////////////////////////////////////
  14. // Utility class used to parse dot-delimited strings
  15. /////////////////////////////////////////////////////
  16. void
  17. CDottedString::Init()
  18. {
  19. // count the number of segments
  20. m_nSegments = 1;
  21. for ( int i = 0 ; i < m_name.GetLength() ; i++ )
  22. {
  23. if ( m_name[i] == _T('.') )
  24. {
  25. m_nSegments++;
  26. }
  27. }
  28. // special case for empty string
  29. if ( m_name.IsEmpty() )
  30. {
  31. m_nSegments = 0;
  32. }
  33. }
  34. void
  35. CDottedString::GetSegment(
  36. int ndx, // in - which segment to get (first=0)
  37. CString & str // out- segment, or empty string if ndx is not valid
  38. )
  39. {
  40. int n = ndx;
  41. int x;
  42. str = _T("");
  43. if ( ndx >= 0 && ndx < m_nSegments )
  44. {
  45. str = m_name;
  46. while ( n )
  47. {
  48. // x = str.Find(_T("."),0);
  49. x = str.Find(_T("."));
  50. str = str.Right(str.GetLength() - x - 1);
  51. n--;
  52. }
  53. // x = str.Find(_T("."),0);
  54. x = str.Find(_T("."));
  55. if ( x >= 0 )
  56. {
  57. str = str.Left(x);
  58. }
  59. }
  60. }