Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

[mb-commits] r7772 - in libmusicbrainz/branches/xmlws: include/musicbrainz3: msg#00380

audio.musicbrainz.cvs

Subject: [mb-commits] r7772 - in libmusicbrainz/branches/xmlws: include/musicbrainz3 src test

Author: luks
Date: 2006-05-31 18:53:04 +0000 (Wed, 31 May 2006)
New Revision: 7772

Added:
libmusicbrainz/branches/xmlws/src/utils_countrynames.h
libmusicbrainz/branches/xmlws/src/utils_languagenames.h
libmusicbrainz/branches/xmlws/src/utils_releasetypenames.h
libmusicbrainz/branches/xmlws/src/utils_scriptnames.h
Modified:
libmusicbrainz/branches/xmlws/include/musicbrainz3/utils.h
libmusicbrainz/branches/xmlws/src/Makefile.am
libmusicbrainz/branches/xmlws/src/utils.cpp
libmusicbrainz/branches/xmlws/test/test_utils.cpp
Log:
Implementation of Utils::get*Name + test cases for these functions.

Modified: libmusicbrainz/branches/xmlws/include/musicbrainz3/utils.h
===================================================================
--- libmusicbrainz/branches/xmlws/include/musicbrainz3/utils.h 2006-05-31
16:50:53 UTC (rev 7771)
+++ libmusicbrainz/branches/xmlws/include/musicbrainz3/utils.h 2006-05-31
18:53:04 UTC (rev 7772)
@@ -48,7 +48,63 @@
* URI. If \a uriStr is empty or a relative URI, then it is returned
* unchanged.
*/
- MB_API std::string extractUuid(const std::string &uriStr);
+ MB_API std::string extractUuid(const std::string &uriStr);
+
+ /**
+ * Returns a country's name based on an ISO-3166 country code.
+ *
+ * The country table this function is based on has been modified for
+ * MusicBrainz purposes by using the extension mechanism defined in
+ * ISO-3166. All IDs are still valid ISO-3166 country codes, but some
+ * IDs have been added to include historic countries and some of the
+ * country names have been modified to make them better suited for
+ * display purposes.
+ *
+ * If the country ID is not found, an empty string is returned. This may
+ * happen for example, when new countries are added to the MusicBrainz
web
+ * service which aren't known to this library yet.
+ *
+ * @param id a two-letter upper case string containing an ISO-3166 code
+ *
+ * @return: a string containing the country's name
+ */
+ MB_API std::string getCountryName(const std::string &id);
+
+ /**
+ * Returns a script name based on an ISO-15924 code.
+ *
+ * This function uses a subset of the ISO-15924 code table to map
+ * script IDs to names.
+ *
+ * @param id a four-letter string containing an ISO-15924 script code
+ *
+ * @return a string containing the script's name
+ */
+ MB_API std::string getScriptName(const std::string &id);
+
+ /**
+ * Returns a language name based on an ISO-639-2/T code.
+ *
+ * This function uses a subset of the ISO-639-2/T code table to map
+ * language IDs (terminologic, not bibliographic ones!) to names.
+ *
+ * @param id a three-letter upper case string containing an ISO-639-2/T
code
+ *
+ * @return a string containing the language's name
+ */
+ MB_API std::string getLanguageName(const std::string &id);
+
+ /**
+ * Returns the name of a release type URI.
+ *
+ * @param releaseType a string containing a release type URI
+ *
+ * @return a string containing a printable name for the release type
+ *
+ * @see Release
+ */
+ MB_API std::string getReleaseTypeName(const std::string &releaseType);
+
}

#endif

Modified: libmusicbrainz/branches/xmlws/src/Makefile.am
===================================================================
--- libmusicbrainz/branches/xmlws/src/Makefile.am 2006-05-31 16:50:53 UTC
(rev 7771)
+++ libmusicbrainz/branches/xmlws/src/Makefile.am 2006-05-31 18:53:04 UTC
(rev 7772)
@@ -29,7 +29,8 @@
artist.cpp artistalias.cpp disc.cpp entity.cpp filters.cpp \
includes.cpp mbxmlparser.cpp metadata.cpp relation.cpp release.cpp \
releaseevent.cpp results.cpp track.cpp user.cpp utils.cpp \
- webservice.cpp utilspriv.cpp query.cpp mb_c.cpp
+ webservice.cpp utilspriv.cpp query.cpp mb_c.cpp utils_countrynames.h \
+ utils_languagenames.h utils_releasetypenames.h utils_scriptnames.h

