ReactOS 0.4.15-dev-8092-ge0ba2f3
xmlstring.c File Reference
#include "libxml.h"
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <libxml/xmlmemory.h>
#include <libxml/parserInternals.h>
#include <libxml/xmlstring.h>
Include dependency graph for xmlstring.c:

Go to the source code of this file.

Macros

#define IN_LIBXML
 

Functions

xmlCharxmlStrndup (const xmlChar *cur, int len)
 
xmlCharxmlStrdup (const xmlChar *cur)
 
xmlCharxmlCharStrndup (const char *cur, int len)
 
xmlCharxmlCharStrdup (const char *cur)
 
int xmlStrcmp (const xmlChar *str1, const xmlChar *str2)
 
int xmlStrEqual (const xmlChar *str1, const xmlChar *str2)
 

: the localname of the QName

xmlStrQEqual: @pref: the prefix of the QName

@str: the second xmlChar *

Check if a QName is Equal to a given string

Returns 1 if they are equal, 0 if they are different

static const xmlChar casemap [256]
 
int xmlStrQEqual (const xmlChar *pref, const xmlChar *name, const xmlChar *str)
 
int xmlStrncmp (const xmlChar *str1, const xmlChar *str2, int len)
 
int xmlStrcasecmp (const xmlChar *str1, const xmlChar *str2)
 
int xmlStrncasecmp (const xmlChar *str1, const xmlChar *str2, int len)
 
const xmlCharxmlStrchr (const xmlChar *str, xmlChar val)
 
const xmlCharxmlStrstr (const xmlChar *str, const xmlChar *val)
 
const xmlCharxmlStrcasestr (const xmlChar *str, const xmlChar *val)
 
xmlCharxmlStrsub (const xmlChar *str, int start, int len)
 
int xmlStrlen (const xmlChar *str)
 
xmlCharxmlStrncat (xmlChar *cur, const xmlChar *add, int len)
 
xmlCharxmlStrncatNew (const xmlChar *str1, const xmlChar *str2, int len)
 
xmlCharxmlStrcat (xmlChar *cur, const xmlChar *add)
 
int XMLCDECL xmlStrPrintf (xmlChar *buf, int len, const char *msg,...)
 
int xmlStrVPrintf (xmlChar *buf, int len, const char *msg, va_list ap)
 
int xmlUTF8Size (const xmlChar *utf)
 
int xmlUTF8Charcmp (const xmlChar *utf1, const xmlChar *utf2)
 
int xmlUTF8Strlen (const xmlChar *utf)
 
int xmlGetUTF8Char (const unsigned char *utf, int *len)
 
int xmlCheckUTF8 (const unsigned char *utf)
 
int xmlUTF8Strsize (const xmlChar *utf, int len)
 
xmlCharxmlUTF8Strndup (const xmlChar *utf, int len)
 
const xmlCharxmlUTF8Strpos (const xmlChar *utf, int pos)
 
int xmlUTF8Strloc (const xmlChar *utf, const xmlChar *utfchar)
 
xmlCharxmlUTF8Strsub (const xmlChar *utf, int start, int len)
 
xmlCharxmlEscapeFormatString (xmlChar **msg)
 

Macro Definition Documentation

◆ IN_LIBXML

#define IN_LIBXML

Definition at line 16 of file xmlstring.c.

Function Documentation

◆ xmlCharStrdup()

xmlChar * xmlCharStrdup ( const char cur)

xmlCharStrdup: @cur: the input char *

a strdup for char's to xmlChar's

Returns a new xmlChar * or NULL

Definition at line 114 of file xmlstring.c.

114 {
115 const char *p = cur;
116
117 if (cur == NULL) return(NULL);
118 while (*p != '\0') p++; /* non input consuming */
119 return(xmlCharStrndup(cur, p - cur));
120}
#define NULL
Definition: types.h:112
FxCollectionEntry * cur
GLfloat GLfloat p
Definition: glext.h:8902
xmlChar * xmlCharStrndup(const char *cur, int len)
Definition: xmlstring.c:86

Referenced by xmlParseDocument(), xmlParseExtParsedEnt(), xmlParseTextDecl(), and xmlPosixStrdup().

◆ xmlCharStrndup()

xmlChar * xmlCharStrndup ( const char cur,
int  len 
)

xmlCharStrndup: @cur: the input char * @len: the len of @cur

a strndup for char's to xmlChar's

Returns a new xmlChar * or NULL

Definition at line 86 of file xmlstring.c.

86 {
87 int i;
88 xmlChar *ret;
89
90 if ((cur == NULL) || (len < 0)) return(NULL);
91 ret = (xmlChar *) xmlMallocAtomic(((size_t) len + 1) * sizeof(xmlChar));
92 if (ret == NULL) {
94 return(NULL);
95 }
96 for (i = 0;i < len;i++) {
97 ret[i] = (xmlChar) cur[i];
98 if (ret[i] == 0) return(ret);
99 }
100 ret[len] = 0;
101 return(ret);
102}
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
void xmlErrMemory(xmlParserCtxtPtr ctxt, const char *extra)
XMLPUBVAR xmlMallocFunc xmlMallocAtomic
Definition: globals.h:249
int ret
unsigned char xmlChar
Definition: xmlstring.h:28

