10596faeddefbf198de137d5e893708495ab1584cFredrik Roubert// © 2016 and later: Unicode, Inc. and others.
264339d36f8bd4db5025fe2988eda22b491a9219cFredrik Roubert// License & terms of use: http://www.unicode.org/copyright.html
3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru***********************************************************************
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Copyright (c) 2002-2007, International Business Machines Corporation
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* and others.  All Rights Reserved.
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru***********************************************************************
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Date        Name        Description
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 06/06/2002  aliu        Creation.
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru***********************************************************************
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef _ANYTRANS_H_
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define _ANYTRANS_H_
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h"
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_TRANSLITERATION
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/translit.h"
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uscript.h"
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "uhash.h"
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_BEGIN
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * A transliterator named Any-T or Any-T/V, where T is the target
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * script and V is the optional variant, that uses multiple
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * transliterators, all going to T or T/V, all with script sources.
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The target must be a script.  It partitions text into runs of the
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * same script, and then based on the script of each run,
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * transliterates from that script to the given target or
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * target/variant.  Adjacent COMMON or INHERITED script characters are
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * included in each run.
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @author Alan Liu
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass AnyTransliterator : public Transliterator {
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Cache mapping UScriptCode values to Transliterator*.
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UHashtable* cache;
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * The target or target/variant string.
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString target;
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * The target script code.  Never USCRIPT_INVALID_CODE.
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UScriptCode targetScript;
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic:
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Destructor.
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual ~AnyTransliterator();
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Copy constructor.
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    AnyTransliterator(const AnyTransliterator&);
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Transliterator API.
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual Transliterator* clone() const;
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Implements {@link Transliterator#handleTransliterate}.
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual void handleTransliterate(Replaceable& text, UTransPosition& index,
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                     UBool incremental) const;
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * ICU "poor man's RTTI", returns a UClassID for the actual class.
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual UClassID getDynamicClassID() const;
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * ICU "poor man's RTTI", returns a UClassID for this class.
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    U_I18N_API static UClassID U_EXPORT2 getStaticClassID();
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruprivate:
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Private constructor
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @param id the ID of the form S-T or S-T/V, where T is theTarget
92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * and V is theVariant.  Must not be empty.
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @param theTarget the target name.  Must not be empty, and must
94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * name a script corresponding to theTargetScript.
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @param theVariant the variant name, or the empty string if
96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * there is no variant
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @param theTargetScript the script code corresponding to
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * theTarget.
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @param ec error code, fails if the internal hashtable cannot be
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * allocated
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    AnyTransliterator(const UnicodeString& id,
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                      const UnicodeString& theTarget,
104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                      const UnicodeString& theVariant,
105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                      UScriptCode theTargetScript,
106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                      UErrorCode& ec);
107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Returns a transliterator from the given source to our target or
110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * target/variant.  Returns NULL if the source is the same as our
111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * target script, or if the source is USCRIPT_INVALID_CODE.
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Caches the result and returns the same transliterator the next
113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * time.  The caller does NOT own the result and must not delete
114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * it.
115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator* getTransliterator(UScriptCode source) const;
117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Registers standard transliterators with the system.  Called by
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Transliterator during initialization.
121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static void registerIDs();
123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    friend class Transliterator; // for registerIDs()
125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_END
128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_TRANSLITERATION */
130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
132