[dasher: 12/38] Fix AbstractXMLParser error message, removing XML, add FormatMessageWith2Strings



commit b1dfb8de59ca4ede169de8e6ab76c0639bce282d
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Fri Dec 9 07:00:13 2011 +0000

    Fix AbstractXMLParser error message, removing XML, add FormatMessageWith2Strings
    
    Dumping 1k of XML to Dasher's on-screen messaging is not useful!
     => print to stdout on debug builds, only

 Src/DasherCore/AbstractXMLParser.cpp |   13 +++++--------
 Src/DasherCore/Messages.cpp          |    7 +++++++
 Src/DasherCore/Messages.h            |    5 +++++
 3 files changed, 17 insertions(+), 8 deletions(-)
---
diff --git a/Src/DasherCore/AbstractXMLParser.cpp b/Src/DasherCore/AbstractXMLParser.cpp
index 6d5d8d0..1afc75e 100644
--- a/Src/DasherCore/AbstractXMLParser.cpp
+++ b/Src/DasherCore/AbstractXMLParser.cpp
@@ -59,14 +59,11 @@ bool AbstractXMLParser::Parse(const std::string &strDesc, istream &in, bool bUse
         const XML_LChar *xmle=XML_ErrorString(XML_GetErrorCode(Parser)); //think XML_LChar==char, depends on preprocessor variables...
         
         ///TRANSLATORS: the first string is the error message from the XML Parser;
-        /// the second is the URL of the file we're trying to read; the third
-        /// is a section excerpt from the file, containing the error.
-        const char *msg=_("XML Error %s in %s somewhere in block: %s");
-        //we can't use FormatMessage as we have too many substitutions...
-        char *buf(new char[strlen(msg) + strlen(xmle) + m_strDesc.length() + len]);
-        sprintf(buf, xmle, m_strDesc.c_str(), string(Buffer,len).c_str());
-        m_pMsgs->Message(buf, true);
-        delete buf;
+        /// the second is the URL of the file we're trying to read.
+        m_pMsgs->FormatMessageWith2Strings(_("XML Error %s in file %s "), xmle, m_strDesc.c_str());
+#ifdef DEBUG
+        std::cout << "Error in: " << string(Buffer,len) << std::endl;
+#endif
       }
       break;
     }
diff --git a/Src/DasherCore/Messages.cpp b/Src/DasherCore/Messages.cpp
index c5e2e5c..aced902 100644
--- a/Src/DasherCore/Messages.cpp
+++ b/Src/DasherCore/Messages.cpp
@@ -13,6 +13,13 @@ void CMessageDisplay::FormatMessageWithString(const char *fmt, const char *str)
   delete buf;
 }
 
+void CMessageDisplay::FormatMessageWith2Strings(const char *fmt, const char *str1, const char *str2) {
+  char *buf(new char[strlen(fmt)+strlen(str1)+strlen(str2)]);
+  sprintf(buf, fmt, str1, str2);
+  Message(buf,true);
+  delete buf;
+}
+
   //The following implements a varargs version of the above,
   // dynamically allocating enough storage for the formatted string
   // using snprintf. However, this doesn't work on Solaris,
diff --git a/Src/DasherCore/Messages.h b/Src/DasherCore/Messages.h
index 892a2aa..b8cfdc2 100644
--- a/Src/DasherCore/Messages.h
+++ b/Src/DasherCore/Messages.h
@@ -47,6 +47,11 @@ public:
   ///Utility method for common case of displaying a modal message with a format
   /// string containing a single %s.
   void FormatMessageWithString(const char* fmt, const char* str);
+
+  ///Utility method for less-but-still-quite-common case of displaying a modal
+  /// message with a format string containing two %s
+  void FormatMessageWith2Strings(const char* fmt, const char* str1, const char* str2);
+
 };
 
 /// @}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]