annotate src/gtk/tools.cpp @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
rev   line source
rlm@1 1 // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
rlm@1 2 // Copyright (C) 1999-2003 Forgotten
rlm@1 3 // Copyright (C) 2004 Forgotten and the VBA development team
rlm@1 4
rlm@1 5 // This program is free software; you can redistribute it and/or modify
rlm@1 6 // it under the terms of the GNU General Public License as published by
rlm@1 7 // the Free Software Foundation; either version 2, or(at your option)
rlm@1 8 // any later version.
rlm@1 9 //
rlm@1 10 // This program is distributed in the hope that it will be useful,
rlm@1 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
rlm@1 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
rlm@1 13 // GNU General Public License for more details.
rlm@1 14 //
rlm@1 15 // You should have received a copy of the GNU General Public License
rlm@1 16 // along with this program; if not, write to the Free Software Foundation,
rlm@1 17 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
rlm@1 18
rlm@1 19 #include "tools.h"
rlm@1 20
rlm@1 21 namespace VBA
rlm@1 22 {
rlm@1 23
rlm@1 24 std::string sCutSuffix(const std::string & _rsString,
rlm@1 25 const std::string & _rsSep)
rlm@1 26 {
rlm@1 27 return _rsString.substr(0, _rsString.find_last_of(_rsSep));
rlm@1 28 }
rlm@1 29
rlm@1 30 Glib::ustring sCutSuffix(const Glib::ustring & _rsString,
rlm@1 31 const Glib::ustring & _rsSep)
rlm@1 32 {
rlm@1 33 return _rsString.substr(0, _rsString.find_last_of(_rsSep));
rlm@1 34 }
rlm@1 35
rlm@1 36 bool bHasSuffix(const Glib::ustring & _rsString,
rlm@1 37 const Glib::ustring & _rsSuffix,
rlm@1 38 bool _bCaseSensitive)
rlm@1 39 {
rlm@1 40 if (_rsSuffix.size() > _rsString.size())
rlm@1 41 {
rlm@1 42 return false;
rlm@1 43 }
rlm@1 44
rlm@1 45 Glib::ustring sEnd = _rsString.substr(_rsString.size() - _rsSuffix.size());
rlm@1 46
rlm@1 47 if (_bCaseSensitive)
rlm@1 48 {
rlm@1 49 if (_rsSuffix == sEnd)
rlm@1 50 {
rlm@1 51 return true;
rlm@1 52 }
rlm@1 53 }
rlm@1 54 else
rlm@1 55 {
rlm@1 56 if (_rsSuffix.lowercase() == sEnd.lowercase())
rlm@1 57 {
rlm@1 58 return true;
rlm@1 59 }
rlm@1 60 }
rlm@1 61
rlm@1 62 return false;
rlm@1 63 }
rlm@1 64
rlm@1 65 } // namespace VBA