[xml] [patch] xmlStrVPrintf
- From: Aleksey Sanin <aleksey aleksey com>
- To: xml <xml gnome org>
- Subject: [xml] [patch] xmlStrVPrintf
- Date: Tue, 28 Oct 2003 20:10:01 -0800
Daniel,
I found that in addition to xmlStrPrintf I need xmlStrVPrintf function
for strings formatting. It's a trivial wrapper around Trio function and
I hope
that you wouldn't object to add this function to LibXML2 API.
Thank you in advance,
Aleksey
Index: parser.c
===================================================================
RCS file: /cvs/gnome/gnome-xml/parser.c,v
retrieving revision 1.340
diff -u -r1.340 parser.c
--- parser.c 28 Oct 2003 23:06:30 -0000 1.340
+++ parser.c 29 Oct 2003 04:03:56 -0000
@@ -2482,6 +2482,30 @@
return(ret);
}
+/**
+ * xmlStrVPrintf:
+ * @buf: the result buffer.
+ * @len: the result buffer length.
+ * @msg: the message with printf formatting.
+ * @ap: extra parameters for the message.
+ *
+ * Formats @msg and places result into @buf.
+ *
+ * Returns the number of characters written to @buf or -1 if an error occurs.
+ */
+int
+xmlStrVPrintf(xmlChar *buf, int len, const xmlChar *msg, va_list ap) {
+ int ret;
+
+ if((buf == NULL) || (msg == NULL)) {
+ return(-1);
+ }
+
+ ret = vsnprintf((char *) buf, len, (const char *) msg, ap);
+ buf[len - 1] = 0; /* be safe ! */
+
+ return(ret);
+}
/************************************************************************
* *
* Commodity functions, cleanup needed ? *
Index: include/libxml/parser.h
===================================================================
RCS file: /cvs/gnome/gnome-xml/include/libxml/parser.h,v
retrieving revision 1.107
diff -u -r1.107 parser.h
--- include/libxml/parser.h 28 Oct 2003 21:31:45 -0000 1.107
+++ include/libxml/parser.h 29 Oct 2003 04:03:58 -0000
@@ -9,6 +9,8 @@
#ifndef __XML_PARSER_H__
#define __XML_PARSER_H__
+#include <stdarg.h>
+
#include <libxml/xmlversion.h>
#include <libxml/tree.h>
#include <libxml/dict.h>
@@ -863,6 +865,12 @@
int len,
const xmlChar *msg,
...);
+
+XMLPUBFUN int XMLCALL
+ xmlStrVPrintf (xmlChar *buf,
+ int len,
+ const xmlChar *msg,
+ va_list ap);
/*
* Basic parsing Interfaces
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]