From 161c2863a7dd7d93d10a491f49c19afba0cbf095 Mon Sep 17 00:00:00 2001 From: Yves Arrouye Date: Sat, 16 Feb 2002 07:43:26 +0000 Subject: [PATCH] ICU-1220 support IDs and compound IDs, but also complex rules in the -x argument. X-SVN-Rev: 7688 --- icu4c/source/extra/uconv/root.txt | 4 ++-- icu4c/source/extra/uconv/uconv.1.in | 22 ++++++++++++++-------- icu4c/source/extra/uconv/uconv.cpp | 14 ++++++++++++-- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/icu4c/source/extra/uconv/root.txt b/icu4c/source/extra/uconv/root.txt index 852eb782922..cc445418840 100644 --- a/icu4c/source/extra/uconv/root.txt +++ b/icu4c/source/extra/uconv/root.txt @@ -1,6 +1,6 @@ // -*- Coding: utf-8; -*- [all uconv resource files] // Copyright (c) 2000 IBM, Inc. and Others. -// $Revision: 1.21 $ +// $Revision: 1.22 $ // // Root translation file for uconv messages. // So you want to translate this file??? Great! @@ -67,7 +67,7 @@ root cantOpenFromCodeset { "Couldn''t open from encoding {0}: {1}\n" } // 0:set, 1: err cantOpenToCodeset { "Couldn''t open to encoding {0}: {1}\n" } // 0: set, 1: err - cantOpenTranslit { "Couldn''t open transliteror {0}: {1}\n" } // 0: set, 1: err + cantCreateTranslit { "Couldn''t create transliteror {0}: {1}\n" } // 0: set, 1: err cantSetCallback { "Couldn''t set transcoding callback: {0}\n" } // 0: err diff --git a/icu4c/source/extra/uconv/uconv.1.in b/icu4c/source/extra/uconv/uconv.1.in index 2856cb7fe49..28735068e05 100644 --- a/icu4c/source/extra/uconv/uconv.1.in +++ b/icu4c/source/extra/uconv/uconv.1.in @@ -37,7 +37,7 @@ .BI "\-\-canon" ] [ -.BI "\-x" " transliterator +.BI "\-x" " transliteration ] [ .BI "\-\-to\-callback" " callback" @@ -90,10 +90,16 @@ such characters in the input. Other callbacks offer a useful visual representation of the invalid data. .PP .B uconv -can also run the transcoding through a specified -.IR transliterator , +can also run the specified +.IR transliteration +on the transcoded data, in which case transliteration will happen as an intermediate step, after the data have been transcoded to Unicode. +The +.I transliteration +can be either a list of semicolon-separated transliterator names, +or an arbitrary complex set of rules in the ICU transliteration +rules format. .SH OPTIONS .TP .BR "\-h\fP, \fB\-?\fP, \fB\-\-help" @@ -137,12 +143,12 @@ If used with .BR "\-L\fP, \fB\-\-list\-transliterators" , print only one transliterator name per line. .TP -.BI "\-x" " transliterator" -Run the transcoded Unicode data through the given -.IR transliterator +.BI "\-x" " transliteration" +Run the given +.IR transliteration +on the transcoded Unicode data, and use the transliterated data as input for the transcoding to -the the destination encoding. Compound transliterators can be -created by separating individual names with a semicolon. +the the destination encoding. .TP .BI "\-\-to\-callback" " callback" Use diff --git a/icu4c/source/extra/uconv/uconv.cpp b/icu4c/source/extra/uconv/uconv.cpp index a3d29d6fa8c..c08b43242f4 100644 --- a/icu4c/source/extra/uconv/uconv.cpp +++ b/icu4c/source/extra/uconv/uconv.cpp @@ -26,6 +26,7 @@ #include #include "cmemory.h" +#include "cstring.h" #include "unicode/uwmsg.h" @@ -424,12 +425,21 @@ static UBool convertFile(const char *pname, // Create transliterator as needed. if (translit != NULL && *translit) { + UParseError parse; UnicodeString str(translit); - t = Transliterator::createInstance(str, UTRANS_FORWARD, err); + + /* Create from rules or by ID as needed. */ + + if (uprv_strchr(translit, ':') || uprv_strchr(translit, '>') || uprv_strchr(translit, '<') || uprv_strchr(translit, '>')) { + t = Transliterator::createFromRules("Uconv", str, UTRANS_FORWARD, parse, err); + } else { + t = Transliterator::createInstance(translit, UTRANS_FORWARD, err); + } + if (U_FAILURE(err)) { str.append((UChar32) 0); initMsg(pname); - u_wmsg("cantOpenTranslit", str.getBuffer(), + u_wmsg("cantCreateTranslit", str.getBuffer(), u_wmsg_errorName(err)); if (t) { delete t;