ICU-4078 use USetAdder interface to remove dependencies of low-level code on the USet/UnicodeSet implementation
X-SVN-Rev: 16266
This commit is contained in:
parent
8a3a93deed
commit
3ba67ae1c2
@ -24,19 +24,45 @@ U_NAMESPACE_BEGIN
|
||||
|
||||
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(NameUnicodeTransliterator)
|
||||
|
||||
static const char CURR_ID[] = "Name-Any";
|
||||
|
||||
static const UChar OPEN[] = {92,78,126,123,126,0}; // "\N~{~"
|
||||
static const UChar OPEN_DELIM = 92; // '\\' first char of OPEN
|
||||
static const UChar CLOSE_DELIM = 125; // '}'
|
||||
static const UChar SPACE = 32; // ' '
|
||||
|
||||
// USetAdder implementation
|
||||
// Does not use uset.h to reduce code dependencies
|
||||
static void U_CALLCONV
|
||||
_set_add(USet *set, UChar32 c) {
|
||||
((UnicodeSet *)set)->add(c);
|
||||
}
|
||||
|
||||
static void U_CALLCONV
|
||||
_set_addRange(USet *set, UChar32 start, UChar32 end) {
|
||||
((UnicodeSet *)set)->add(start, end);
|
||||
}
|
||||
|
||||
static void U_CALLCONV
|
||||
_set_addString(USet *set, const UChar *str, int32_t length) {
|
||||
((UnicodeSet *)set)->add(UnicodeString((UBool)(length<0), str, length));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a transliterator with the default delimiters '{' and
|
||||
* '}'.
|
||||
*/
|
||||
NameUnicodeTransliterator::NameUnicodeTransliterator(UnicodeFilter* adoptedFilter) :
|
||||
Transliterator(UnicodeString(CURR_ID, ""), adoptedFilter) {
|
||||
Transliterator(UNICODE_STRING("Name-Any", 8), adoptedFilter) {
|
||||
|
||||
// Get the legal character set
|
||||
UnicodeSet legal;
|
||||
USetAdder sa = {
|
||||
(USet *)&legal, // USet* == UnicodeSet*
|
||||
_set_add,
|
||||
_set_addRange,
|
||||
_set_addString
|
||||
};
|
||||
uprv_getCharNameCharacters(&sa);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,7 +74,7 @@ NameUnicodeTransliterator::~NameUnicodeTransliterator() {}
|
||||
* Copy constructor.
|
||||
*/
|
||||
NameUnicodeTransliterator::NameUnicodeTransliterator(const NameUnicodeTransliterator& o) :
|
||||
Transliterator(o) {}
|
||||
Transliterator(o), legal(o.legal) {}
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
@ -56,6 +82,7 @@ NameUnicodeTransliterator::NameUnicodeTransliterator(const NameUnicodeTransliter
|
||||
NameUnicodeTransliterator& NameUnicodeTransliterator::operator=(
|
||||
const NameUnicodeTransliterator& o) {
|
||||
Transliterator::operator=(o);
|
||||
// not necessary: the legal sets should all be the same -- legal=o.legal;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -92,10 +119,6 @@ void NameUnicodeTransliterator::handleTransliterate(Replaceable& text, UTransPos
|
||||
UnicodeString openPat(TRUE, OPEN, -1);
|
||||
UnicodeString str, name;
|
||||
|
||||
// Get the legal character set
|
||||
UnicodeSet legal;
|
||||
uprv_getCharNameCharacters((USet*) &legal); // USet* == UnicodeSet*
|
||||
|
||||
int32_t cursor = offsets.start;
|
||||
int32_t limit = offsets.limit;
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
#if !UCONFIG_NO_TRANSLITERATION
|
||||
|
||||
#include "unicode/translit.h"
|
||||
#include "unicode/uniset.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
@ -81,6 +82,10 @@ public:
|
||||
virtual void handleTransliterate(Replaceable& text, UTransPosition& offset,
|
||||
UBool isIncremental) const;
|
||||
|
||||
/**
|
||||
* Set of characters which occur in Unicode character names.
|
||||
*/
|
||||
UnicodeSet legal;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "cintltst.h"
|
||||
#include "uparse.h"
|
||||
#include "uprops.h"
|
||||
#include "uset_imp.h"
|
||||
#include "usc_impl.h"
|
||||
#include "unormimp.h"
|
||||
#include "cucdapi.h"
|
||||
@ -1644,7 +1645,16 @@ TestCharNames() {
|
||||
* it includes all the characters in lowercased names of
|
||||
* general categories, for the full possible set of extended names.
|
||||
*/
|
||||
uprv_getCharNameCharacters(set);
|
||||
{
|
||||
USetAdder sa={
|
||||
NULL,
|
||||
uset_add,
|
||||
uset_addRange,
|
||||
uset_addString
|
||||
};
|
||||
sa.set=set;
|
||||
uprv_getCharNameCharacters(&sa);
|
||||
}
|
||||
|
||||
/* build set the dumb (but sure-fire) way */
|
||||
for (i=0; i<256; ++i) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 1997-2003, International Business Machines Corporation and
|
||||
* Copyright (c) 1997-2004, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
|
||||
@ -1671,6 +1671,23 @@ initExpectedSkippables(UnicodeSet skipSets[UNORM_MODE_COUNT]) {
|
||||
"D6A8-\\U0001D7C9\\U0001D7CE-\\U0001D7FF\\U0002F800-\\U0002FA1D]", ""), errorCode);
|
||||
}
|
||||
|
||||
// USetAdder implementation
|
||||
// Does not use uset.h to reduce code dependencies
|
||||
static void U_CALLCONV
|
||||
_set_add(USet *set, UChar32 c) {
|
||||
((UnicodeSet *)set)->add(c);
|
||||
}
|
||||
|
||||
static void U_CALLCONV
|
||||
_set_addRange(USet *set, UChar32 start, UChar32 end) {
|
||||
((UnicodeSet *)set)->add(start, end);
|
||||
}
|
||||
|
||||
static void U_CALLCONV
|
||||
_set_addString(USet *set, const UChar *str, int32_t length) {
|
||||
((UnicodeSet *)set)->add(UnicodeString((UBool)(length<0), str, length));
|
||||
}
|
||||
|
||||
void
|
||||
BasicNormalizerTest::TestSkippable() {
|
||||
UnicodeSet starts, diff, skipSets[UNORM_MODE_COUNT], expectSets[UNORM_MODE_COUNT];
|
||||
@ -1682,7 +1699,13 @@ BasicNormalizerTest::TestSkippable() {
|
||||
|
||||
/* build NF*Skippable sets from runtime data */
|
||||
status=U_ZERO_ERROR;
|
||||
unorm_addPropertyStarts((USet *)&starts, &status);
|
||||
USetAdder sa = {
|
||||
(USet *)&starts,
|
||||
_set_add,
|
||||
_set_addRange,
|
||||
_set_addString
|
||||
};
|
||||
unorm_addPropertyStarts(&sa, &status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("unable to load normalization data for unorm_addPropertyStarts(() - %s\n", u_errorName(status));
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user