1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
/* --------------------------------------------------------------------------
flactag -- A tagger for single album FLAC files with embedded CUE sheets
using data retrieved from the MusicBrainz service
Copyright (C) 2006-2008 Andrew Hawkins
This file is part of flactag.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Flactag is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id$
----------------------------------------------------------------------------*/
#include "TagName.h"
#include <stdlib.h>
#include <sstream>
CTagName::CTagName(const std::string& Name, int Number)
: m_Name(Name),
m_Number(Number)
{
}
CTagName::CTagName(const std::string& Name)
: m_Name(Name),
m_Number(-1)
{
std::string::size_type OpenPos=Name.find("[");
if (std::string::npos!=OpenPos)
{
std::string::size_type ClosePos=Name.find("]",OpenPos);
if (std::string::npos!=ClosePos)
{
std::string NumberStr=Name.substr(OpenPos+1,ClosePos-OpenPos-1);
m_Number=atoi(NumberStr.c_str());
m_Name=Name.substr(0,OpenPos);
}
}
}
bool CTagName::operator <(const CTagName& Other) const
{
//return String()<Other.String();
bool RetVal=false;
if (!SpecialTag() && Other.SpecialTag())
RetVal=true;
else if (SpecialTag()==Other.SpecialTag() && m_Number<Other.m_Number)
RetVal=true;
else if (SpecialTag()==Other.SpecialTag() && m_Number==Other.m_Number && m_Name=="TRACKNUMBER" && Other.m_Name!="TRACKNUMBER")
RetVal=true;
else if (SpecialTag()==Other.SpecialTag() && m_Number==Other.m_Number && m_Name!="TRACKNUMBER" && Other.m_Name=="TRACKNUMBER")
RetVal=false;
else if (SpecialTag()==Other.SpecialTag() && m_Number==Other.m_Number && m_Name!="TRACKNUMBER" && Other.m_Name!="TRACKNUMBER" && m_Name<Other.m_Name)
RetVal=true;
return RetVal;
}
bool CTagName::operator >(const CTagName& Other) const
{
bool RetVal=!(*this<Other) && !(*this==Other);
return RetVal;
}
bool CTagName::operator ==(const CTagName& Other) const
{
bool RetVal=(m_Name==Other.m_Name && m_Number==Other.m_Number);
return RetVal;
}
bool CTagName::operator !=(const CTagName& Other) const
{
return !(*this==Other);
}
std::string CTagName::Name() const
{
return m_Name;
}
int CTagName::Number() const
{
return m_Number;
}
bool CTagName::SpecialTag() const
{
bool RetVal=(std::string::npos!=m_Name.find("REPLAYGAIN") ||
std::string::npos!=m_Name.find("DISCID"));
return RetVal;
}
std::string CTagName::String() const
{
std::stringstream os;
if (m_Number==-1)
os << m_Name;
else
os << m_Name << "[" << m_Number <<"]";
return os.str();
}
|