ICU-8972 gennorm2 parse * Unicode version lines from .txt input files

X-SVN-Rev: 31193
This commit is contained in:
Markus Scherer 2012-01-10 21:04:58 +00:00
parent e8d8222080
commit 6d038075aa
4 changed files with 33 additions and 9 deletions

View file

@ -1,4 +1,4 @@
# Copyright (C) 1999-2011, International Business Machines
# Copyright (C) 1999-2012, International Business Machines
# Corporation and others. All Rights Reserved.
#
# file name: nfc.txt
@ -6,7 +6,8 @@
# machine-generated by ICU preparseucd.py
#
# Complete data for Unicode NFC normalization.
# Unicode 6.1.0
* Unicode 6.1.0
# Canonical_Combining_Class (ccc) values
0300..0314:230

View file

@ -1,4 +1,4 @@
# Copyright (C) 1999-2011, International Business Machines
# Copyright (C) 1999-2012, International Business Machines
# Corporation and others. All Rights Reserved.
#
# file name: nfkc.txt
@ -6,7 +6,8 @@
# machine-generated by ICU preparseucd.py
#
# Complete data for Unicode NFKC normalization.
# Unicode 6.1.0
* Unicode 6.1.0
# Canonical_Combining_Class (ccc) values
0300..0314:230

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 2009-2010, International Business Machines
* Copyright (C) 2009-2012, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
@ -80,7 +80,6 @@ main(int argc, char* argv[]) {
/* preset then read command line options */
options[SOURCEDIR].value="";
options[UNICODE_VERSION].value=U_UNICODE_VERSION;
argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[HELP_H]), options);
/* error handling, printing usage message */
@ -145,7 +144,9 @@ main(int argc, char* argv[]) {
LocalPointer<Normalizer2DataBuilder> builder(new Normalizer2DataBuilder(errorCode));
errorCode.assertSuccess();
builder->setUnicodeVersion(options[UNICODE_VERSION].value);
if(options[UNICODE_VERSION].doesOccur) {
builder->setUnicodeVersion(options[UNICODE_VERSION].value);
}
if(options[OPT_FAST].doesOccur) {
builder->setOptimization(Normalizer2DataBuilder::OPTIMIZE_FAST);
@ -198,6 +199,11 @@ void parseFile(FILE *f, Normalizer2DataBuilder &builder) {
continue; // skip empty and comment-only lines
}
if(line[0]=='*') {
const char *s=u_skipWhitespace(line+1);
if(0==strncmp(s, "Unicode", 7)) {
s=u_skipWhitespace(s+7);
builder.setUnicodeVersion(s);
}
continue; // reserved syntax
}
const char *delimiter;

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 2009-2011, International Business Machines
* Copyright (C) 2009-2012, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
@ -193,7 +193,19 @@ Normalizer2DataBuilder::~Normalizer2DataBuilder() {
void
Normalizer2DataBuilder::setUnicodeVersion(const char *v) {
u_versionFromString(unicodeVersion, v);
UVersionInfo nullVersion={ 0, 0, 0, 0 };
UVersionInfo version;
u_versionFromString(version, v);
if( 0!=memcmp(version, unicodeVersion, U_MAX_VERSION_LENGTH) &&
0!=memcmp(nullVersion, unicodeVersion, U_MAX_VERSION_LENGTH)
) {
char buffer[U_MAX_VERSION_STRING_LENGTH];
u_versionToString(unicodeVersion, buffer);
fprintf(stderr, "gennorm2 error: multiple inconsistent Unicode version numbers %s vs. %s\n",
buffer, v);
exit(U_ILLEGAL_ARGUMENT_ERROR);
}
memcpy(unicodeVersion, version, U_MAX_VERSION_LENGTH);
}
Norm *Normalizer2DataBuilder::allocNorm() {
@ -1177,6 +1189,10 @@ void Normalizer2DataBuilder::writeBinaryFile(const char *filename) {
printf("minMaybeYes: 0x%04x\n", (int)indexes[Normalizer2Impl::IX_MIN_MAYBE_YES]);
}
UVersionInfo nullVersion={ 0, 0, 0, 0 };
if(0==memcmp(nullVersion, unicodeVersion, 4)) {
u_versionFromString(unicodeVersion, U_UNICODE_VERSION);
}
memcpy(dataInfo.dataVersion, unicodeVersion, 4);
UNewDataMemory *pData=
udata_create(NULL, NULL, filename, &dataInfo,