Referenced by xmlCharStrdup().

◆ xmlCheckUTF8()

int xmlCheckUTF8 ( const unsigned char utf)

xmlCheckUTF8: @utf: Pointer to putative UTF-8 encoded string.

Checks @utf for being valid UTF-8. @utf is assumed to be null-terminated. This function is not super-strict, as it will allow longer UTF-8 sequences than necessary. Note that Java is capable of producing these sequences if provoked. Also note, this routine checks for the 4-byte maximum size, but does not check for 0x10ffff maximum value.

Return value: true if @utf is valid.

Definition at line 779 of file xmlstring.c.

780{
781 int ix;
782 unsigned char c;
783
784 if (utf == NULL)
785 return(0);
786 /*
787 * utf is a string of 1, 2, 3 or 4 bytes. The valid strings
788 * are as follows (in "bit format"):
789 * 0xxxxxxx valid 1-byte
790 * 110xxxxx 10xxxxxx valid 2-byte
791 * 1110xxxx 10xxxxxx 10xxxxxx valid 3-byte
792 * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx valid 4-byte
793 */
794 while ((c = utf[0])) { /* string is 0-terminated */
795 ix = 0;
796 if ((c & 0x80) == 0x00) { /* 1-byte code, starts with 10 */
797 ix = 1;
798 } else if ((c & 0xe0) == 0xc0) {/* 2-byte code, starts with 110 */
799 if ((utf[1] & 0xc0 ) != 0x80)
800 return 0;
801 ix = 2;
802 } else if ((c & 0xf0) == 0xe0) {/* 3-byte code, starts with 1110 */
803 if (((utf[1] & 0xc0) != 0x80) ||
804 ((utf[2] & 0xc0) != 0x80))
805 return 0;
806 ix = 3;
807 } else if ((c & 0xf8) == 0xf0) {/* 4-byte code, starts with 11110 */
808 if (((utf[1] & 0xc0) != 0x80) ||
809 ((utf[2] & 0xc0) != 0x80) ||
810 ((utf[3] & 0xc0) != 0x80))
811 return 0;
812 ix = 4;
813 } else /* unknown encoding */
814 return 0;
815 utf += ix;
816 }
817 return(1);
818}
const GLubyte * c
Definition: glext.h:8905
#define c
Definition: ke_i.h:80

◆ xmlEscapeFormatString()

xmlChar * xmlEscapeFormatString ( xmlChar **  msg)

xmlEscapeFormatString: @msg: a pointer to the string in which to escape '' characters. Must be a heap-allocated buffer created by libxml2 that may be returned, or that may be freed and replaced.

Replaces the string pointed to by 'msg' with an escaped string. Returns the same string with all '' characters escaped.

Definition at line 1001 of file xmlstring.c.

1002{
1003 xmlChar *msgPtr = NULL;
1004 xmlChar *result = NULL;
1005 xmlChar *resultPtr = NULL;
1006 size_t count = 0;
1007 size_t msgLen = 0;
1008 size_t resultLen = 0;
1009
1010 if (!msg || !*msg)
1011 return(NULL);
1012
1013 for (msgPtr = *msg; *msgPtr != '\0'; ++msgPtr) {
1014 ++msgLen;
1015 if (*msgPtr == '%')
1016 ++count;
1017 }
1018
1019 if (count == 0)
1020 return(*msg);
1021
1022 if ((count > INT_MAX) || (msgLen > INT_MAX - count))
1023 return(NULL);
1024 resultLen = msgLen + count + 1;
1025 result = (xmlChar *) xmlMallocAtomic(resultLen * sizeof(xmlChar));
1026 if (result == NULL) {
1027 /* Clear *msg to prevent format string vulnerabilities in
1028 out-of-memory situations. */
1029 xmlFree(*msg);
1030 *msg = NULL;
1032 return(NULL);
1033 }
1034
1035 for (msgPtr = *msg, resultPtr = result; *msgPtr != '\0'; ++msgPtr, ++resultPtr) {
1036 *resultPtr = *msgPtr;
1037 if (*msgPtr == '%')
1038 *(++resultPtr) = '%';
1039 }
1040 result[resultLen - 1] = '\0';
1041
1042 xmlFree(*msg);
1043 *msg = result;
1044
1045 return *msg;
1046}
#define msg(x)
Definition: auth_time.c:54
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint64EXT * result
Definition: glext.h:11304
#define INT_MAX
Definition: limits.h:40
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:251

◆ xmlGetUTF8Char()

int xmlGetUTF8Char ( const unsigned char utf,
int len 
)

xmlGetUTF8Char: @utf: a sequence of UTF-8 encoded bytes @len: a pointer to the minimum number of bytes present in the sequence. This is used to assure the next character is completely contained within the sequence.

Read the first UTF8 character from @utf

Returns the char value or -1 in case of error, and sets *len to the actual number of bytes consumed (0 in case of error)

Definition at line 708 of file xmlstring.c.

