]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/tools/gennorm2/n2builder.cpp
ICU-59117.0.1.tar.gz
[apple/icu.git] / icuSources / tools / gennorm2 / n2builder.cpp
index a2c47f4a9dab6f55208ecfd154457e24b7d52f1e..66ccd700344127f71d48d793373dab2ad6779ed0 100644 (file)
@@ -1,12 +1,14 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
 *******************************************************************************
 *
-*   Copyright (C) 2009-2014, International Business Machines
+*   Copyright (C) 2009-2016, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
 *   file name:  n2builder.cpp
-*   encoding:   US-ASCII
+*   encoding:   UTF-8
 *   tab size:   8 (not used)
 *   indentation:4
 *
@@ -23,9 +25,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#if U_HAVE_STD_STRING
 #include <vector>
-#endif
 #include "unicode/errorcode.h"
 #include "unicode/localpointer.h"
 #include "unicode/putil.h"
@@ -280,7 +280,7 @@ uint8_t Normalizer2DataBuilder::getCC(UChar32 c) const {
 
 static UBool isWellFormed(const UnicodeString &s) {
     UErrorCode errorCode=U_ZERO_ERROR;
-    u_strToUTF8(NULL, 0, NULL, s.getBuffer(), s.length(), &errorCode);
+    u_strToUTF8(NULL, 0, NULL, toUCharPtr(s.getBuffer()), s.length(), &errorCode);
     return U_SUCCESS(errorCode) || errorCode==U_BUFFER_OVERFLOW_ERROR;
 }
 
@@ -313,7 +313,7 @@ void Normalizer2DataBuilder::setRoundTripMapping(UChar32 c, const UnicodeString
                 (int)phase, (long)c);
         exit(U_INVALID_FORMAT_ERROR);
     }
-    int32_t numCP=u_countChar32(m.getBuffer(), m.length());
+    int32_t numCP=u_countChar32(toUCharPtr(m.getBuffer()), m.length());
     if(numCP!=2) {
         fprintf(stderr,
                 "error in gennorm2 phase %d: "
@@ -450,7 +450,7 @@ Normalizer2DataBuilder::decompose(UChar32 start, UChar32 end, uint32_t value) {
         Norm &norm=norms[value];
         const UnicodeString &m=*norm.mapping;
         UnicodeString *decomposed=NULL;
-        const UChar *s=m.getBuffer();
+        const UChar *s=toUCharPtr(m.getBuffer());
         int32_t length=m.length();
         int32_t prev, i=0;
         UChar32 c;
@@ -605,7 +605,7 @@ Normalizer2DataBuilder::reorder(Norm *p, BuilderReorderingBuffer &buffer) {
     if(length>Normalizer2Impl::MAPPING_LENGTH_MASK) {
         return;  // writeMapping() will complain about it and print the code point.
     }
-    const UChar *s=m.getBuffer();
+    const UChar *s=toUCharPtr(m.getBuffer());
     int32_t i=0;
     UChar32 c;
     while(i<length) {
@@ -1207,7 +1207,7 @@ void Normalizer2DataBuilder::writeBinaryFile(const char *filename) {
     }
     udata_writeBlock(pData, indexes, sizeof(indexes));
     udata_writeBlock(pData, norm16TrieBytes.getAlias(), norm16TrieLength);
-    udata_writeUString(pData, extraData.getBuffer(), extraData.length());
+    udata_writeUString(pData, toUCharPtr(extraData.getBuffer()), extraData.length());
     udata_writeBlock(pData, smallFCD, sizeof(smallFCD));
     int32_t writtenSize=udata_finish(pData, errorCode);
     if(errorCode.isFailure()) {
@@ -1247,6 +1247,7 @@ Normalizer2DataBuilder::writeCSourceFile(const char *filename) {
         exit(U_FILE_ACCESS_ERROR);
         return;
     }
+    fputs("#ifdef INCLUDED_FROM_NORMALIZER2_CPP\n\n", f);
     char line[100];
     sprintf(line, "static const UVersionInfo %s_formatVersion={", dataName.data());
     usrc_writeArray(f, line, dataInfo.formatVersion, 8, 4, "};\n");
@@ -1287,6 +1288,7 @@ Normalizer2DataBuilder::writeCSourceFile(const char *filename) {
         line,
         norm16Trie, line2, NULL,
         "};\n");
+    fputs("\n#endif  // INCLUDED_FROM_NORMALIZER2_CPP\n", f);
     fclose(f);
 }