2017-01-20 00:20:31 +00:00
|
|
|
// © 2016 and later: Unicode, Inc. and others.
|
2016-06-15 18:58:17 +00:00
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
2002-06-07 20:24:40 +00:00
|
|
|
/*
|
2005-03-08 22:49:59 +00:00
|
|
|
***********************************************************************
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (c) 2002-2007, International Business Machines Corporation
|
|
|
|
* and others. All Rights Reserved.
|
2005-03-08 22:49:59 +00:00
|
|
|
***********************************************************************
|
2002-06-07 20:24:40 +00:00
|
|
|
* Date Name Description
|
|
|
|
* 06/06/2002 aliu Creation.
|
2005-03-08 22:49:59 +00:00
|
|
|
***********************************************************************
|
2002-06-07 20:24:40 +00:00
|
|
|
*/
|
|
|
|
#ifndef _ANYTRANS_H_
|
|
|
|
#define _ANYTRANS_H_
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_TRANSLITERATION
|
|
|
|
|
2002-06-07 20:24:40 +00:00
|
|
|
#include "unicode/translit.h"
|
|
|
|
#include "unicode/uscript.h"
|
2002-06-11 22:36:11 +00:00
|
|
|
#include "uhash.h"
|
2002-06-07 20:24:40 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/**
|
2002-06-11 22:36:11 +00:00
|
|
|
* A transliterator named Any-T or Any-T/V, where T is the target
|
|
|
|
* script and V is the optional variant, that uses multiple
|
|
|
|
* transliterators, all going to T or T/V, all with script sources.
|
|
|
|
* The target must be a script. It partitions text into runs of the
|
|
|
|
* same script, and then based on the script of each run,
|
|
|
|
* transliterates from that script to the given target or
|
|
|
|
* target/variant. Adjacent COMMON or INHERITED script characters are
|
|
|
|
* included in each run.
|
2002-06-07 20:24:40 +00:00
|
|
|
*
|
|
|
|
* @author Alan Liu
|
|
|
|
*/
|
2007-06-03 06:08:46 +00:00
|
|
|
class AnyTransliterator : public Transliterator {
|
2002-06-07 20:24:40 +00:00
|
|
|
|
|
|
|
/**
|
2002-06-11 22:36:11 +00:00
|
|
|
* Cache mapping UScriptCode values to Transliterator*.
|
2002-06-07 20:24:40 +00:00
|
|
|
*/
|
2002-06-11 22:36:11 +00:00
|
|
|
UHashtable* cache;
|
2002-06-07 20:24:40 +00:00
|
|
|
|
|
|
|
/**
|
2002-06-11 22:36:11 +00:00
|
|
|
* The target or target/variant string.
|
2002-06-07 20:24:40 +00:00
|
|
|
*/
|
2002-06-11 22:36:11 +00:00
|
|
|
UnicodeString target;
|
2002-06-07 20:24:40 +00:00
|
|
|
|
|
|
|
/**
|
2002-06-11 22:36:11 +00:00
|
|
|
* The target script code. Never USCRIPT_INVALID_CODE.
|
2002-06-07 20:24:40 +00:00
|
|
|
*/
|
2002-06-11 22:36:11 +00:00
|
|
|
UScriptCode targetScript;
|
2002-06-07 20:24:40 +00:00
|
|
|
|
|
|
|
public:
|
2004-08-24 17:38:33 +00:00
|
|
|
|
2002-06-07 20:24:40 +00:00
|
|
|
/**
|
|
|
|
* Destructor.
|
|
|
|
*/
|
|
|
|
virtual ~AnyTransliterator();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy constructor.
|
|
|
|
*/
|
|
|
|
AnyTransliterator(const AnyTransliterator&);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transliterator API.
|
|
|
|
*/
|
2004-08-28 04:42:33 +00:00
|
|
|
virtual Transliterator* clone() const;
|
2002-06-07 20:24:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements {@link Transliterator#handleTransliterate}.
|
|
|
|
*/
|
|
|
|
virtual void handleTransliterate(Replaceable& text, UTransPosition& index,
|
|
|
|
UBool incremental) const;
|
2004-08-24 17:38:33 +00:00
|
|
|
|
2002-06-29 00:04:16 +00:00
|
|
|
/**
|
|
|
|
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
|
|
|
*/
|
2003-08-31 20:53:46 +00:00
|
|
|
virtual UClassID getDynamicClassID() const;
|
2002-06-29 00:04:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ICU "poor man's RTTI", returns a UClassID for this class.
|
|
|
|
*/
|
2007-06-03 06:08:46 +00:00
|
|
|
U_I18N_API static UClassID U_EXPORT2 getStaticClassID();
|
2002-06-29 00:04:16 +00:00
|
|
|
|
2002-06-07 20:24:40 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
2002-06-11 22:36:11 +00:00
|
|
|
* Private constructor
|
|
|
|
* @param id the ID of the form S-T or S-T/V, where T is theTarget
|
|
|
|
* and V is theVariant. Must not be empty.
|
|
|
|
* @param theTarget the target name. Must not be empty, and must
|
|
|
|
* name a script corresponding to theTargetScript.
|
|
|
|
* @param theVariant the variant name, or the empty string if
|
|
|
|
* there is no variant
|
|
|
|
* @param theTargetScript the script code corresponding to
|
|
|
|
* theTarget.
|
|
|
|
* @param ec error code, fails if the internal hashtable cannot be
|
|
|
|
* allocated
|
2002-06-07 20:24:40 +00:00
|
|
|
*/
|
2002-06-11 22:36:11 +00:00
|
|
|
AnyTransliterator(const UnicodeString& id,
|
|
|
|
const UnicodeString& theTarget,
|
|
|
|
const UnicodeString& theVariant,
|
|
|
|
UScriptCode theTargetScript,
|
|
|
|
UErrorCode& ec);
|
2002-06-07 20:24:40 +00:00
|
|
|
|
|
|
|
/**
|
2002-06-11 22:36:11 +00:00
|
|
|
* Returns a transliterator from the given source to our target or
|
|
|
|
* target/variant. Returns NULL if the source is the same as our
|
|
|
|
* target script, or if the source is USCRIPT_INVALID_CODE.
|
|
|
|
* Caches the result and returns the same transliterator the next
|
|
|
|
* time. The caller does NOT own the result and must not delete
|
|
|
|
* it.
|
2002-06-07 20:24:40 +00:00
|
|
|
*/
|
2002-06-11 22:36:11 +00:00
|
|
|
Transliterator* getTransliterator(UScriptCode source) const;
|
|
|
|
|
2002-06-07 20:24:40 +00:00
|
|
|
/**
|
2002-06-11 22:36:11 +00:00
|
|
|
* Registers standard transliterators with the system. Called by
|
2002-06-07 20:24:40 +00:00
|
|
|
* Transliterator during initialization.
|
|
|
|
*/
|
|
|
|
static void registerIDs();
|
|
|
|
|
|
|
|
friend class Transliterator; // for registerIDs()
|
|
|
|
};
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_TRANSLITERATION */
|
|
|
|
|
2002-06-07 20:24:40 +00:00
|
|
|
#endif
|