Avoid using String::null where an empty string is required.

String::null is not necessarily be empty or remains the same instance.
Using it in a public header may lead to a linkage error.
This commit is contained in:
Tsuda Kageyu 2015-11-20 22:21:47 +09:00
parent c4fe65787c
commit 8c6fe45453
29 changed files with 106 additions and 105 deletions

View File

@ -210,7 +210,7 @@ String APE::Item::toString() const
if(d->type == Text && !isEmpty())
return d->text.front();
else
return String::null;
return String();
}
bool APE::Item::isEmpty() const

View File

@ -91,35 +91,35 @@ ByteVector APE::Tag::fileIdentifier()
String APE::Tag::title() const
{
if(d->itemListMap["TITLE"].isEmpty())
return String::null;
return String();
return d->itemListMap["TITLE"].values().toString();
}
String APE::Tag::artist() const
{
if(d->itemListMap["ARTIST"].isEmpty())
return String::null;
return String();
return d->itemListMap["ARTIST"].values().toString();
}
String APE::Tag::album() const
{
if(d->itemListMap["ALBUM"].isEmpty())
return String::null;
return String();
return d->itemListMap["ALBUM"].values().toString();
}
String APE::Tag::comment() const
{
if(d->itemListMap["COMMENT"].isEmpty())
return String::null;
return String();
return d->itemListMap["COMMENT"].values().toString();
}
String APE::Tag::genre() const
{
if(d->itemListMap["GENRE"].isEmpty())
return String::null;
return String();
return d->itemListMap["GENRE"].values().toString();
}

View File

@ -64,7 +64,7 @@ String ASF::Tag::album() const
{
if(d->attributeListMap.contains("WM/AlbumTitle"))
return d->attributeListMap["WM/AlbumTitle"][0].toString();
return String::null;
return String();
}
String ASF::Tag::copyright() const
@ -107,7 +107,7 @@ String ASF::Tag::genre() const
{
if(d->attributeListMap.contains("WM/Genre"))
return d->attributeListMap["WM/Genre"][0].toString();
return String::null;
return String();
}
void ASF::Tag::setTitle(const String &value)
@ -329,16 +329,16 @@ PropertyMap ASF::Tag::setProperties(const PropertyMap &props)
for(; it != origProps.end(); ++it) {
if(!props.contains(it->first) || props[it->first].isEmpty()) {
if(it->first == "TITLE") {
d->title = String::null;
d->title.clear();
}
else if(it->first == "ARTIST") {
d->artist = String::null;
d->artist.clear();
}
else if(it->first == "COMMENT") {
d->comment = String::null;
d->comment.clear();
}
else if(it->first == "COPYRIGHT") {
d->copyright = String::null;
d->copyright.clear();
}
else {
d->attributeListMap.erase(reverseKeyMap[it->first]);

View File

@ -118,7 +118,7 @@ bool IT::File::save()
if(i < lines.size())
writeString(lines[i], 25);
else
writeString(String::null, 25);
writeString(String(), 25);
writeByte(0);
}
@ -133,7 +133,7 @@ bool IT::File::save()
if((TagLib::uint)(i + instrumentCount) < lines.size())
writeString(lines[i + instrumentCount], 25);
else
writeString(String::null, 25);
writeString(String(), 25);
writeByte(0);
}

View File

@ -99,7 +99,7 @@ bool Mod::File::save()
}
for(uint i = n; i < d->properties.instrumentCount(); ++ i) {
writeString(String::null, 22);
writeString(String(), 22);
seek(8, Current);
}
return true;

View File

@ -55,12 +55,12 @@ String Mod::Tag::title() const
String Mod::Tag::artist() const
{
return String::null;
return String();
}
String Mod::Tag::album() const
{
return String::null;
return String();
}
String Mod::Tag::comment() const
@ -70,7 +70,7 @@ String Mod::Tag::comment() const
String Mod::Tag::genre() const
{
return String::null;
return String();
}
TagLib::uint Mod::Tag::year() const
@ -142,19 +142,19 @@ PropertyMap Mod::Tag::setProperties(const PropertyMap &origProps)
d->title = properties["TITLE"].front();
oneValueSet.append("TITLE");
} else
d->title = String::null;
d->title.clear();
if(properties.contains("COMMENT")) {
d->comment = properties["COMMENT"].front();
oneValueSet.append("COMMENT");
} else
d->comment = String::null;
d->comment.clear();
if(properties.contains("TRACKERNAME")) {
d->trackerName = properties["TRACKERNAME"].front();
oneValueSet.append("TRACKERNAME");
} else
d->trackerName = String::null;
d->trackerName.clear();
// for each tag that has been set above, remove the first entry in the corresponding
// value list. The others will be returned as unsupported by this format.

