lib/icu: migrate from class Error to C++ exceptions

This commit is contained in:
Max Kellermann 2016-11-02 09:54:13 +01:00
parent e9c2885f34
commit 6d409d27ca
8 changed files with 23 additions and 88 deletions

View File

@ -508,8 +508,7 @@ libevent_a_SOURCES = \
libicu_a_SOURCES = \
src/lib/icu/Collate.cxx src/lib/icu/Collate.hxx \
src/lib/icu/Converter.cxx src/lib/icu/Converter.hxx \
src/lib/icu/Error.cxx src/lib/icu/Error.hxx
src/lib/icu/Converter.cxx src/lib/icu/Converter.hxx
if HAVE_ICU
libicu_a_SOURCES += \

View File

@ -400,10 +400,7 @@ try {
#endif
#endif
if (!IcuInit(error)) {
LogError(error);
return EXIT_FAILURE;
}
IcuInit();
winsock_init();
io_thread_init();

View File

@ -23,10 +23,9 @@
#ifdef HAVE_ICU
#include "Util.hxx"
#include "Error.hxx"
#include "util/AllocatedArray.hxx"
#include "util/ConstBuffer.hxx"
#include "util/Error.hxx"
#include "util/RuntimeError.hxx"
#include <unicode/ucol.h>
#include <unicode/ustring.h>
@ -53,21 +52,16 @@ static UCollator *collator;
#ifdef HAVE_ICU
bool
IcuCollateInit(Error &error)
void
IcuCollateInit()
{
assert(collator == nullptr);
assert(!error.IsDefined());
UErrorCode code = U_ZERO_ERROR;
collator = ucol_open("", &code);
if (collator == nullptr) {
error.Format(icu_domain, int(code),
"ucol_open() failed: %s", u_errorName(code));
return false;
}
return true;
if (collator == nullptr)
throw FormatRuntimeError("ucol_open() failed: %s",
u_errorName(code));
}
void

View File

@ -26,8 +26,11 @@
class Error;
template<typename T> class AllocatedString;
bool
IcuCollateInit(Error &error);
/**
* Throws #std::runtime_error on error.
*/
void
IcuCollateInit();
void
IcuCollateFinish();

View File

@ -1,24 +0,0 @@
/*
* Copyright 2003-2016 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "Error.hxx"
#include "util/Domain.hxx"
const Domain icu_domain("icu");

View File

@ -1,29 +0,0 @@
/*
* Copyright 2003-2016 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_ICU_ERROR_HXX
#define MPD_ICU_ERROR_HXX
#include "check.h"
class Domain;
extern const Domain icu_domain;
#endif

View File

@ -19,24 +19,21 @@
#include "config.h"
#include "Init.hxx"
#include "Error.hxx"
#include "Collate.hxx"
#include "util/Error.hxx"
#include "util/RuntimeError.hxx"
#include <unicode/uclean.h>
bool
IcuInit(Error &error)
void
IcuInit()
{
UErrorCode code = U_ZERO_ERROR;
u_init(&code);
if (U_FAILURE(code)) {
error.Format(icu_domain, int(code),
"u_init() failed: %s", u_errorName(code));
return false;
}
if (U_FAILURE(code))
throw FormatRuntimeError("u_init() failed: %s",
u_errorName(code));
return IcuCollateInit(error);
IcuCollateInit();
}
void

View File

@ -22,19 +22,17 @@
#include "check.h"
class Error;
#ifdef HAVE_ICU
bool
IcuInit(Error &error);
void
IcuInit();
void
IcuFinish();
#else
static inline bool IcuInit(Error &) { return true; }
static inline void IcuInit() {}
static inline void IcuFinish() {}
#endif