# Here are a set of rules to help you update your library version information:
# Scheme: current:revsion:age

Modified: libmusicbrainz/branches/xmlws/src/utils.cpp
===================================================================
--- libmusicbrainz/branches/xmlws/src/utils.cpp 2006-05-31 16:50:53 UTC (rev
7771)
+++ libmusicbrainz/branches/xmlws/src/utils.cpp 2006-05-31 18:53:04 UTC (rev
7772)
@@ -19,10 +19,13 @@
*
* $Id$
*/
-
+
+#include <string>
+#include <hash_map>
#include <musicbrainz3/utils.h>

using namespace std;
+using namespace stdext;
using namespace MusicBrainz;

std::string
@@ -57,3 +60,75 @@
throw ValueError(uri + "is not a valid MusicBrainz ID.");
}

+#include "utils_countrynames.h"
+
+string
+MusicBrainz::getCountryName(const string &id)
+{
+ static bool countryNamesMapBuilt = false;
+ static hash_map<string, string> countryNamesMap;
+
+ if (!countryNamesMapBuilt) {
+ for (int i = 0; i < (int)(sizeof(countryNames) /
sizeof(countryNames[0])); i++)
+ countryNamesMap[countryNames[i][0]] =
countryNames[i][1];
+ countryNamesMapBuilt = true;
+ }
+
+ hash_map<string, string>::iterator i = countryNamesMap.find(id);
+ return i == countryNamesMap.end() ? string() : i->second;
+}
+
+#include "utils_languagenames.h"
+
+string
+MusicBrainz::getLanguageName(const string &id)
+{
+ static bool languageNamesMapBuilt = false;
+ static hash_map<string, string> languageNamesMap;
+
+ if (!languageNamesMapBuilt) {
+ for (int i = 0; i < (int)(sizeof(languageNames) /
sizeof(languageNames[0])); i++)
+ languageNamesMap[languageNames[i][0]] =
languageNames[i][1];
+ languageNamesMapBuilt = true;
+ }
+
+ hash_map<string, string>::iterator i = languageNamesMap.find(id);
+ return i == languageNamesMap.end() ? string() : i->second;
+}
+
+#include "utils_scriptnames.h"
+
+string
+MusicBrainz::getScriptName(const string &id)
+{
+ static bool scriptNamesMapBuilt = false;
+ static hash_map<string, string> scriptNamesMap;
+
+ if (!scriptNamesMapBuilt) {
+ for (int i = 0; i < (int)(sizeof(scriptNames) /
sizeof(scriptNames[0])); i++)
+ scriptNamesMap[scriptNames[i][0]] = scriptNames[i][1];
+ scriptNamesMapBuilt = true;
+ }
+
+ hash_map<string, string>::iterator i = scriptNamesMap.find(id);
+ return i == scriptNamesMap.end() ? string() : i->second;
+}
+
+#include "utils_releasetypenames.h"
+
+string
+MusicBrainz::getReleaseTypeName(const string &id)
+{
+ static bool releaseTypeNamesMapBuilt = false;
+ static hash_map<string, string> releaseTypeNamesMap;
+
+ if (!releaseTypeNamesMapBuilt) {
+ for (int i = 0; i < (int)(sizeof(releaseTypeNames) /
sizeof(releaseTypeNames[0])); i++)
+ releaseTypeNamesMap[releaseTypeNames[i][0]] =
releaseTypeNames[i][1];
+ releaseTypeNamesMapBuilt = true;
+ }
+
+ hash_map<string, string>::iterator i = releaseTypeNamesMap.find(id);
+ return i == releaseTypeNamesMap.end() ? string() : i->second;
+}
+

Added: libmusicbrainz/branches/xmlws/src/utils_countrynames.h


Property changes on: libmusicbrainz/branches/xmlws/src/utils_countrynames.h
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native

Added: libmusicbrainz/branches/xmlws/src/utils_languagenames.h


Property changes on: libmusicbrainz/branches/xmlws/src/utils_languagenames.h
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native

Added: libmusicbrainz/branches/xmlws/src/utils_releasetypenames.h


