lib/icu: migrate from class Error to C++ exceptions
This commit is contained in:
parent
e9c2885f34
commit
6d409d27ca
@ -508,8 +508,7 @@ libevent_a_SOURCES = \
|
|||||||
|
|
||||||
libicu_a_SOURCES = \
|
libicu_a_SOURCES = \
|
||||||
src/lib/icu/Collate.cxx src/lib/icu/Collate.hxx \
|
src/lib/icu/Collate.cxx src/lib/icu/Collate.hxx \
|
||||||
src/lib/icu/Converter.cxx src/lib/icu/Converter.hxx \
|
src/lib/icu/Converter.cxx src/lib/icu/Converter.hxx
|
||||||
src/lib/icu/Error.cxx src/lib/icu/Error.hxx
|
|
||||||
|
|
||||||
if HAVE_ICU
|
if HAVE_ICU
|
||||||
libicu_a_SOURCES += \
|
libicu_a_SOURCES += \
|
||||||
|
@ -400,10 +400,7 @@ try {
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!IcuInit(error)) {
|
IcuInit();
|
||||||
LogError(error);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
winsock_init();
|
winsock_init();
|
||||||
io_thread_init();
|
io_thread_init();
|
||||||
|
@ -23,10 +23,9 @@
|
|||||||
|
|
||||||
#ifdef HAVE_ICU
|
#ifdef HAVE_ICU
|
||||||
#include "Util.hxx"
|
#include "Util.hxx"
|
||||||
#include "Error.hxx"
|
|
||||||
#include "util/AllocatedArray.hxx"
|
#include "util/AllocatedArray.hxx"
|
||||||
#include "util/ConstBuffer.hxx"
|
#include "util/ConstBuffer.hxx"
|
||||||
#include "util/Error.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
|
|
||||||
#include <unicode/ucol.h>
|
#include <unicode/ucol.h>
|
||||||
#include <unicode/ustring.h>
|
#include <unicode/ustring.h>
|
||||||
@ -53,21 +52,16 @@ static UCollator *collator;
|
|||||||
|
|
||||||
#ifdef HAVE_ICU
|
#ifdef HAVE_ICU
|
||||||
|
|
||||||
bool
|
void
|
||||||
IcuCollateInit(Error &error)
|
IcuCollateInit()
|
||||||
{
|
{
|
||||||
assert(collator == nullptr);
|
assert(collator == nullptr);
|
||||||
assert(!error.IsDefined());
|
|
||||||
|
|
||||||
UErrorCode code = U_ZERO_ERROR;
|
UErrorCode code = U_ZERO_ERROR;
|
||||||
collator = ucol_open("", &code);
|
collator = ucol_open("", &code);
|
||||||
if (collator == nullptr) {
|
if (collator == nullptr)
|
||||||
error.Format(icu_domain, int(code),
|
throw FormatRuntimeError("ucol_open() failed: %s",
|
||||||
"ucol_open() failed: %s", u_errorName(code));
|
u_errorName(code));
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -26,8 +26,11 @@
|
|||||||
class Error;
|
class Error;
|
||||||
template<typename T> class AllocatedString;
|
template<typename T> class AllocatedString;
|
||||||
|
|
||||||
bool
|
/**
|
||||||
IcuCollateInit(Error &error);
|
* Throws #std::runtime_error on error.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
IcuCollateInit();
|
||||||
|
|
||||||
void
|
void
|
||||||
IcuCollateFinish();
|
IcuCollateFinish();
|
||||||
|
@ -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");
|
|
@ -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
|
|
@ -19,24 +19,21 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "Init.hxx"
|
#include "Init.hxx"
|
||||||
#include "Error.hxx"
|
|
||||||
#include "Collate.hxx"
|
#include "Collate.hxx"
|
||||||
#include "util/Error.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
|
|
||||||
#include <unicode/uclean.h>
|
#include <unicode/uclean.h>
|
||||||
|
|
||||||
bool
|
void
|
||||||
IcuInit(Error &error)
|
IcuInit()
|
||||||
{
|
{
|
||||||
UErrorCode code = U_ZERO_ERROR;
|
UErrorCode code = U_ZERO_ERROR;
|
||||||
u_init(&code);
|
u_init(&code);
|
||||||
if (U_FAILURE(code)) {
|
if (U_FAILURE(code))
|
||||||
error.Format(icu_domain, int(code),
|
throw FormatRuntimeError("u_init() failed: %s",
|
||||||
"u_init() failed: %s", u_errorName(code));
|
u_errorName(code));
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return IcuCollateInit(error);
|
IcuCollateInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -22,19 +22,17 @@
|
|||||||
|
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
class Error;
|
|
||||||
|
|
||||||
#ifdef HAVE_ICU
|
#ifdef HAVE_ICU
|
||||||
|
|
||||||
bool
|
void
|
||||||
IcuInit(Error &error);
|
IcuInit();
|
||||||
|
|
||||||
void
|
void
|
||||||
IcuFinish();
|
IcuFinish();
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static inline bool IcuInit(Error &) { return true; }
|
static inline void IcuInit() {}
|
||||||
static inline void IcuFinish() {}
|
static inline void IcuFinish() {}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user