2 **********************************************************************
3 * Copyright (c) 2002-2014, International Business Machines Corporation
4 * and others. All Rights Reserved.
5 **********************************************************************
6 * Date Name Description
7 * 01/14/2002 aliu Creation.
8 **********************************************************************
11 #include "unicode/utypes.h"
13 #if !UCONFIG_NO_TRANSLITERATION
21 #include "unicode/parsepos.h"
22 #include "unicode/translit.h"
23 #include "unicode/uchar.h"
24 #include "unicode/uniset.h"
25 #include "unicode/unistr.h"
26 #include "unicode/utrans.h"
32 static const UChar ID_DELIM
= 0x003B; // ;
33 static const UChar TARGET_SEP
= 0x002D; // -
34 static const UChar VARIANT_SEP
= 0x002F; // /
35 static const UChar OPEN_REV
= 0x0028; // (
36 static const UChar CLOSE_REV
= 0x0029; // )
38 //static const UChar EMPTY[] = {0}; // ""
39 static const UChar ANY
[] = {65,110,121,0}; // "Any"
40 static const UChar ANY_NULL
[] = {65,110,121,45,78,117,108,108,0}; // "Any-Null"
42 static const int32_t FORWARD
= UTRANS_FORWARD
;
43 static const int32_t REVERSE
= UTRANS_REVERSE
;
45 static Hashtable
* SPECIAL_INVERSES
= NULL
;
46 static UInitOnce gSpecialInversesInitOnce
= U_INITONCE_INITIALIZER
;
49 * The mutex controlling access to SPECIAL_INVERSES
51 static UMutex LOCK
= U_MUTEX_INITIALIZER
;
53 TransliteratorIDParser::Specs::Specs(const UnicodeString
& s
, const UnicodeString
& t
,
54 const UnicodeString
& v
, UBool sawS
,
55 const UnicodeString
& f
) {
63 TransliteratorIDParser::SingleID::SingleID(const UnicodeString
& c
, const UnicodeString
& b
,
64 const UnicodeString
& f
) {
70 TransliteratorIDParser::SingleID::SingleID(const UnicodeString
& c
, const UnicodeString
& b
) {
75 Transliterator
* TransliteratorIDParser::SingleID::createInstance() {
77 if (basicID
.length() == 0) {
78 t
= createBasicInstance(UnicodeString(TRUE
, ANY_NULL
, 8), &canonID
);
80 t
= createBasicInstance(basicID
, &canonID
);
83 if (filter
.length() != 0) {
84 UErrorCode ec
= U_ZERO_ERROR
;
85 UnicodeSet
*set
= new UnicodeSet(filter
, ec
);
98 * Parse a single ID, that is, an ID of the general form
99 * "[f1] s1-t1/v1 ([f2] s2-t3/v2)", with the parenthesized element
100 * optional, the filters optional, and the variants optional.
101 * @param id the id to be parsed
102 * @param pos INPUT-OUTPUT parameter. On input, the position of
103 * the first character to parse. On output, the position after
104 * the last character parsed.
105 * @param dir the direction. If the direction is REVERSE then the
106 * SingleID is constructed for the reverse direction.
107 * @return a SingleID object or NULL
109 TransliteratorIDParser::SingleID
*
110 TransliteratorIDParser::parseSingleID(const UnicodeString
& id
, int32_t& pos
,
111 int32_t dir
, UErrorCode
& status
) {
115 // The ID will be of the form A, A(), A(B), or (B), where
116 // A and B are filter IDs.
117 Specs
* specsA
= NULL
;
118 Specs
* specsB
= NULL
;
119 UBool sawParen
= FALSE
;
121 // On the first pass, look for (B) or (). If this fails, then
122 // on the second pass, look for A, A(B), or A().
123 for (int32_t pass
=1; pass
<=2; ++pass
) {
125 specsA
= parseFilterID(id
, pos
, TRUE
);
126 if (specsA
== NULL
) {
131 if (ICU_Utility::parseChar(id
, pos
, OPEN_REV
)) {
133 if (!ICU_Utility::parseChar(id
, pos
, CLOSE_REV
)) {
134 specsB
= parseFilterID(id
, pos
, TRUE
);
135 // Must close with a ')'
136 if (specsB
== NULL
|| !ICU_Utility::parseChar(id
, pos
, CLOSE_REV
)) {
146 // Assemble return results
149 if (dir
== FORWARD
) {
150 SingleID
* b
= specsToID(specsB
, FORWARD
);
151 single
= specsToID(specsA
, FORWARD
);
152 // Null pointers check
153 if (b
== NULL
|| single
== NULL
) {
156 status
= U_MEMORY_ALLOCATION_ERROR
;
159 single
->canonID
.append(OPEN_REV
)
160 .append(b
->canonID
).append(CLOSE_REV
);
161 if (specsA
!= NULL
) {
162 single
->filter
= specsA
->filter
;
166 SingleID
* a
= specsToID(specsA
, FORWARD
);
167 single
= specsToID(specsB
, FORWARD
);
168 // Check for null pointer.
169 if (a
== NULL
|| single
== NULL
) {
172 status
= U_MEMORY_ALLOCATION_ERROR
;
175 single
->canonID
.append(OPEN_REV
)
176 .append(a
->canonID
).append(CLOSE_REV
);
177 if (specsB
!= NULL
) {
178 single
->filter
= specsB
->filter
;
183 // assert(specsA != NULL);
184 if (dir
== FORWARD
) {
185 single
= specsToID(specsA
, FORWARD
);
187 single
= specsToSpecialInverse(*specsA
, status
);
188 if (single
== NULL
) {
189 single
= specsToID(specsA
, REVERSE
);
192 // Check for NULL pointer
193 if (single
== NULL
) {
194 status
= U_MEMORY_ALLOCATION_ERROR
;
197 single
->filter
= specsA
->filter
;
207 * Parse a filter ID, that is, an ID of the general form
208 * "[f1] s1-t1/v1", with the filters optional, and the variants optional.
209 * @param id the id to be parsed
210 * @param pos INPUT-OUTPUT parameter. On input, the position of
211 * the first character to parse. On output, the position after
212 * the last character parsed.
213 * @return a SingleID object or null if the parse fails
215 TransliteratorIDParser::SingleID
*
216 TransliteratorIDParser::parseFilterID(const UnicodeString
& id
, int32_t& pos
) {
220 Specs
* specs
= parseFilterID(id
, pos
, TRUE
);
226 // Assemble return results
227 SingleID
* single
= specsToID(specs
, FORWARD
);
228 if (single
!= NULL
) {
229 single
->filter
= specs
->filter
;
236 * Parse a global filter of the form "[f]" or "([f])", depending
238 * @param id the pattern the parse
239 * @param pos INPUT-OUTPUT parameter. On input, the position of
240 * the first character to parse. On output, the position after
241 * the last character parsed.
242 * @param dir the direction.
243 * @param withParens INPUT-OUTPUT parameter. On entry, if
244 * withParens is 0, then parens are disallowed. If it is 1,
245 * then parens are requires. If it is -1, then parens are
246 * optional, and the return result will be set to 0 or 1.
247 * @param canonID OUTPUT parameter. The pattern for the filter
248 * added to the canonID, either at the end, if dir is FORWARD, or
249 * at the start, if dir is REVERSE. The pattern will be enclosed
250 * in parentheses if appropriate, and will be suffixed with an
251 * ID_DELIM character. May be NULL.
252 * @return a UnicodeSet object or NULL. A non-NULL results
253 * indicates a successful parse, regardless of whether the filter
254 * applies to the given direction. The caller should discard it
255 * if withParens != (dir == REVERSE).
257 UnicodeSet
* TransliteratorIDParser::parseGlobalFilter(const UnicodeString
& id
, int32_t& pos
,
260 UnicodeString
* canonID
) {
261 UnicodeSet
* filter
= NULL
;
264 if (withParens
== -1) {
265 withParens
= ICU_Utility::parseChar(id
, pos
, OPEN_REV
) ? 1 : 0;
266 } else if (withParens
== 1) {
267 if (!ICU_Utility::parseChar(id
, pos
, OPEN_REV
)) {
273 ICU_Utility::skipWhitespace(id
, pos
, TRUE
);
275 if (UnicodeSet::resemblesPattern(id
, pos
)) {
276 ParsePosition
ppos(pos
);
277 UErrorCode ec
= U_ZERO_ERROR
;
278 filter
= new UnicodeSet(id
, ppos
, USET_IGNORE_SPACE
, NULL
, ec
);
290 UnicodeString pattern
;
291 id
.extractBetween(pos
, ppos
.getIndex(), pattern
);
292 pos
= ppos
.getIndex();
294 if (withParens
== 1 && !ICU_Utility::parseChar(id
, pos
, CLOSE_REV
)) {
299 // In the forward direction, append the pattern to the
300 // canonID. In the reverse, insert it at zero, and invert
301 // the presence of parens ("A" <-> "(A)").
302 if (canonID
!= NULL
) {
303 if (dir
== FORWARD
) {
304 if (withParens
== 1) {
305 pattern
.insert(0, OPEN_REV
);
306 pattern
.append(CLOSE_REV
);
308 canonID
->append(pattern
).append(ID_DELIM
);
310 if (withParens
== 0) {
311 pattern
.insert(0, OPEN_REV
);
312 pattern
.append(CLOSE_REV
);
314 canonID
->insert(0, pattern
);
315 canonID
->insert(pattern
.length(), ID_DELIM
);
324 static void U_CALLCONV
_deleteSingleID(void* obj
) {
325 delete (TransliteratorIDParser::SingleID
*) obj
;
328 static void U_CALLCONV
_deleteTransliteratorTrIDPars(void* obj
) {
329 delete (Transliterator
*) obj
;
334 * Parse a compound ID, consisting of an optional forward global
335 * filter, a separator, one or more single IDs delimited by
336 * separators, an an optional reverse global filter. The
337 * separator is a semicolon. The global filters are UnicodeSet
338 * patterns. The reverse global filter must be enclosed in
340 * @param id the pattern the parse
341 * @param dir the direction.
342 * @param canonID OUTPUT parameter that receives the canonical ID,
343 * consisting of canonical IDs for all elements, as returned by
344 * parseSingleID(), separated by semicolons. Previous contents
346 * @param list OUTPUT parameter that receives a list of SingleID
347 * objects representing the parsed IDs. Previous contents are
349 * @param globalFilter OUTPUT parameter that receives a pointer to
350 * a newly created global filter for this ID in this direction, or
351 * NULL if there is none.
352 * @return TRUE if the parse succeeds, that is, if the entire
353 * id is consumed without syntax error.
355 UBool
TransliteratorIDParser::parseCompoundID(const UnicodeString
& id
, int32_t dir
,
356 UnicodeString
& canonID
,
358 UnicodeSet
*& globalFilter
) {
359 UErrorCode ec
= U_ZERO_ERROR
;
362 int32_t withParens
= 1;
363 list
.removeAllElements();
368 // Parse leading global filter, if any
369 withParens
= 0; // parens disallowed
370 filter
= parseGlobalFilter(id
, pos
, dir
, withParens
, &canonID
);
371 if (filter
!= NULL
) {
372 if (!ICU_Utility::parseChar(id
, pos
, ID_DELIM
)) {
373 // Not a global filter; backup and resume
377 if (dir
== FORWARD
) {
378 globalFilter
= filter
;
385 UBool sawDelimiter
= TRUE
;
387 SingleID
* single
= parseSingleID(id
, pos
, dir
, ec
);
388 if (single
== NULL
) {
391 if (dir
== FORWARD
) {
392 list
.addElement(single
, ec
);
394 list
.insertElementAt(single
, 0, ec
);
399 if (!ICU_Utility::parseChar(id
, pos
, ID_DELIM
)) {
400 sawDelimiter
= FALSE
;
405 if (list
.size() == 0) {
409 // Construct canonical ID
410 for (i
=0; i
<list
.size(); ++i
) {
411 SingleID
* single
= (SingleID
*) list
.elementAt(i
);
412 canonID
.append(single
->canonID
);
413 if (i
!= (list
.size()-1)) {
414 canonID
.append(ID_DELIM
);
418 // Parse trailing global filter, if any, and only if we saw
419 // a trailing delimiter after the IDs.
421 withParens
= 1; // parens required
422 filter
= parseGlobalFilter(id
, pos
, dir
, withParens
, &canonID
);
423 if (filter
!= NULL
) {
424 // Don't require trailing ';', but parse it if present
425 ICU_Utility::parseChar(id
, pos
, ID_DELIM
);
427 if (dir
== REVERSE
) {
428 globalFilter
= filter
;
436 // Trailing unparsed text is a syntax error
437 ICU_Utility::skipWhitespace(id
, pos
, TRUE
);
438 if (pos
!= id
.length()) {
445 UObjectDeleter
*save
= list
.setDeleter(_deleteSingleID
);
446 list
.removeAllElements();
447 list
.setDeleter(save
);
454 * Convert the elements of the 'list' vector, which are SingleID
455 * objects, into actual Transliterator objects. In the course of
456 * this, some (or all) entries may be removed. If all entries
457 * are removed, the NULL transliterator will be added.
459 * Delete entries with empty basicIDs; these are generated by
460 * elements like "(A)" in the forward direction, or "A()" in
461 * the reverse. THIS MAY RESULT IN AN EMPTY VECTOR. Convert
462 * SingleID entries to actual transliterators.
464 * @param list vector of SingleID objects. On exit, vector
465 * of one or more Transliterators.
466 * @return new value of insertIndex. The index will shift if
467 * there are empty items, like "(Lower)", with indices less than
470 void TransliteratorIDParser::instantiateList(UVector
& list
,
476 tlist
.setDeleter(_deleteTransliteratorTrIDPars
);
480 for (i
=0; i
<=list
.size(); ++i
) { // [sic]: i<=list.size()
481 // We run the loop too long by one, so we can
482 // do an insert after the last element
483 if (i
==list
.size()) {
487 SingleID
* single
= (SingleID
*) list
.elementAt(i
);
488 if (single
->basicID
.length() != 0) {
489 t
= single
->createInstance();
494 tlist
.addElement(t
, ec
);
502 // An empty list is equivalent to a NULL transliterator.
503 if (tlist
.size() == 0) {
504 t
= createBasicInstance(UnicodeString(TRUE
, ANY_NULL
, 8), NULL
);
506 // Should never happen
507 ec
= U_INTERNAL_TRANSLITERATOR_ERROR
;
509 tlist
.addElement(t
, ec
);
517 UObjectDeleter
*save
= list
.setDeleter(_deleteSingleID
);
518 list
.removeAllElements();
521 list
.setDeleter(_deleteTransliteratorTrIDPars
);
523 while (tlist
.size() > 0) {
524 t
= (Transliterator
*) tlist
.orphanElementAt(0);
525 list
.addElement(t
, ec
);
528 list
.removeAllElements();
534 list
.setDeleter(save
);
538 * Parse an ID into pieces. Take IDs of the form T, T/V, S-T,
539 * S-T/V, or S/V-T. If the source is missing, return a source of
541 * @param id the id string, in any of several forms
542 * @return an array of 4 strings: source, target, variant, and
543 * isSourcePresent. If the source is not present, ANY will be
544 * given as the source, and isSourcePresent will be NULL. Otherwise
545 * isSourcePresent will be non-NULL. The target may be empty if the
546 * id is not well-formed. The variant may be empty.
548 void TransliteratorIDParser::IDtoSTV(const UnicodeString
& id
,
549 UnicodeString
& source
,
550 UnicodeString
& target
,
551 UnicodeString
& variant
,
552 UBool
& isSourcePresent
) {
553 source
.setTo(ANY
, 3);
557 int32_t sep
= id
.indexOf(TARGET_SEP
);
558 int32_t var
= id
.indexOf(VARIANT_SEP
);
562 isSourcePresent
= FALSE
;
565 // Form: T/V or T (or /V)
566 id
.extractBetween(0, var
, target
);
567 id
.extractBetween(var
, id
.length(), variant
);
568 } else if (sep
< var
) {
569 // Form: S-T/V or S-T (or -T/V or -T)
571 id
.extractBetween(0, sep
, source
);
572 isSourcePresent
= TRUE
;
574 id
.extractBetween(++sep
, var
, target
);
575 id
.extractBetween(var
, id
.length(), variant
);
577 // Form: (S/V-T or /V-T)
579 id
.extractBetween(0, var
, source
);
580 isSourcePresent
= TRUE
;
582 id
.extractBetween(var
, sep
++, variant
);
583 id
.extractBetween(sep
, id
.length(), target
);
586 if (variant
.length() > 0) {
587 variant
.remove(0, 1);
592 * Given source, target, and variant strings, concatenate them into a
593 * full ID. If the source is empty, then "Any" will be used for the
594 * source, so the ID will always be of the form s-t/v or s-t.
596 void TransliteratorIDParser::STVtoID(const UnicodeString
& source
,
597 const UnicodeString
& target
,
598 const UnicodeString
& variant
,
601 if (id
.length() == 0) {
604 id
.append(TARGET_SEP
).append(target
);
605 if (variant
.length() != 0) {
606 id
.append(VARIANT_SEP
).append(variant
);
608 // NUL-terminate the ID string for getTerminatedBuffer.
609 // This prevents valgrind and Purify warnings.
611 id
.truncate(id
.length()-1);
615 * Register two targets as being inverses of one another. For
616 * example, calling registerSpecialInverse("NFC", "NFD", TRUE) causes
617 * Transliterator to form the following inverse relationships:
622 * Any-NFD => Any-NFC</pre>
624 * (Without the special inverse registration, the inverse of NFC
625 * would be NFC-Any.) Note that NFD is shorthand for Any-NFD, but
626 * that the presence or absence of "Any-" is preserved.
628 * <p>The relationship is symmetrical; registering (a, b) is
629 * equivalent to registering (b, a).
631 * <p>The relevant IDs must still be registered separately as
632 * factories or classes.
634 * <p>Only the targets are specified. Special inverses always
635 * have the form Any-Target1 <=> Any-Target2. The target should
636 * have canonical casing (the casing desired to be produced when
637 * an inverse is formed) and should contain no whitespace or other
638 * extraneous characters.
640 * @param target the target against which to register the inverse
641 * @param inverseTarget the inverse of target, that is
642 * Any-target.getInverse() => Any-inverseTarget
643 * @param bidirectional if TRUE, register the reverse relation
644 * as well, that is, Any-inverseTarget.getInverse() => Any-target
646 void TransliteratorIDParser::registerSpecialInverse(const UnicodeString
& target
,
647 const UnicodeString
& inverseTarget
,
649 UErrorCode
&status
) {
650 umtx_initOnce(gSpecialInversesInitOnce
, init
, status
);
651 if (U_FAILURE(status
)) {
655 // If target == inverseTarget then force bidirectional => FALSE
656 if (bidirectional
&& 0==target
.caseCompare(inverseTarget
, U_FOLD_CASE_DEFAULT
)) {
657 bidirectional
= FALSE
;
662 UnicodeString
*tempus
= new UnicodeString(inverseTarget
); // Used for null pointer check before usage.
663 if (tempus
== NULL
) {
664 status
= U_MEMORY_ALLOCATION_ERROR
;
667 SPECIAL_INVERSES
->put(target
, tempus
, status
);
669 tempus
= new UnicodeString(target
);
670 if (tempus
== NULL
) {
671 status
= U_MEMORY_ALLOCATION_ERROR
;
674 SPECIAL_INVERSES
->put(inverseTarget
, tempus
, status
);
678 //----------------------------------------------------------------
679 // Private implementation
680 //----------------------------------------------------------------
683 * Parse an ID into component pieces. Take IDs of the form T,
684 * T/V, S-T, S-T/V, or S/V-T. If the source is missing, return a
686 * @param id the id string, in any of several forms
687 * @param pos INPUT-OUTPUT parameter. On input, pos is the
688 * offset of the first character to parse in id. On output,
689 * pos is the offset after the last parsed character. If the
690 * parse failed, pos will be unchanged.
691 * @param allowFilter2 if TRUE, a UnicodeSet pattern is allowed
692 * at any location between specs or delimiters, and is returned
693 * as the fifth string in the array.
694 * @return a Specs object, or NULL if the parse failed. If
695 * neither source nor target was seen in the parsed id, then the
696 * parse fails. If allowFilter is TRUE, then the parsed filter
697 * pattern is returned in the Specs object, otherwise the returned
698 * filter reference is NULL. If the parse fails for any reason
701 TransliteratorIDParser::Specs
*
702 TransliteratorIDParser::parseFilterID(const UnicodeString
& id
, int32_t& pos
,
705 UnicodeString source
;
706 UnicodeString target
;
707 UnicodeString variant
;
708 UnicodeString filter
;
710 int32_t specCount
= 0;
713 // This loop parses one of the following things with each
714 // pass: a filter, a delimiter character (either '-' or '/'),
715 // or a spec (source, target, or variant).
717 ICU_Utility::skipWhitespace(id
, pos
, TRUE
);
718 if (pos
== id
.length()) {
723 if (allowFilter
&& filter
.length() == 0 &&
724 UnicodeSet::resemblesPattern(id
, pos
)) {
726 ParsePosition
ppos(pos
);
727 UErrorCode ec
= U_ZERO_ERROR
;
728 UnicodeSet
set(id
, ppos
, USET_IGNORE_SPACE
, NULL
, ec
);
733 id
.extractBetween(pos
, ppos
.getIndex(), filter
);
734 pos
= ppos
.getIndex();
738 if (delimiter
== 0) {
739 UChar c
= id
.charAt(pos
);
740 if ((c
== TARGET_SEP
&& target
.length() == 0) ||
741 (c
== VARIANT_SEP
&& variant
.length() == 0)) {
748 // We are about to try to parse a spec with no delimiter
749 // when we can no longer do so (we can only do so at the
751 if (delimiter
== 0 && specCount
> 0) {
755 UnicodeString spec
= ICU_Utility::parseUnicodeIdentifier(id
, pos
);
756 if (spec
.length() == 0) {
757 // Note that if there was a trailing delimiter, we
758 // consume it. So Foo-, Foo/, Foo-Bar/, and Foo/Bar-
778 // A spec with no prior character is either source or target,
779 // depending on whether an explicit "-target" was seen.
780 if (first
.length() != 0) {
781 if (target
.length() == 0) {
788 // Must have either source or target
789 if (source
.length() == 0 && target
.length() == 0) {
794 // Empty source or target defaults to ANY
795 UBool sawSource
= TRUE
;
796 if (source
.length() == 0) {
797 source
.setTo(ANY
, 3);
800 if (target
.length() == 0) {
801 target
.setTo(ANY
, 3);
804 return new Specs(source
, target
, variant
, sawSource
, filter
);
808 * Givens a Spec object, convert it to a SingleID object. The
809 * Spec object is a more unprocessed parse result. The SingleID
810 * object contains information about canonical and basic IDs.
811 * @return a SingleID; never returns NULL. Returned object always
812 * has 'filter' field of NULL.
814 TransliteratorIDParser::SingleID
*
815 TransliteratorIDParser::specsToID(const Specs
* specs
, int32_t dir
) {
816 UnicodeString canonID
;
817 UnicodeString basicID
;
818 UnicodeString basicPrefix
;
821 if (dir
== FORWARD
) {
822 if (specs
->sawSource
) {
823 buf
.append(specs
->source
).append(TARGET_SEP
);
825 basicPrefix
= specs
->source
;
826 basicPrefix
.append(TARGET_SEP
);
828 buf
.append(specs
->target
);
830 buf
.append(specs
->target
).append(TARGET_SEP
).append(specs
->source
);
832 if (specs
->variant
.length() != 0) {
833 buf
.append(VARIANT_SEP
).append(specs
->variant
);
835 basicID
= basicPrefix
;
837 if (specs
->filter
.length() != 0) {
838 buf
.insert(0, specs
->filter
);
842 return new SingleID(canonID
, basicID
);
846 * Given a Specs object, return a SingleID representing the
847 * special inverse of that ID. If there is no special inverse
849 * @return a SingleID or NULL. Returned object always has
850 * 'filter' field of NULL.
852 TransliteratorIDParser::SingleID
*
853 TransliteratorIDParser::specsToSpecialInverse(const Specs
& specs
, UErrorCode
&status
) {
854 if (0!=specs
.source
.caseCompare(ANY
, 3, U_FOLD_CASE_DEFAULT
)) {
857 umtx_initOnce(gSpecialInversesInitOnce
, init
, status
);
858 if (U_FAILURE(status
)) {
862 UnicodeString
* inverseTarget
;
865 inverseTarget
= (UnicodeString
*) SPECIAL_INVERSES
->get(specs
.target
);
868 if (inverseTarget
!= NULL
) {
869 // If the original ID contained "Any-" then make the
870 // special inverse "Any-Foo"; otherwise make it "Foo".
871 // So "Any-NFC" => "Any-NFD" but "NFC" => "NFD".
873 if (specs
.filter
.length() != 0) {
874 buf
.append(specs
.filter
);
876 if (specs
.sawSource
) {
877 buf
.append(ANY
, 3).append(TARGET_SEP
);
879 buf
.append(*inverseTarget
);
881 UnicodeString
basicID(TRUE
, ANY
, 3);
882 basicID
.append(TARGET_SEP
).append(*inverseTarget
);
884 if (specs
.variant
.length() != 0) {
885 buf
.append(VARIANT_SEP
).append(specs
.variant
);
886 basicID
.append(VARIANT_SEP
).append(specs
.variant
);
888 return new SingleID(buf
, basicID
);
894 * Glue method to get around access problems in C++. This would
895 * ideally be inline but we want to avoid a circular header
898 Transliterator
* TransliteratorIDParser::createBasicInstance(const UnicodeString
& id
, const UnicodeString
* canonID
) {
899 return Transliterator::createBasicInstance(id
, canonID
);
903 * Initialize static memory. Called through umtx_initOnce only.
905 void TransliteratorIDParser::init(UErrorCode
&status
) {
906 U_ASSERT(SPECIAL_INVERSES
== NULL
);
907 ucln_i18n_registerCleanup(UCLN_I18N_TRANSLITERATOR
, utrans_transliterator_cleanup
);
909 SPECIAL_INVERSES
= new Hashtable(TRUE
, status
);
910 if (SPECIAL_INVERSES
== NULL
) {
911 status
= U_MEMORY_ALLOCATION_ERROR
;
914 SPECIAL_INVERSES
->setValueDeleter(uprv_deleteUObject
);
918 * Free static memory.
920 void TransliteratorIDParser::cleanup() {
921 if (SPECIAL_INVERSES
) {
922 delete SPECIAL_INVERSES
;
923 SPECIAL_INVERSES
= NULL
;
925 gSpecialInversesInitOnce
.reset();
930 #endif /* #if !UCONFIG_NO_TRANSLITERATION */