708 {
709 unsigned int c;
710
711 if (utf == NULL)
712 goto error;
713 if (len == NULL)
714 goto error;
715 if (*len < 1)
716 goto error;
717
718 c = utf[0];
719 if (c & 0x80) {
720 if (*len < 2)
721 goto error;
722 if ((utf[1] & 0xc0) != 0x80)
723 goto error;
724 if ((c & 0xe0) == 0xe0) {
725 if (*len < 3)
726 goto error;
727 if ((utf[2] & 0xc0) != 0x80)
728 goto error;
729 if ((c & 0xf0) == 0xf0) {
730 if (*len < 4)
731 goto error;
732 if ((c & 0xf8) != 0xf0 || (utf[3] & 0xc0) != 0x80)
733 goto error;
734 *len = 4;
735 /* 4-byte code */
736 c = (utf[0] & 0x7) << 18;
737 c |= (utf[1] & 0x3f) << 12;
738 c |= (utf[2] & 0x3f) << 6;
739 c |= utf[3] & 0x3f;
740 } else {
741 /* 3-byte code */
742 *len = 3;
743 c = (utf[0] & 0xf) << 12;
744 c |= (utf[1] & 0x3f) << 6;
745 c |= utf[2] & 0x3f;
746 }
747 } else {
748 /* 2-byte code */
749 *len = 2;
750 c = (utf[0] & 0x1f) << 6;
751 c |= utf[1] & 0x3f;
752 }
753 } else {
754 /* 1-byte code */
755 *len = 1;
756 }
757 return(c);
758
759error:
760 if (len != NULL)
761 *len = 0;
762 return(-1);
763}
#define error(str)
Definition: mkdosfs.c:1605

Referenced by xmlCharEncOutFunc().

◆ xmlStrcasecmp()

int xmlStrcasecmp ( const xmlChar str1,
const xmlChar str2 
)

xmlStrcasecmp: @str1: the first xmlChar * @str2: the second xmlChar *

a strcasecmp for xmlChar's

Returns the integer result of the comparison

Definition at line 275 of file xmlstring.c.

275 {
276 register int tmp;
277
278 if (str1 == str2) return(0);
279 if (str1 == NULL) return(-1);
280 if (str2 == NULL) return(1);
281 do {
282 tmp = casemap[*str1++] - casemap[*str2];
283 if (tmp != 0) return(tmp);
284 } while (*str2++ != 0);
285 return 0;
286}
static const xmlChar casemap[256]
Definition: xmlstring.c:229

Referenced by xmlParseEncodingDecl(), xsltApplyStylesheetInternal(), xsltDocumentElem(), xsltGetHTMLIDs(), and xsltParseStylesheetPI().

◆ xmlStrcasestr()

const xmlChar * xmlStrcasestr ( const xmlChar str,
const xmlChar val 
)

xmlStrcasestr: @str: the xmlChar * array (haystack) @val: the xmlChar to search (needle)

a case-ignoring strstr for xmlChar's

Returns the xmlChar * for the first occurrence or NULL.

Definition at line 373 of file xmlstring.c.

373 {
374 int n;
375
376 if (str == NULL) return(NULL);
377 if (val == NULL) return(NULL);
378 n = xmlStrlen(val);
379
380 if (n == 0) return(str);
381 while (*str != 0) { /* non input consuming */
382 if (casemap[*str] == casemap[*val])
383 if (!xmlStrncasecmp(str, val, n)) return(str);
384 str++;
385 }
386 return(NULL);
387}
GLdouble n
Definition: glext.h:7729
GLuint GLfloat * val
Definition: glext.h:7180
const WCHAR * str
int xmlStrlen(const xmlChar *str)
Definition: xmlstring.c:426
int xmlStrncasecmp(const xmlChar *str1, const xmlChar *str2, int len)
Definition: xmlstring.c:300

◆ xmlStrcat()

xmlChar * xmlStrcat ( xmlChar cur,
const xmlChar add 
)

xmlStrcat: @cur: the original xmlChar * array @add: the xmlChar * array added

a strcat for array of xmlChar's. Since they are supposed to be encoded in UTF-8 or an encoding with 8bit based chars, we assume a termination mark of '0'.

Returns a new xmlChar * containing the concatenated string. The original @cur is reallocated and should not be freed.

Definition at line 524 of file xmlstring.c.

524 {
525 const xmlChar *p = add;
526
527 if (add == NULL) return(cur);
528 if (cur == NULL)
529 return(xmlStrdup(add));
530
531 while (*p != 0) p++; /* non input consuming */
532 return(xmlStrncat(cur, add, p - add));
533}
xmlChar * xmlStrdup(const xmlChar *cur)
Definition: xmlstring.c:67
xmlChar * xmlStrncat(xmlChar *cur, const xmlChar *add, int len)
Definition: xmlstring.c:446

Referenced by xmllintExternalEntityLoader(), xmlURIEscape(), xsltAddKey(), xsltAttrTemplateValueProcessNode(), xsltEvalAVT(), xsltFormatNumberConversion(), and xsltReverseCompMatch().

◆ xmlStrchr()

const xmlChar * xmlStrchr ( const xmlChar str,
xmlChar  val 
)

xmlStrchr: @str: the xmlChar * array @val: the xmlChar to search

a strchr for xmlChar's

Returns the xmlChar * for the first occurrence or NULL.

Definition at line 325 of file xmlstring.c.

325 {
326 if (str == NULL) return(NULL);
327 while (*str != 0) { /* non input consuming */
328 if (*str == val) return((xmlChar *) str);
329 str++;
330 }
331 return(NULL);
332}

Referenced by xmlBufWriteQuotedString(), xmlParseAttValueComplex(), xmlParseEntityDecl(), xmlParseEntityRef(), xmlParseNotationDecl(), xmlParsePITarget(), xmlParseReference(), xmlParserEntityCheck(), xmlParseStringEntityRef(), xmlURIEscapeStr(), xsltCompileAttr(), and xsltEvalStaticAttrValueTemplate().

◆ xmlStrcmp()

int xmlStrcmp ( const xmlChar str1,
const xmlChar str2 
)

xmlStrcmp: @str1: the first xmlChar * @str2: the second xmlChar *

a strcmp for xmlChar's

Returns the integer result of the comparison

Definition at line 133 of file xmlstring.c.

133 {
134 if (str1 == str2) return(0);
135 if (str1 == NULL) return(-1);
136 if (str2 == NULL) return(1);
137#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
138 return(strcmp((const char *)str1, (const char *)str2));
139#else
140 do {
141 int tmp = *str1++ - *str2;
142 if (tmp != 0) return(tmp);
143 } while (*str2++ != 0);
144 return 0;
145#endif
146}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469

Referenced by xmlBuildRelativeURI(), xmlCreateEntityParserCtxtInternal(), xsltDefaultSortFunction(), and xsltLocaleStrcmp().

◆ xmlStrdup()

xmlChar * xmlStrdup ( const xmlChar cur)

xmlStrdup: @cur: the input xmlChar *

a strdup for array of xmlChar's. Since they are supposed to be encoded in UTF-8 or an encoding with 8bit based chars, we assume a termination mark of '0'.

Returns a new xmlChar * or NULL

Definition at line 67 of file xmlstring.c.

67 {
68 const xmlChar *p = cur;
69
70 if (cur == NULL) return(NULL);
71 while (*p != 0) p++; /* non input consuming */
72 return(xmlStrndup(cur, p - cur));
73}
xmlChar * xmlStrndup(const xmlChar *cur, int len)
Definition: xmlstring.c:42

Referenced by xmlAddAttributeDecl(), xmlAddElementDecl(), xmlAddID(), xmlAddNotationDecl(), xmlAddRef(), xmlBuildRelativeURI(), xmlBuildURI(), xmlCanonicPath(), xmlCopyDocElementContent(), xmlCreateEnumeration(), xmlCtxtResetPush(), xmlCtxtUseOptionsInternal(), xmlDoRead(), xmlGetDtdElementDesc2(), xmlHashAddEntry3(), xmlHashUpdateEntry3(), xmlInitializeGlobalState(), xmllintExternalEntityLoader(), xmlNewDocElementContent(), xmlNewEntityInputStream(), xmlNewInputFromFile(), xmlParseExternalEntityPrivate(), xmlParseInNodeContext(), xmlPathToURI(), xmlSAX2AttributeNs(), xmlSAX2EndDocument(), xmlSAX2StartDocument(), xmlSAX2StartElementNs(), xmlSAX2Text(), xmlSplitQName(), xmlStrcat(), xmlStrncatNew(), xmlSwitchEncoding(), xmlURIEscapeStr(), xsltAddKey(), xsltApplyStylesheetInternal(), xsltAttribute(), xsltAttrListTemplateProcess(), xsltAttrTemplateProcess(), xsltCheckWrite(), xsltCompileStepPattern(), xsltCopyText(), xsltDocumentElem(), xsltElement(), xsltElementAvailableFunction(), xsltFormatNumberConversion(), xsltFunctionAvailableFunction(), xsltGetNsProp(), xsltGetQNameURI(), xsltKeyFunction(), xsltNewDecimalFormat(), xsltNewExtDef(), xsltNewKeyDef(), xsltNewKeyTable(), xsltParseStylesheetKey(), xsltParseStylesheetOutput(), xsltParseStylesheetProcess(), xsltParseStylesheetTemplate(), xsltReverseCompMatch(), and xsltSystemPropertyFunction().

◆ xmlStrEqual()

int xmlStrEqual ( const xmlChar str1,
const xmlChar str2 
)

xmlStrEqual: @str1: the first xmlChar * @str2: the second xmlChar *

Check if both strings are equal of have same content. Should be a bit more readable and faster than xmlStrcmp()

Returns 1 if they are equal, 0 if they are different

Definition at line 160 of file xmlstring.c.

160 {
161 if (str1 == str2) return(1);
162 if (str1 == NULL) return(0);
163 if (str2 == NULL) return(0);
164#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
165 return(strcmp((const char *)str1, (const char *)str2) == 0);
166#else
167 do {
168 if (*str1++ != *str2) return(0);
169 } while (*str2++);
170 return(1);
171#endif
172}

Referenced by exclPrefixPush(), xmlAddAttributeDecl(), xmlBuildRelativeURI(), xmlHashAddEntry3(), xmlHashLookup3(), xmlHashRemoveEntry3(), xmlHashScanFull3(), xmlHashUpdateEntry3(), xmlIsID(), xmlIsXHTML(), xmlParseAttribute2(), xmlParseDocument(), xmlParseEntityDecl(), xmlParseEnumerationType(), xmlParseExternalEntityPrivate(), xmlParseNotationType(), xmlParsePI(), xmlParsePITarget(), xmlParseStartTag2(), xmlParseXMLDecl(), xmlSaveUri(), xmlSAX2AttributeDecl(), xmlSAX2StartElementNs(), xmlStrQEqual(), xsltApplyFallbacks(), xsltApplySequenceConstructor(), xsltApplyStylesheetInternal(), xsltApplyXSLTTemplate(), xsltAttribute(), xsltAttributeComp(), xsltAttrListTemplateProcess(), xsltAttrTemplateProcess(), xsltCheckExtPrefix(), xsltCheckExtURI(), xsltCheckInstructionElement(), xsltCheckParentElement(), xsltCheckRead(), xsltCheckTopLevelElement(), xsltCheckWrite(), xsltCompileIdKeyPattern(), xsltCompileStepPattern(), xsltCopyNamespaceList(), xsltCopyNamespaceListInternal(), xsltCopyTree(), xsltDecimalFormatGetByName(), xsltDecimalFormatGetByQName(), xsltDefaultSortFunction(), xsltDocumentComp(), xsltDocumentElem(), xsltDocumentFunction(), xsltDocumentFunctionLoadDocument(), xsltElement(), xsltFindElemSpaceHandling(), xsltGatherNamespaces(), xsltGetCNsProp(), xsltGetInheritedNsList(), xsltGetKey(), xsltGetNsProp(), xsltGetSpecialNamespace(), xsltInitAllDocKeys(), xsltInitCtxtKey(), xsltInitDocKeyTable(), xsltLoadDocument(), xsltLoadStyleDocument(), xsltLoadStylesheetPI(), xsltMessage(), xsltNamespaceAlias(), xsltNumberComp(), xsltNumberFormat(), xsltParseStylesheetExcludePrefix(), xsltParseStylesheetExtPrefix(), xsltParseStylesheetImport(), xsltParseStylesheetInclude(), xsltParseStylesheetOutput(), xsltParseStylesheetPreserveSpace(), xsltParseStylesheetProcess(), xsltParseStylesheetStripSpace(), xsltParseStylesheetTop(), xsltParseTemplateContent(), xsltPreprocessStylesheet(), xsltProcessUserParamInternal(), xsltRegisterExtPrefix(), xsltRegisterGlobalVariable(), xsltSaveResultTo(), xsltSaveResultToFd(), xsltSaveResultToFile(), xsltSaveResultToFilename(), xsltSaveResultToString(), xsltShallowCopyNsNode(), xsltSortComp(), xsltStylePreCompute(), xsltSystemPropertyFunction(), xsltTestCompMatch(), xsltTestCompMatchCount(), xsltTestStepMatch(), xsltTextComp(), and xsltValueOfComp().

◆ xmlStrlen()

◆ xmlStrncasecmp()

int xmlStrncasecmp ( const xmlChar str1,
const xmlChar str2,
int  len 
)

xmlStrncasecmp: @str1: the first xmlChar * @str2: the second xmlChar * @len: the max comparison length

a strncasecmp for xmlChar's

Returns the integer result of the comparison

Definition at line 300 of file xmlstring.c.

300 {
301 register int tmp;
302
303 if (len <= 0) return(0);
304 if (str1 == str2) return(0);
305 if (str1 == NULL) return(-1);
306 if (str2 == NULL) return(1);
307 do {
308 tmp = casemap[*str1++] - casemap[*str2];
309 if (tmp != 0 || --len == 0) return(tmp);
310 } while (*str2++ != 0);
311 return 0;
312}

Referenced by xmlStrcasestr(), and xsltElementComp().

◆ xmlStrncat()

xmlChar * xmlStrncat ( xmlChar cur,
const xmlChar add,
int  len 
)

xmlStrncat: @cur: the original xmlChar * array @add: the xmlChar * array added @len: the length of @add

a strncat for array of xmlChar's, it will extend @cur with the len first bytes of @add. Note that if @len < 0 then this is an API error and NULL will be returned.

Returns a new xmlChar *, the original @cur is reallocated and should not be freed.

Definition at line 446 of file xmlstring.c.

446 {
447 int size;
448 xmlChar *ret;
449
450 if ((add == NULL) || (len == 0))
451 return(cur);
452 if (len < 0)
453 return(NULL);
454 if (cur == NULL)
455 return(xmlStrndup(add, len));
456
457 size = xmlStrlen(cur);
458 if ((size < 0) || (size > INT_MAX - len))
459 return(NULL);
460 ret = (xmlChar *) xmlRealloc(cur, ((size_t) size + len + 1) * sizeof(xmlChar));
461 if (ret == NULL) {
463 return(cur);
464 }
465 memcpy(&ret[size], add, len * sizeof(xmlChar));
466 ret[size + len] = 0;
467 return(ret);
468}
GLsizeiptr size
Definition: glext.h:5919
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
XMLPUBVAR xmlReallocFunc xmlRealloc
Definition: globals.h:250