View File

@ -686,7 +686,7 @@ MP4::Tag::title() const
{
if(d->items.contains("\251nam"))
return d->items["\251nam"].toStringList().toString(", ");
return String::null;
return String();
}
String
@ -694,7 +694,7 @@ MP4::Tag::artist() const
{
if(d->items.contains("\251ART"))
return d->items["\251ART"].toStringList().toString(", ");
return String::null;
return String();
}
String
@ -702,7 +702,7 @@ MP4::Tag::album() const
{
if(d->items.contains("\251alb"))
return d->items["\251alb"].toStringList().toString(", ");
return String::null;
return String();
}
String
@ -710,7 +710,7 @@ MP4::Tag::comment() const
{
if(d->items.contains("\251cmt"))
return d->items["\251cmt"].toStringList().toString(", ");
return String::null;
return String();
}
String
@ -718,7 +718,7 @@ MP4::Tag::genre() const
{
if(d->items.contains("\251gen"))
return d->items["\251gen"].toStringList().toString(", ");
return String::null;
return String();
}
unsigned int

View File

@ -184,7 +184,7 @@ void ID3v1::Tag::setGenre(const String &s)
void ID3v1::Tag::setYear(TagLib::uint i)
{
d->year = i > 0 ? String::number(i) : String::null;
d->year = i > 0 ? String::number(i) : String();
}
void ID3v1::Tag::setTrack(TagLib::uint i)

View File

@ -214,7 +214,7 @@ void TableOfContentsFrame::removeEmbeddedFrames(const ByteVector &id)
String TableOfContentsFrame::toString() const
{
return String::null;
return String();
}
PropertyMap TableOfContentsFrame::asProperties() const

View File

@ -312,8 +312,8 @@ UserTextIdentificationFrame::UserTextIdentificationFrame(String::Type encoding)
d(0)
{
StringList l;
l.append(String::null);
l.append(String::null);
l.append(String());
l.append(String());
setText(l);
}
@ -341,7 +341,7 @@ String UserTextIdentificationFrame::description() const
{
return !TextIdentificationFrame::fieldList().isEmpty()
? TextIdentificationFrame::fieldList().front()
: String::null;
: String();
}
StringList UserTextIdentificationFrame::fieldList() const
@ -354,7 +354,7 @@ StringList UserTextIdentificationFrame::fieldList() const
void UserTextIdentificationFrame::setText(const String &text)
{
if(description().isEmpty())
setDescription(String::null);
setDescription(String());
TextIdentificationFrame::setText(StringList(description()).append(text));
}
@ -362,7 +362,7 @@ void UserTextIdentificationFrame::setText(const String &text)
void UserTextIdentificationFrame::setText(const StringList &fields)
{
if(description().isEmpty())
setDescription(String::null);
setDescription(String());
TextIdentificationFrame::setText(StringList(description()).append(fields));
}
@ -417,7 +417,7 @@ void UserTextIdentificationFrame::checkFields()
int fields = fieldList().size();
if(fields == 0)
setDescription(String::null);
setDescription(String());
if(fields <= 1)
setText(String::null);
setText(String());
}

View File

@ -86,7 +86,7 @@ void UniqueFileIdentifierFrame::setIdentifier(const ByteVector &v)
String UniqueFileIdentifierFrame::toString() const
{
return String::null;
return String();
}
PropertyMap UniqueFileIdentifierFrame::asProperties() const

View File

@ -51,7 +51,7 @@ UnknownFrame::~UnknownFrame()
String UnknownFrame::toString() const
{
return String::null;
return String();
}
ByteVector UnknownFrame::data() const

View File

@ -317,7 +317,7 @@ String Frame::readStringField(const ByteVector &data, String::Type encoding, int
int end = data.find(delimiter, *position, delimiter.size());
if(end < *position)
return String::null;
return String();
String str;
if(encoding == String::Latin1)

View File

@ -516,7 +516,7 @@ void FrameFactory::updateGenre(TextIdentificationFrame *frame) const
}
if(newfields.isEmpty())
fields.append(String::null);
fields.append(String());
frame->setText(newfields);

View File

