You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by tn...@apache.org on 2001/02/26 22:56:22 UTC
cvs commit: xml-xerces/c/src/util QName.cpp QName.hpp
tng 01/02/26 13:56:21
Modified: c/src/util QName.cpp QName.hpp
Log:
Schema: QName can also be constructed with rawName.
Revision Changes Path
1.2 +88 -28 xml-xerces/c/src/util/QName.cpp
Index: QName.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/util/QName.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- QName.cpp 2001/02/26 19:44:25 1.1
+++ QName.cpp 2001/02/26 21:56:15 1.2
@@ -56,12 +56,16 @@
/*
* $Log: QName.cpp,v $
+ * Revision 1.2 2001/02/26 21:56:15 tng
+ * Schema: QName can also be constructed with rawName.
+ *
* Revision 1.1 2001/02/26 19:44:25 tng
* Schema: add utility class QName, by Pei Yong Zhang.
*
- */
+ */
#include <util/QName.hpp>
+#include <util/Janitor.hpp>
// ---------------------------------------------------------------------------
// QName: Constructors and Destructor
@@ -77,10 +81,9 @@
{
}
-QName::QName(
- const XMLCh* const prefix
- , const XMLCh* const localPart
- , const int uriId
+QName::QName(const XMLCh* const prefix
+ , const XMLCh* const localPart
+ , const int uriId
) :
fPrefix(0)
, fPrefixBufSz(0)
@@ -105,6 +108,32 @@
}
}
+QName::QName(const XMLCh* const rawName
+ , const int uriId
+ ) :
+ fPrefix(0)
+ , fPrefixBufSz(0)
+ , fLocalPart(0)
+ , fLocalPartBufSz(0)
+ , fRawName(0)
+ , fRawNameBufSz(0)
+ , fURIId(0)
+{
+ try
+ {
+ //
+ // Just call the local setters to set up everything. Too much
+ // work is required to replicate that functionality here.
+ //
+ setName(rawName, uriId);
+ }
+
+ catch(...)
+ {
+ cleanUp();
+ }
+}
+
QName::~QName()
{
cleanUp();
@@ -204,33 +233,69 @@
// ---------------------------------------------------------------------------
// QName: Setter methods
// ---------------------------------------------------------------------------
-void QName::setName( const XMLCh* const localPart
- , const XMLCh* const prefix
+void QName::setName(const XMLCh* const prefix
+ , const XMLCh* const localPart
, const int uriId)
{
+ setPrefix(prefix);
+ setLocalPart(localPart);
+
+ // And clean up any QName and leave it undone until/if asked for again
+ if (fRawName)
+ *fRawName = 0;
+
+ // And finally store the URI id parameter
+ fURIId = uriId;
+}
+
+void QName::setName(const XMLCh* const rawName
+ , const int uriId)
+{
+ //set the rawName
unsigned int newLen;
- newLen = XMLString::stringLen(localPart);
- if (!fLocalPartBufSz || (newLen > fLocalPartBufSz))
+ newLen = XMLString::stringLen(rawName);
+ if (!fRawNameBufSz || (newLen > fRawNameBufSz))
{
- delete [] fLocalPart;
- fLocalPartBufSz = newLen + 8;
- fLocalPart = new XMLCh[fLocalPartBufSz + 1];
+ delete [] fRawName;
+ fRawNameBufSz = newLen + 8;
+ fRawName = new XMLCh[fRawNameBufSz + 1];
}
- XMLString::moveChars(fLocalPart, localPart, newLen + 1);
+ XMLString::moveChars(fRawName, rawName, newLen + 1);
- newLen = XMLString::stringLen(prefix);
- if (!fPrefixBufSz || (newLen > fPrefixBufSz))
+ //find out the prefix and localPart from the rawName
+ ArrayJanitor<XMLCh> janName(0);
+ XMLCh tempBuffer[100];
+
+ const int colonInd = XMLString::indexOf(rawName, chColon);
+ const XMLCh* prefPtr = XMLUni::fgZeroLenString;
+ const XMLCh* suffPtr = XMLUni::fgZeroLenString;
+ if (colonInd != -1)
{
- delete [] fPrefix;
- fPrefixBufSz = newLen + 8;
- fPrefix = new XMLCh[fPrefixBufSz + 1];
+ // We have to split the string, so make a copy.
+ if (XMLString::stringLen(rawName) < sizeof(tempBuffer) / sizeof(tempBuffer[0]))
+ {
+ XMLString::copyString(tempBuffer, rawName);
+ tempBuffer[colonInd] = chNull;
+ prefPtr = tempBuffer;
+ }
+ else
+ {
+ janName.reset(XMLString::replicate(rawName));
+ janName[colonInd] = chNull;
+ prefPtr = janName.get();
+ }
+
+ suffPtr = prefPtr + colonInd + 1;
}
- XMLString::moveChars(fPrefix, prefix, newLen + 1);
+ else
+ {
+ // No colon, so we just have a name with no prefix
+ suffPtr = rawName;
+ }
- // And clean up any QName and leave it undone until/if asked for again
- if (fRawName)
- *fRawName = 0;
+ setPrefix(prefPtr);
+ setLocalPart(suffPtr);
// And finally store the URI id parameter
fURIId = uriId;
@@ -278,11 +343,6 @@
(XMLString::compareString(fLocalPart, qname.getLocalPart())==0) &&
(fURIId == qname.getURI());
}
-
-// -----------------------------------------------------------------------
-// Misc
-// -----------------------------------------------------------------------
-
// ---------------------------------------------------------------------------
// QName: Private, helper methods
1.2 +18 -3 xml-xerces/c/src/util/QName.hpp
Index: QName.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/util/QName.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- QName.hpp 2001/02/26 19:44:25 1.1
+++ QName.hpp 2001/02/26 21:56:16 1.2
@@ -56,6 +56,9 @@
/*
* $Log: QName.hpp,v $
+ * Revision 1.2 2001/02/26 21:56:16 tng
+ * Schema: QName can also be constructed with rawName.
+ *
* Revision 1.1 2001/02/26 19:44:25 tng
* Schema: add utility class QName, by Pei Yong Zhang.
*
@@ -77,13 +80,19 @@
/** Default constructor. */
QName();
- /** Constructs a specified qname. */
+ /** Constructs a specified qname using prefix, and localpart. */
QName
( const XMLCh* const prefix
,const XMLCh* const localPart
,const int uriId = -1
);
+ /** Constructs a specified qname using rawName. */
+ QName
+ ( const XMLCh* const rawName
+ ,const int uriId = -1
+ );
+
/** Copy constructor. */
QName(const QName& qname);
@@ -109,8 +118,14 @@
,const XMLCh* const localPart
,const int uriId = -1
);
+
+ void setName
+ (
+ const XMLCh* const rawName
+ ,const int uriId = -1
+ );
- void setPrefix(const XMLCh*) ;
+ void setPrefix(const XMLCh*) ;
void setLocalPart(const XMLCh*) ;