Referenced by xmlStrcat(), xsltAddKey(), xsltAttrTemplateValueProcessNode(), and xsltCompileAttr().

◆ xmlStrncatNew()

xmlChar * xmlStrncatNew ( const xmlChar str1,
const xmlChar str2,
int  len 
)

xmlStrncatNew: @str1: first xmlChar string @str2: second xmlChar string @len: the len of @str2 or < 0

same as xmlStrncat, but creates a new string. The original two strings are not freed. If @len is < 0 then the length will be calculated automatically.

Returns a new xmlChar * or NULL

Definition at line 483 of file xmlstring.c.

483 {
484 int size;
485 xmlChar *ret;
486
487 if (len < 0) {
488 len = xmlStrlen(str2);
489 if (len < 0)
490 return(NULL);
491 }
492 if ((str2 == NULL) || (len == 0))
493 return(xmlStrdup(str1));
494 if (str1 == NULL)
495 return(xmlStrndup(str2, len));
496
497 size = xmlStrlen(str1);
498 if ((size < 0) || (size > INT_MAX - len))
499 return(NULL);
500 ret = (xmlChar *) xmlMalloc(((size_t) size + len + 1) * sizeof(xmlChar));
501 if (ret == NULL) {
503 return(xmlStrndup(str1, size));
504 }
505 memcpy(ret, str1, size * sizeof(xmlChar));
506 memcpy(&ret[size], str2, len * sizeof(xmlChar));
507 ret[size + len] = 0;
508 return(ret);
509}
XMLPUBVAR xmlMallocFunc xmlMalloc
Definition: globals.h:248

◆ xmlStrncmp()

int xmlStrncmp ( const xmlChar str1,
const xmlChar str2,
int  len 
)

xmlStrncmp: @str1: the first xmlChar * @str2: the second xmlChar * @len: the max comparison length

a strncmp for xmlChar's

Returns the integer result of the comparison

Definition at line 213 of file xmlstring.c.

213 {
214 if (len <= 0) return(0);
215 if (str1 == str2) return(0);
216 if (str1 == NULL) return(-1);
217 if (str2 == NULL) return(1);
218#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
219 return(strncmp((const char *)str1, (const char *)str2, len));
220#else
221 do {
222 int tmp = *str1++ - *str2;
223 if (tmp != 0 || --len == 0) return(tmp);
224 } while (*str2++ != 0);
225 return 0;
226#endif
227}
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534

Referenced by xmlDictExists(), xmlDictLookup(), xmlStrstr(), xmlUTF8Charcmp(), xmlUTF8Strloc(), xsltFormatNumberConversion(), and xsltUTF8Charcmp().

◆ xmlStrndup()

◆ xmlStrPrintf()

int XMLCDECL xmlStrPrintf ( xmlChar buf,
int  len,
const char msg,
  ... 
)

xmlStrPrintf: @buf: the result buffer. @len: the result buffer length. @msg: the message with printf formatting. ...: 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.

Definition at line 547 of file xmlstring.c.

547 {
549 int ret;
550
551 if((buf == NULL) || (msg == NULL)) {
552 return(-1);
553 }
554
555 va_start(args, msg);
556 ret = vsnprintf((char *) buf, len, (const char *) msg, args);
557 va_end(args);
558 buf[len - 1] = 0; /* be safe ! */
559
560 return(ret);
561}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define args
Definition: format.c:66
Definition: match.c:390
#define vsnprintf
Definition: tif_win32.c:406

◆ xmlStrQEqual()

int xmlStrQEqual ( const xmlChar pref,
const xmlChar name,
const xmlChar str 
)

Definition at line 186 of file xmlstring.c.

186 {
187 if (pref == NULL) return(xmlStrEqual(name, str));
188 if (name == NULL) return(0);
189 if (str == NULL) return(0);
190
191 do {
192 if (*pref++ != *str) return(0);
193 } while ((*str++) && (*pref));
194 if (*str++ != ':') return(0);
195 do {
196 if (*name++ != *str) return(0);
197 } while (*str++);
198 return(1);
199}
Definition: name.c:39
int xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:160

Referenced by xmlDictQLookup(), and xmlHashQLookup3().

◆ xmlStrstr()

const xmlChar * xmlStrstr ( const xmlChar str,
const xmlChar val 
)

xmlStrstr: @str: the xmlChar * array (haystack) @val: the xmlChar to search (needle)

a strstr for xmlChar's

Returns the xmlChar * for the first occurrence or NULL.

Definition at line 345 of file xmlstring.c.

345 {
346 int n;
347
348 if (str == NULL) return(NULL);
349 if (val == NULL) return(NULL);
350 n = xmlStrlen(val);
351
352 if (n == 0) return(str);
353 while (*str != 0) { /* non input consuming */
354 if (*str == *val) {
355 if (!xmlStrncmp(str, val, n)) return((const xmlChar *) str);
356 }
357 str++;
358 }
359 return(NULL);
360}
int xmlStrncmp(const xmlChar *str1, const xmlChar *str2, int len)
Definition: xmlstring.c:213

Referenced by xmlCanonicPath(), xsltComment(), xsltProcessingInstruction(), and xsltSystemPropertyFunction().

◆ xmlStrsub()

xmlChar * xmlStrsub ( const xmlChar str,
int  start,
int  len 
)

xmlStrsub: @str: the xmlChar * array (haystack) @start: the index of the first char (zero based) @len: the length of the substring

Extract a substring of a given string

Returns the xmlChar * for the first occurrence or NULL.

Definition at line 401 of file xmlstring.c.

401 {
402 int i;
403
404 if (str == NULL) return(NULL);
405 if (start < 0) return(NULL);
406 if (len < 0) return(NULL);
407
408 for (i = 0;i < start;i++) {
409 if (*str == 0) return(NULL);
410 str++;
411 }
412 if (*str == 0) return(NULL);
413 return(xmlStrndup(str, len));
414}
GLuint start
Definition: gl.h:1545

◆ xmlStrVPrintf()

int xmlStrVPrintf ( xmlChar buf,
int  len,
const char msg,
va_list  ap 
)

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.

Definition at line 575 of file xmlstring.c.

575 {
576 int ret;
577
578 if((buf == NULL) || (msg == NULL)) {
579 return(-1);
580 }
581
582 ret = vsnprintf((char *) buf, len, (const char *) msg, ap);
583 buf[len - 1] = 0; /* be safe ! */
584
585 return(ret);
586}
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36

◆ xmlUTF8Charcmp()

int xmlUTF8Charcmp ( const xmlChar utf1,
const xmlChar utf2 
)

xmlUTF8Charcmp: @utf1: pointer to first UTF8 char @utf2: pointer to second UTF8 char

compares the two UCS4 values

returns result of the compare as with xmlStrncmp

Definition at line 644 of file xmlstring.c.

644 {
645
646 if (utf1 == NULL ) {
647 if (utf2 == NULL)
648 return 0;
649 return -1;
650 }
651 return xmlStrncmp(utf1, utf2, xmlUTF8Size(utf1));
652}
int xmlUTF8Size(const xmlChar *utf)
Definition: xmlstring.c:613

◆ xmlUTF8Size()

int xmlUTF8Size ( const xmlChar utf)

xmlUTF8Size: @utf: pointer to the UTF8 character

calculates the internal size of a UTF8 character

returns the numbers of bytes in the character, -1 on format error

Definition at line 613 of file xmlstring.c.

613 {
615 int len;
616
617 if (utf == NULL)
618 return -1;
619 if (*utf < 0x80)
620 return 1;
621 /* check valid UTF8 character */
622 if (!(*utf & 0x40))
623 return -1;
624 /* determine number of bytes in char */
625 len = 2;
626 for (mask=0x20; mask != 0; mask>>=1) {
627 if (!(*utf & mask))
628 return len;
629 len++;
630 }
631 return -1;
632}
GLenum GLint GLuint mask
Definition: glext.h:6028

Referenced by xmlUTF8Charcmp().

◆ xmlUTF8Strlen()

int xmlUTF8Strlen ( const xmlChar utf)

xmlUTF8Strlen: @utf: a sequence of UTF-8 encoded bytes

compute the length of an UTF8 string, it doesn't do a full UTF8 checking of the content of the string.

Returns the number of characters in the string or -1 in case of error

Definition at line 664 of file xmlstring.c.

664 {
665 size_t ret = 0;
666
667 if (utf == NULL)
668 return(-1);
669
670 while (*utf != 0) {
671 if (utf[0] & 0x80) {
672 if ((utf[1] & 0xc0) != 0x80)
673 return(-1);
674 if ((utf[0] & 0xe0) == 0xe0) {
675 if ((utf[2] & 0xc0) != 0x80)
676 return(-1);
677 if ((utf[0] & 0xf0) == 0xf0) {
678 if ((utf[0] & 0xf8) != 0xf0 || (utf[3] & 0xc0) != 0x80)
679 return(-1);
680 utf += 4;
681 } else {
682 utf += 3;
683 }
684 } else {
685 utf += 2;
686 }
687 } else {
688 utf++;
689 }
690 ret++;
691 }
692 return(ret > INT_MAX ? 0 : ret);
693}

◆ xmlUTF8Strloc()

int xmlUTF8Strloc ( const xmlChar utf,
const xmlChar utfchar 
)

xmlUTF8Strloc: @utf: the input UTF8 * @utfchar: the UTF8 character to be found

a function to provide the relative location of a UTF8 char

Returns the relative character position of the desired char or -1 if not found

Definition at line 926 of file xmlstring.c.

926 {
927 size_t i;
928 int size;
929 int ch;
930
931 if (utf==NULL || utfchar==NULL) return -1;
932 size = xmlUTF8Strsize(utfchar, 1);
933 for(i=0; (ch=*utf) != 0; i++) {
934 if (xmlStrncmp(utf, utfchar, size)==0)
935 return(i > INT_MAX ? 0 : i);
936 utf++;
937 if ( ch & 0x80 ) {
938 /* if not simple ascii, verify proper format */
939 if ( (ch & 0xc0) != 0xc0 )
940 return(-1);
941 /* then skip over remaining bytes for this char */
942 while ( (ch <<= 1) & 0x80 )
943 if ( (*utf++ & 0xc0) != 0x80 )
944 return(-1);
945 }
946 }
947
948 return(-1);
949}
int xmlUTF8Strsize(const xmlChar *utf, int len)
Definition: xmlstring.c:833

Referenced by xsltFormatNumberConversion().

◆ xmlUTF8Strndup()

xmlChar * xmlUTF8Strndup ( const xmlChar utf,
int  len 
)

xmlUTF8Strndup: @utf: the input UTF8 * @len: the len of @utf (in chars)

a strndup for array of UTF8's

Returns a new UTF8 * or NULL

Definition at line 868 of file xmlstring.c.

868 {
869 xmlChar *ret;
870 int i;
871
872 if ((utf == NULL) || (len < 0)) return(NULL);
873 i = xmlUTF8Strsize(utf, len);
874 ret = (xmlChar *) xmlMallocAtomic(((size_t) i + 1) * sizeof(xmlChar));
875 if (ret == NULL) {
876 return(NULL);
877 }
878 memcpy(ret, utf, i * sizeof(xmlChar));
879 ret[i] = 0;
880 return(ret);
881}

Referenced by xmlUTF8Strsub().

◆ xmlUTF8Strpos()

const xmlChar * xmlUTF8Strpos ( const xmlChar utf,
int  pos 
)

xmlUTF8Strpos: @utf: the input UTF8 * @pos: the position of the desired UTF8 char (in chars)

a function to provide the equivalent of fetching a character from a string array

Returns a pointer to the UTF8 character or NULL

Definition at line 894 of file xmlstring.c.

894 {
895 int ch;
896
897 if (utf == NULL) return(NULL);
898 if (pos < 0)
899 return(NULL);
900 while (pos--) {
901 if ((ch=*utf++) == 0) return(NULL);
902 if ( ch & 0x80 ) {
903 /* if not simple ascii, verify proper format */
904 if ( (ch & 0xc0) != 0xc0 )
905 return(NULL);
906 /* then skip over remaining bytes for this char */
907 while ( (ch <<= 1) & 0x80 )
908 if ( (*utf++ & 0xc0) != 0x80 )
909 return(NULL);
910 }
911 }
912 return((xmlChar *)utf);
913}

Referenced by xsltFormatNumberConversion().

◆ xmlUTF8Strsize()

int xmlUTF8Strsize ( const xmlChar utf,
int  len 
)

xmlUTF8Strsize: @utf: a sequence of UTF-8 encoded bytes @len: the number of characters in the array

storage size of an UTF8 string the behaviour is not guaranteed if the input string is not UTF-8

Returns the storage size of the first 'len' characters of ARRAY

Definition at line 833 of file xmlstring.c.

833 {
834 const xmlChar *ptr=utf;
835 int ch;
836 size_t ret;
837
838 if (utf == NULL)
839 return(0);
840
841 if (len <= 0)
842 return(0);
843
844 while ( len-- > 0) {
845 if ( !*ptr )
846 break;
847 if ( (ch = *ptr++) & 0x80)
848 while ((ch<<=1) & 0x80 ) {
849 if (*ptr == 0) break;
850 ptr++;
851 }
852 }
853 ret = ptr - utf;
854 return (ret > INT_MAX ? 0 : ret);
855}
static PVOID ptr
Definition: dispmode.c:27

Referenced by xmlUTF8Strloc(), xmlUTF8Strndup(), xsltFormatNumberConversion(), xsltFormatNumberPreSuffix(), and xsltUTF8Charcmp().

◆ xmlUTF8Strsub()

xmlChar * xmlUTF8Strsub ( const xmlChar utf,
int  start,
int  len 
)

xmlUTF8Strsub: @utf: a sequence of UTF-8 encoded bytes @start: relative pos of first char @len: total number to copy

Create a substring from a given UTF-8 string Note: positions are given in units of UTF-8 chars

Returns a pointer to a newly created string or NULL if any problem

Definition at line 964 of file xmlstring.c.

964 {
965 int i;
966 int ch;
967
968 if (utf == NULL) return(NULL);
969 if (start < 0) return(NULL);
970 if (len < 0) return(NULL);
971
972 /*
973 * Skip over any leading chars
974 */
975 for (i = 0;i < start;i++) {
976 if ((ch=*utf++) == 0) return(NULL);
977 if ( ch & 0x80 ) {
978 /* if not simple ascii, verify proper format */
979 if ( (ch & 0xc0) != 0xc0 )
980 return(NULL);
981 /* then skip over remaining bytes for this char */
982 while ( (ch <<= 1) & 0x80 )
983 if ( (*utf++ & 0xc0) != 0x80 )
984 return(NULL);
985 }
986 }
987
988 return(xmlUTF8Strndup(utf, len));
989}
xmlChar * xmlUTF8Strndup(const xmlChar *utf, int len)
Definition: xmlstring.c:868

Variable Documentation

◆ casemap

const xmlChar casemap[256]
static

Definition at line 229 of file xmlstring.c.

Referenced by xmlStrcasecmp(), xmlStrcasestr(), and xmlStrncasecmp().