@ -140,21 +140,21 @@ String ID3v2::Tag::title() const
{
if(!d->frameListMap["TIT2"].isEmpty())
return d->frameListMap["TIT2"].front()->toString();
return String::null;
return String();
}
String ID3v2::Tag::artist() const
{
if(!d->frameListMap["TPE1"].isEmpty())
return d->frameListMap["TPE1"].front()->toString();
return String::null;
return String();
}
String ID3v2::Tag::album() const
{
if(!d->frameListMap["TALB"].isEmpty())
return d->frameListMap["TALB"].front()->toString();
return String::null;
return String();
}
String ID3v2::Tag::comment() const
@ -162,7 +162,7 @@ String ID3v2::Tag::comment() const
const FrameList &comments = d->frameListMap["COMM"];
if(comments.isEmpty())
return String::null;
return String();
for(FrameList::ConstIterator it = comments.begin(); it != comments.end(); ++it)
{
@ -184,7 +184,7 @@ String ID3v2::Tag::genre() const
if(d->frameListMap["TCON"].isEmpty() ||
!dynamic_cast<TextIdentificationFrame *>(d->frameListMap["TCON"].front()))
{
return String::null;
return String();
}
// ID3v2.4 lists genres as the fields in its frames field list. If the field

View File

@ -62,21 +62,21 @@ Ogg::XiphComment::~XiphComment()
String Ogg::XiphComment::title() const
{
if(d->fieldListMap["TITLE"].isEmpty())
return String::null;
return String();
return d->fieldListMap["TITLE"].toString();
}
String Ogg::XiphComment::artist() const
{
if(d->fieldListMap["ARTIST"].isEmpty())
return String::null;
return String();
return d->fieldListMap["ARTIST"].toString();
}
String Ogg::XiphComment::album() const
{
if(d->fieldListMap["ALBUM"].isEmpty())
return String::null;
return String();
return d->fieldListMap["ALBUM"].toString();
}
@ -92,13 +92,13 @@ String Ogg::XiphComment::comment() const
return d->fieldListMap["COMMENT"].toString();
}
return String::null;
return String();
}
String Ogg::XiphComment::genre() const
{
if(d->fieldListMap["GENRE"].isEmpty())
return String::null;
return String();
return d->fieldListMap["GENRE"].toString();
}

View File

@ -134,7 +134,7 @@ bool S3M::File::save()
if(i < lines.size())
writeString(lines[i], 27);
else
writeString(String::null, 27);
writeString(String(), 27);
// string terminating NUL is not optional:
writeByte(0);
}

View File

@ -89,31 +89,31 @@ PropertyMap Tag::setProperties(const PropertyMap &origProps)
setTitle(properties["TITLE"].front());
oneValueSet.append("TITLE");
} else
setTitle(String::null);
setTitle(String());
if(properties.contains("ARTIST")) {
setArtist(properties["ARTIST"].front());
oneValueSet.append("ARTIST");
} else
setArtist(String::null);
setArtist(String());
if(properties.contains("ALBUM")) {
setAlbum(properties["ALBUM"].front());
oneValueSet.append("ALBUM");
} else
setAlbum(String::null);
setAlbum(String());
if(properties.contains("COMMENT")) {
setComment(properties["COMMENT"].front());
oneValueSet.append("COMMENT");
} else
setComment(String::null);
setComment(String());
if(properties.contains("GENRE")) {
setGenre(properties["GENRE"].front());
oneValueSet.append("GENRE");
} else
setGenre(String::null);
setGenre(String());
if(properties.contains("DATE")) {
bool ok;

View File

@ -42,7 +42,7 @@ using namespace TagLib;
return tag(1)->method(); \
if(tag(2) && !tag(2)->method().isEmpty()) \
return tag(2)->method(); \
return String::null \
return String(); \
#define numberUnion(method) \
if(tag(0) && tag(0)->method() > 0) \

View File

@ -33,10 +33,10 @@ using namespace TagLib;
# include "tdebug.h"
# include <windows.h>
namespace
namespace
{
// Check if the running system has CreateFileW() function.
// Windows9x systems don't have CreateFileW() or can't accept Unicode file names.
// Windows9x systems don't have CreateFileW() or can't accept Unicode file names.
bool supportsUnicode()
{
@ -49,11 +49,11 @@ namespace
}
// Indicates whether the system supports Unicode file names.
const bool SystemSupportsUnicode = supportsUnicode();
const bool SystemSupportsUnicode = supportsUnicode();
// Converts a UTF-16 string into a local encoding.
// This function should only be used in Windows9x systems which don't support
// This function should only be used in Windows9x systems which don't support
// Unicode file names.
std::string unicodeToAnsi(const wchar_t *wstr)
@ -76,52 +76,52 @@ namespace
// If WinNT, stores a Unicode string into m_wname directly.
// If Win9x, converts and stores it into m_name to avoid calling Unicode version functions.
FileName::FileName(const wchar_t *name)
FileName::FileName(const wchar_t *name)
: m_name (SystemSupportsUnicode ? "" : unicodeToAnsi(name))
, m_wname(SystemSupportsUnicode ? name : L"")
{
}
FileName::FileName(const char *name)
: m_name(name)
FileName::FileName(const char *name)
: m_name(name)
{
}
FileName::FileName(const FileName &name)
: m_name (name.m_name)
FileName::FileName(const FileName &name)
: m_name (name.m_name)
, m_wname(name.m_wname)
{
}
FileName::operator const wchar_t *() const
{
return m_wname.c_str();
FileName::operator const wchar_t *() const
{
return m_wname.c_str();
}
FileName::operator const char *() const
{
return m_name.c_str();
FileName::operator const char *() const
{
return m_name.c_str();
}
const std::wstring &FileName::wstr() const
{
return m_wname;
const std::wstring &FileName::wstr() const
{
return m_wname;
}
const std::string &FileName::str() const
{
return m_name;
}
const std::string &FileName::str() const
{
return m_name;
}
String FileName::toString() const
{
if(!m_wname.empty()) {
return String(m_wname);
}
}
else if(!m_name.empty()) {
const int len = MultiByteToWideChar(CP_ACP, 0, m_name.c_str(), -1, NULL, 0);
if(len == 0)
return String::null;
return String();
std::vector<wchar_t> buf(len);
MultiByteToWideChar(CP_ACP, 0, m_name.c_str(), -1, &buf[0], len);
@ -129,7 +129,7 @@ String FileName::toString() const
return String(&buf[0]);
}
else {
return String::null;
return String();
}
}

View File

@ -144,7 +144,8 @@ bool PropertyMap::operator!=(const PropertyMap &other) const
String PropertyMap::toString() const
{
String ret = "";
String ret;
for(ConstIterator it = begin(); it != end(); ++it)
ret += it->first+"="+it->second.toString(", ") + "\n";
if(!unsupported.isEmpty())

View File

@ -449,7 +449,7 @@ bool XM::File::save()
seek(pos + 4);
const uint len = std::min(22UL, instrumentHeaderSize - 4U);
if(i >= lines.size())
writeString(String::null, len);
writeString(String(), len);
else
writeString(lines[i], len);
@ -480,7 +480,7 @@ bool XM::File::save()
seek(pos + 18);
const uint len = std::min(sampleHeaderSize - 18U, 22UL);
if(sampleNameIndex >= lines.size())
writeString(String::null, len);
writeString(String(), len);
else
writeString(lines[sampleNameIndex ++], len);
}

View File

@ -108,7 +108,7 @@ public:
ByteVector data("Test Data");
item.setBinaryData(data);
CPPUNIT_ASSERT(item.values().isEmpty());
CPPUNIT_ASSERT_EQUAL(String::null, item.toString());
CPPUNIT_ASSERT_EQUAL(String(), item.toString());
CPPUNIT_ASSERT_EQUAL(data, item.binaryData());
item.setValue("Test Text 2");

View File

@ -36,7 +36,7 @@ class PublicFrame : public ID3v2::Frame
String readStringField(const ByteVector &data, String::Type encoding,
int *positon = 0)
{ return ID3v2::Frame::readStringField(data, encoding, positon); }
virtual String toString() const { return String::null; }
virtual String toString() const { return String(); }
virtual void parseFields(const ByteVector &) {}
virtual ByteVector renderFields() const { return ByteVector(); }
};

View File

@ -123,10 +123,10 @@ private:
CPPUNIT_ASSERT_EQUAL((TagLib::uchar)128, p->panningSeparation());
CPPUNIT_ASSERT_EQUAL((TagLib::uchar) 0, p->pitchWheelDepth());
CPPUNIT_ASSERT_EQUAL(title, t->title());
CPPUNIT_ASSERT_EQUAL(String::null, t->artist());
CPPUNIT_ASSERT_EQUAL(String::null, t->album());
CPPUNIT_ASSERT_EQUAL(String(), t->artist());
CPPUNIT_ASSERT_EQUAL(String(), t->album());
CPPUNIT_ASSERT_EQUAL(comment, t->comment());
CPPUNIT_ASSERT_EQUAL(String::null, t->genre());
CPPUNIT_ASSERT_EQUAL(String(), t->genre());
CPPUNIT_ASSERT_EQUAL(0U, t->year());
CPPUNIT_ASSERT_EQUAL(0U, t->track());
CPPUNIT_ASSERT_EQUAL(String("Impulse Tracker"), t->trackerName());

View File

@ -113,10 +113,10 @@ private:
CPPUNIT_ASSERT_EQUAL(31U, p->instrumentCount());
CPPUNIT_ASSERT_EQUAL((uchar)1, p->lengthInPatterns());
CPPUNIT_ASSERT_EQUAL(title, t->title());
CPPUNIT_ASSERT_EQUAL(String::null, t->artist());
CPPUNIT_ASSERT_EQUAL(String::null, t->album());
CPPUNIT_ASSERT_EQUAL(String(), t->artist());
CPPUNIT_ASSERT_EQUAL(String(), t->album());
CPPUNIT_ASSERT_EQUAL(comment, t->comment());
CPPUNIT_ASSERT_EQUAL(String::null, t->genre());
CPPUNIT_ASSERT_EQUAL(String(), t->genre());
CPPUNIT_ASSERT_EQUAL(0U, t->year());
CPPUNIT_ASSERT_EQUAL(0U, t->track());
CPPUNIT_ASSERT_EQUAL(String("StarTrekker"), t->trackerName());

View File

@ -110,10 +110,10 @@ private:
CPPUNIT_ASSERT_EQUAL((TagLib::uchar)125, p->tempo());
CPPUNIT_ASSERT_EQUAL((TagLib::uchar) 6, p->bpmSpeed());
CPPUNIT_ASSERT_EQUAL(title, t->title());
CPPUNIT_ASSERT_EQUAL(String::null, t->artist());
CPPUNIT_ASSERT_EQUAL(String::null, t->album());
CPPUNIT_ASSERT_EQUAL(String(), t->artist());
CPPUNIT_ASSERT_EQUAL(String(), t->album());
CPPUNIT_ASSERT_EQUAL(comment, t->comment());
CPPUNIT_ASSERT_EQUAL(String::null, t->genre());
CPPUNIT_ASSERT_EQUAL(String(), t->genre());
CPPUNIT_ASSERT_EQUAL(0U, t->year());
CPPUNIT_ASSERT_EQUAL(0U, t->track());
CPPUNIT_ASSERT_EQUAL(String("ScreamTracker III"), t->trackerName());

View File

@ -69,7 +69,7 @@ public:
s.clear();
CPPUNIT_ASSERT(s.isEmpty());
CPPUNIT_ASSERT(!s.isNull());
CPPUNIT_ASSERT(!s.isNull()); // deprecated, but still worth it to check.
String unicode("José Carlos", String::UTF8);
CPPUNIT_ASSERT(strcmp(unicode.toCString(), "Jos\xe9 Carlos") == 0);

View File

@ -139,13 +139,13 @@ public:
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 6, p->tempo());
CPPUNIT_ASSERT_EQUAL((TagLib::ushort)125, p->bpmSpeed());
CPPUNIT_ASSERT_EQUAL(titleBefore, t->title());
CPPUNIT_ASSERT_EQUAL(String::null, t->artist());
CPPUNIT_ASSERT_EQUAL(String::null, t->album());
CPPUNIT_ASSERT_EQUAL(String::null, t->comment());
CPPUNIT_ASSERT_EQUAL(String::null, t->genre());
CPPUNIT_ASSERT_EQUAL(String(), t->artist());
CPPUNIT_ASSERT_EQUAL(String(), t->album());
CPPUNIT_ASSERT_EQUAL(String(), t->comment());
CPPUNIT_ASSERT_EQUAL(String(), t->genre());
CPPUNIT_ASSERT_EQUAL(0U, t->year());
CPPUNIT_ASSERT_EQUAL(0U, t->track());
CPPUNIT_ASSERT_EQUAL(String::null, t->trackerName());
CPPUNIT_ASSERT_EQUAL(String(), t->trackerName());
}
void testWriteTagsShort()
@ -185,10 +185,10 @@ private:
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 6, p->tempo());
CPPUNIT_ASSERT_EQUAL((TagLib::ushort)125, p->bpmSpeed());
CPPUNIT_ASSERT_EQUAL(title, t->title());
CPPUNIT_ASSERT_EQUAL(String::null, t->artist());
CPPUNIT_ASSERT_EQUAL(String::null, t->album());
CPPUNIT_ASSERT_EQUAL(String(), t->artist());
CPPUNIT_ASSERT_EQUAL(String(), t->album());
CPPUNIT_ASSERT_EQUAL(comment, t->comment());
CPPUNIT_ASSERT_EQUAL(String::null, t->genre());
CPPUNIT_ASSERT_EQUAL(String(), t->genre());
CPPUNIT_ASSERT_EQUAL(0U, t->year());
CPPUNIT_ASSERT_EQUAL(0U, t->track());
CPPUNIT_ASSERT_EQUAL(trackerName, t->trackerName());