Property changes on: libmusicbrainz/branches/xmlws/src/utils_releasetypenames.h
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native

Added: libmusicbrainz/branches/xmlws/src/utils_scriptnames.h


Property changes on: libmusicbrainz/branches/xmlws/src/utils_scriptnames.h
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native

Modified: libmusicbrainz/branches/xmlws/test/test_utils.cpp
===================================================================
--- libmusicbrainz/branches/xmlws/test/test_utils.cpp 2006-05-31 16:50:53 UTC
(rev 7771)
+++ libmusicbrainz/branches/xmlws/test/test_utils.cpp 2006-05-31 18:53:04 UTC
(rev 7772)
@@ -1,5 +1,6 @@
#include <string>
#include <cppunit/extensions/HelperMacros.h>
+#include <musicbrainz3/model.h>
#include <musicbrainz3/utils.h>

using namespace std;
@@ -9,6 +10,11 @@
{
CPPUNIT_TEST_SUITE(UtilsTest);
CPPUNIT_TEST(testExtractUuid);
+ CPPUNIT_TEST(testExtractFragment);
+ CPPUNIT_TEST(testGetCountryName);
+ CPPUNIT_TEST(testGetLanguageName);
+ CPPUNIT_TEST(testGetScriptName);
+ CPPUNIT_TEST(testGetReleaseTypeName);
CPPUNIT_TEST_SUITE_END();

protected:
@@ -22,6 +28,43 @@
CPPUNIT_ASSERT_EQUAL(uuid, extractUuid(uuid));
CPPUNIT_ASSERT_EQUAL(uuid, extractUuid(mbid));
}
+
+ void testExtractFragment()
+ {
+ string fragment = "Album";
+ string uri = NS_MMD_1 + fragment;
+ CPPUNIT_ASSERT_EQUAL(string(), extractFragment(string()));
+ CPPUNIT_ASSERT_EQUAL(fragment, extractFragment(fragment));
+ CPPUNIT_ASSERT_EQUAL(fragment, extractFragment(uri));
+ }
+
+ void testGetCountryName()
+ {
+ CPPUNIT_ASSERT_EQUAL(string(), getCountryName("00"));
+ CPPUNIT_ASSERT_EQUAL(string("Slovakia"), getCountryName("SK"));
+ CPPUNIT_ASSERT_EQUAL(string("Czechoslovakia (historical,
1918-1992)"), getCountryName("XC"));
+ }
+
+ void testGetLanguageName()
+ {
+ CPPUNIT_ASSERT_EQUAL(string(), getLanguageName("000"));
+ CPPUNIT_ASSERT_EQUAL(string("Slovak"), getLanguageName("SLK"));
+ CPPUNIT_ASSERT_EQUAL(string("Czech"), getLanguageName("CES"));
+ }
+
+ void testGetScriptName()
+ {
+ CPPUNIT_ASSERT_EQUAL(string(), getScriptName("-"));
+ CPPUNIT_ASSERT_EQUAL(string("Latin"), getScriptName("Latn"));
+ CPPUNIT_ASSERT_EQUAL(string("Cyrillic"), getScriptName("Cyrl"));
+ }
+
+ void testGetReleaseTypeName()
+ {
+ CPPUNIT_ASSERT_EQUAL(string(), getReleaseTypeName("-"));
+ CPPUNIT_ASSERT_EQUAL(string("Album"),
getReleaseTypeName(Release::TYPE_ALBUM));
+ CPPUNIT_ASSERT_EQUAL(string("Compilation"),
getReleaseTypeName(Release::TYPE_COMPILATION));
+ }
};

CPPUNIT_TEST_SUITE_REGISTRATION(UtilsTest);


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
user-groups.jax...    php.zend.framew...    os.solaris.open...    web.quixote.use...    java.openjdk.ho...    ietf.secmech/20...    gnu.glpk/2004-0...    recreation.cars...    network.smokepi...    linux.drivers.i...    cms.opencms.dev...    fonts.gfontview...    text.xml.soap.u...    voip.nist-sip/2...    debian.ports.hp...    xfree86.interna...    science.biology...    qnx.openqnx.dev...    mail.sylpheed.c...    busybox/bios/20...    emulators.kvm.s...    hardware.openco...    apple.fink.begi...    kde.german/2006...   
Home | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation