home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / src / gtk / tools.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-13  |  1.7 KB  |  66 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. #include "tools.h"
  20.  
  21. namespace VBA
  22. {
  23.  
  24. std::string sCutSuffix(const std::string & _rsString,
  25.                        const std::string & _rsSep)
  26. {
  27.   return _rsString.substr(0, _rsString.find_last_of(_rsSep));
  28. }
  29.  
  30. Glib::ustring sCutSuffix(const Glib::ustring & _rsString,
  31.                          const Glib::ustring & _rsSep)
  32. {
  33.   return _rsString.substr(0, _rsString.find_last_of(_rsSep));
  34. }
  35.  
  36. bool bHasSuffix(const Glib::ustring & _rsString,
  37.                 const Glib::ustring & _rsSuffix,
  38.                 bool _bCaseSensitive)
  39. {
  40.   if (_rsSuffix.size() > _rsString.size())
  41.   {
  42.     return false;
  43.   }
  44.  
  45.   Glib::ustring sEnd = _rsString.substr(_rsString.size() - _rsSuffix.size());
  46.  
  47.   if (_bCaseSensitive)
  48.   {
  49.     if (_rsSuffix == sEnd)
  50.     {
  51.       return true;
  52.     }
  53.   }
  54.   else
  55.   {
  56.     if (_rsSuffix.lowercase() == sEnd.lowercase())
  57.     {
  58.       return true;
  59.     }
  60.   }
  61.  
  62.   return false;
  63. }
  64.  
  65. } // namespace VBA
  66.