ICU-66108.tar.gz
[apple/icu.git] / icuSources / tools / toolutil / xmlparser.cpp
index 556883202131e8add5bbf527a75bfe337cf4dfab..a9650cc599927f26be11a8f1d014ded0c534e312 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) 2004-2008, International Business Machines
+*   Copyright (C) 2004-2010, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
 *   file name:  xmlparser.cpp
-*   encoding:   US-ASCII
+*   encoding:   UTF-8
 *   tab size:   8 (not used)
 *   indentation:4
 *
@@ -207,7 +209,7 @@ UXMLParser::parseFile(const char *filename, UErrorCode &errorCode) {
             goto exit;
         }
 
-        buffer=src.getBuffer(bytesLength);
+        buffer=toUCharPtr(src.getBuffer(bytesLength));
         if(buffer==NULL) {
             // unexpected failure to reserve some string capacity
             errorCode=U_MEMORY_ALLOCATION_ERROR;
@@ -276,7 +278,7 @@ UXMLParser::parseFile(const char *filename, UErrorCode &errorCode) {
         pb=bytes;
         for(;;) {
             length=src.length();
-            buffer=src.getBuffer(capacity);
+            buffer=toUCharPtr(src.getBuffer(capacity));
             if(buffer==NULL) {
                 // unexpected failure to reserve some string capacity
                 errorCode=U_MEMORY_ALLOCATION_ERROR;
@@ -311,7 +313,7 @@ UXMLParser::parseFile(const char *filename, UErrorCode &errorCode) {
             // reached end of file, convert once more to flush the converter
             flush=TRUE;
         }
-    };
+    }
 
 exit:
     ucnv_close(cnv);
@@ -563,7 +565,7 @@ UnicodeString
 UXMLParser::scanContent(UErrorCode &status) {
     UnicodeString  result;
     if (mXMLCharData.lookingAt(fPos, status)) {
-        result = mXMLCharData.group(0, status);
+        result = mXMLCharData.group((int32_t)0, status);
         // Normalize the new-lines.  (Before char ref substitution)
         mNewLineNormalizer.reset(result);
         result = mNewLineNormalizer.replaceAll(fOneLF, status);
@@ -622,7 +624,7 @@ UXMLParser::replaceCharRefs(UnicodeString &s, UErrorCode &status) {
             // An unrecognized &entity;  Leave it alone.
             //  TODO:  check that it really looks like an entity, and is not some
             //         random & in the text.
-            replacement = mAmps.group(0, status);
+            replacement = mAmps.group((int32_t)0, status);
         }
         mAmps.appendReplacement(result, replacement, status);
     }
@@ -715,8 +717,9 @@ UXMLElement::appendText(UnicodeString &text, UBool recurse) const {
     int32_t i, count=fChildren.size();
     for(i=0; i<count; ++i) {
         node=(const UObject *)fChildren.elementAt(i);
-        if(node->getDynamicClassID()==UnicodeString::getStaticClassID()) {
-            text.append(*(const UnicodeString *)node);
+        const UnicodeString *s=dynamic_cast<const UnicodeString *>(node);
+        if(s!=NULL) {
+            text.append(*s);
         } else if(recurse) /* must be a UXMLElement */ {
             ((const UXMLElement *)node)->appendText(text, recurse);
         }
@@ -766,7 +769,7 @@ const UObject *
 UXMLElement::getChild(int32_t i, UXMLNodeType &type) const {
     if(0<=i && i<fChildren.size()) {
         const UObject *node=(const UObject *)fChildren.elementAt(i);
-        if(node->getDynamicClassID()==UXMLElement::getStaticClassID()) {
+        if(dynamic_cast<const UXMLElement *>(node)!=NULL) {
             type=UXML_NODE_TYPE_ELEMENT;
         } else {
             type=UXML_NODE_TYPE_STRING;
@@ -787,10 +790,9 @@ UXMLElement::nextChildElement(int32_t &i) const {
     int32_t count=fChildren.size();
     while(i<count) {
         node=(const UObject *)fChildren.elementAt(i++);
-        // TODO: see if ICU can use C++ instanceof instead of its own poor man's RTTI
-        // if(node instanceof UXMLElement) {
-        if(node->getDynamicClassID()==UXMLElement::getStaticClassID()) {
-            return (const UXMLElement *)node;
+        const UXMLElement *elem=dynamic_cast<const UXMLElement *>(node);
+        if(elem!=NULL) {
+            return elem;
         }
     }
     return NULL;
@@ -809,8 +811,8 @@ UXMLElement::getChildElement(const UnicodeString &name) const {
     int32_t i, count=fChildren.size();
     for(i=0; i<count; ++i) {
         node=(const UObject *)fChildren.elementAt(i);
-        if(node->getDynamicClassID()==UXMLElement::getStaticClassID()) {
-            const UXMLElement *elem=(const UXMLElement *)node;
+        const UXMLElement *elem=dynamic_cast<const UXMLElement *>(node);
+        if(elem!=NULL) {
             if(p==elem->fName) {
                 return elem;
             }