home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / src / win32 / StringTokenizer.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-13  |  1.9 KB  |  70 lines

  1. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
  2. // Copyright (C) 1999-2003 Forgotten
  3. // Copyright (C) 2004 Forgotten and the VBA development team
  4.  
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2, or(at your option)
  8. // any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software Foundation,
  17. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18.  
  19. // StringTokenizer.cpp: implementation of the StringTokenizer class.
  20. //
  21. //////////////////////////////////////////////////////////////////////
  22.  
  23. #include "stdafx.h"
  24. #include "vba.h"
  25. #include "StringTokenizer.h"
  26.  
  27. #ifdef _DEBUG
  28. #undef THIS_FILE
  29. static char THIS_FILE[]=__FILE__;
  30. #define new DEBUG_NEW
  31. #endif
  32.  
  33. //////////////////////////////////////////////////////////////////////
  34. // Construction/Destruction
  35. //////////////////////////////////////////////////////////////////////
  36.  
  37. StringTokenizer::StringTokenizer(CString str, CString del)
  38. {
  39.   m_right = str;
  40.   m_delim = del;
  41. }
  42.  
  43. StringTokenizer::~StringTokenizer()
  44. {
  45.  
  46. }
  47.  
  48.  
  49. const char *StringTokenizer::next()
  50. {
  51.   int index = m_right.FindOneOf(m_delim);
  52.   
  53.   while(index == 0) {
  54.     m_right = m_right.Right(m_right.GetLength()-1);
  55.     index = m_right.FindOneOf(m_delim);
  56.   }
  57.   if(index == -1) {
  58.     if(m_right.IsEmpty())
  59.       return NULL;
  60.     m_token = m_right;
  61.     m_right.Empty();
  62.     return m_token;
  63.   }
  64.  
  65.   m_token = m_right.Left(index);
  66.   m_right = m_right.Right(m_right.GetLength()-(1+index));
  67.  
  68.   return m_token;
  69. }
  70.