ReactOS 0.4.16-dev-2216-ga08d639
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 "private/parser.h"
#include "private/string.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 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 116 of file xmlstring.c.

116 {
117 const char *p = cur;
118
119 if (cur == NULL) return(NULL);
120 while (*p != '\0') p++; /* non input consuming */
121 return(xmlCharStrndup(cur, p - cur));
122}
#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:88

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 88 of file xmlstring.c.

88 {
89 int i;
90 xmlChar *ret;
91
92 if ((cur == NULL) || (len < 0)) return(NULL);
93 ret = (xmlChar *) xmlMallocAtomic((size_t) len + 1);
94 if (ret == NULL) {
95 return(NULL);
96 }
97 for (i = 0;i < len;i++) {
98 /* Explicit sign change */
99 ret[i] = (xmlChar) cur[i];
100 if (ret[i] == 0) return(ret);
101 }
102 ret[len] = 0;
103 return(ret);
104}
return ret
Definition: mutex.c:146
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
xmlMallocFunc xmlMallocAtomic
Definition: globals.c:204
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);
1026 if (result == NULL) {
1027 /* Clear *msg to prevent format string vulnerabilities in
1028 out-of-memory situations. */
1029 xmlFree(*msg);
1030 *msg = NULL;
1031 return(NULL);
1032 }
1033
1034 for (msgPtr = *msg, resultPtr = result; *msgPtr != '\0'; ++msgPtr, ++resultPtr) {
1035 *resultPtr = *msgPtr;
1036 if (*msgPtr == '%')
1037 *(++resultPtr) = '%';
1038 }
1039 result[resultLen - 1] = '\0';
1040
1041 xmlFree(*msg);
1042 *msg = result;
1043
1044 return *msg;
1045}
#define msg(x)
Definition: auth_time.c:54
#define INT_MAX
Definition: limits.h:26
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint64EXT * result
Definition: glext.h:11304
xmlFreeFunc xmlFree
Definition: globals.c:184

◆ 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
716 c = utf[0];
717 if (c < 0x80) {
718 if (*len < 1)
719 goto error;
720 /* 1-byte code */
721 *len = 1;
722 } else {
723 if ((*len < 2) || ((utf[1] & 0xc0) != 0x80))
724 goto error;
725 if (c < 0xe0) {
726 if (c < 0xc2)
727 goto error;
728 /* 2-byte code */
729 *len = 2;
730 c = (c & 0x1f) << 6;
731 c |= utf[1] & 0x3f;
732 } else {
733 if ((*len < 3) || ((utf[2] & 0xc0) != 0x80))
734 goto error;
735 if (c < 0xf0) {
736 /* 3-byte code */
737 *len = 3;
738 c = (c & 0xf) << 12;
739 c |= (utf[1] & 0x3f) << 6;
740 c |= utf[2] & 0x3f;
741 if ((c < 0x800) || ((c >= 0xd800) && (c < 0xe000)))
742 goto error;
743 } else {
744 if ((*len < 4) || ((utf[3] & 0xc0) != 0x80))
745 goto error;
746 *len = 4;
747 /* 4-byte code */
748 c = (c & 0x7) << 18;
749 c |= (utf[1] & 0x3f) << 12;
750 c |= (utf[2] & 0x3f) << 6;
751 c |= utf[3] & 0x3f;
752 if ((c < 0x10000) || (c >= 0x110000))
753 goto error;
754 }
755 }
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 xmlLoadEntityContent(), xmlParserPrintFileContextInternal(), and xmlStringCurrentChar().

◆ 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 277 of file xmlstring.c.

277 {
278 register int tmp;
279
280 if (str1 == str2) return(0);
281 if (str1 == NULL) return(-1);
282 if (str2 == NULL) return(1);
283 do {
284 tmp = casemap[*str1++] - casemap[*str2];
285 if (tmp != 0) return(tmp);
286 } while (*str2++ != 0);
287 return 0;
288}
XML_HIDDEN void xmlParserErrors const char const xmlChar const xmlChar * str2
Definition: parser.h:35
XML_HIDDEN void xmlParserErrors const char const xmlChar * str1
Definition: parser.h:35
static const xmlChar casemap[256]
Definition: xmlstring.c:231

Referenced by str_to_dt(), xmlSetDeclaredEncoding(), xmlSwitchInputEncoding(), XSLPattern_OP_IEq(), XSLPattern_OP_IGEq(), XSLPattern_OP_IGt(), XSLPattern_OP_ILEq(), XSLPattern_OP_ILt(), XSLPattern_OP_INEq(), xsltApplyStylesheetInternal(), xsltDocumentElem(), xsltGetHTMLIDs(), xsltParseStylesheetPI(), xsltSaveResultToFd(), xsltSaveResultToFile(), xsltSaveResultToFilename(), and xsltSaveResultToString().

◆ 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 375 of file xmlstring.c.

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

◆ 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}
__forceinline bool __cdecl add(big_integer &x, uint32_t const value)
xmlChar * xmlStrdup(const xmlChar *cur)
Definition: xmlstring.c:69
xmlChar * xmlStrncat(xmlChar *cur, const xmlChar *add, int len)
Definition: xmlstring.c:448

Referenced by do_get_text(), tagName_to_XPath(), XDR_E_AttributeType(), XDR_E_ElementType(), 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 327 of file xmlstring.c.

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

Referenced by xml_write_quotedstring(), xmlBufWriteQuotedString(), xmlParseEntityDecl(), xmlParseEntityRef(), xmlParseNotationDecl(), xmlParsePITarget(), 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 135 of file xmlstring.c.

135 {
136 if (str1 == str2) return(0);
137 if (str1 == NULL) return(-1);
138 if (str2 == NULL) return(1);
139#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
140 return(strcmp((const char *)str1, (const char *)str2));
141#else
142 do {
143 int tmp = *str1++ - *str2;
144 if (tmp != 0) return(tmp);
145 } while (*str2++ != 0);
146 return 0;
147#endif
148}
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3319

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 69 of file xmlstring.c.

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

Referenced by do_get_text(), domelem_getAttribute(), internal_parseBuffer(), tagName_to_XPath(), XDR_E_AttributeType(), XDR_E_ElementType(), xmlAddAttributeDecl(), xmlAddElementDecl(), xmlAddID(), xmlAddNotationDecl(), xmlAddRef(), xmlBuildRelativeURI(), xmlBuildURI(), xmlCanonicPath(), xmlCopyDocElementContent(), xmlCreateEnumeration(), xmlDoRead(), xmlGetDtdElementDesc2(), xmlNewDocElementContent(), xmlNewEntityInputStream(), xmlNewInputFromFile(), xmlParseExternalEntityPrivate(), xmlPathToURI(), xmlSAX2AttributeNs(), xmlSAX2EndDocument(), xmlSAX2StartElementNs(), xmlSAX2Text(), xmlSplitQName(), xmlStrcat(), xmlStrncatNew(), 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 162 of file xmlstring.c.

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

Referenced by cache_free_uri(), cache_from_doc_ns(), cache_type_from_xmlDocPtr(), domattr_get_prefix(), domelem_getAttribute(), domelem_setAttribute(), element_get_dt(), exclPrefixPush(), get_child(), get_child_with_attr(), get_dt_ns(), link_datatypes(), lookup_schema_elemDecl(), node_get_base_name(), node_has_prop(), node_transform_write(), node_transform_write_to_stream(), SAXAttributes_populate(), SchemaCache_get_node_dt(), transform_is_valid_method(), XDR_A_dt_type(), XDR_A_maxOccurs(), XDR_A_required(), XDR_E_attribute(), XDR_E_AttributeType(), XDR_E_element(), XDR_E_ElementType(), XDR_E_group(), XDR_E_Schema(), xmlAddAttributeDecl(), xmlBuildRelativeURI(), xmldoc_unlink_xmldecl(), xmlIsID(), xmlLoadEntityContent(), xmlParseAttribute2(), xmlParseDocument(), xmlParseEntityDecl(), xmlParseEnumerationType(), xmlParseExternalEntityPrivate(), xmlParseNotationType(), xmlParsePI(), xmlParsePITarget(), xmlParseStartTag2(), xmlParseXMLDecl(), xmlSaveUri(), xmlSAX2AttributeDecl(), xmlSAX2AttributeNs(), xmlSAX2StartElementNs(), xmlStrQEqual(), xsltApplyFallbacks(), xsltApplySequenceConstructor(), xsltApplyStylesheetInternal(), xsltApplyXSLTTemplate(), xsltAttribute(), xsltAttributeComp(), xsltAttrListTemplateProcess(), xsltAttrTemplateProcess(), xsltCheckCycle(), 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(), xsltParseStylesheetOutput(), xsltParseStylesheetPreserveSpace(), xsltParseStylesheetProcess(), xsltParseStylesheetStripSpace(), xsltParseStylesheetTop(), xsltParseTemplateContent(), xsltPreprocessStylesheet(), xsltProcessUserParamInternal(), xsltRegisterExtPrefix(), xsltRegisterGlobalVariable(), xsltSaveResultTo(), 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 302 of file xmlstring.c.

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

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 448 of file xmlstring.c.

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

Referenced by tagName_to_XPath(), 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 484 of file xmlstring.c.

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

◆ 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 215 of file xmlstring.c.

215 {
216 if (len <= 0) return(0);
217 if (str1 == str2) return(0);
218 if (str1 == NULL) return(-1);
219 if (str2 == NULL) return(1);
220#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
221 return(strncmp((const char *)str1, (const char *)str2, len));
222#else
223 do {
224 int tmp = *str1++ - *str2;
225 if (tmp != 0 || --len == 0) return(tmp);
226 } while (*str2++ != 0);
227 return 0;
228#endif
229}
_ACRTIMP int __cdecl strncmp(const char *, const char *, size_t)
Definition: string.c:3330

Referenced by domdoc_setProperty(), xmlDetectEBCDIC(), xmlStrstr(), xmlUTF8Charcmp(), xmlUTF8Strloc(), xsltFormatNumberConversion(), and xsltUTF8Charcmp().

◆ xmlStrndup()

◆ xmlStrPrintf()

int 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}
#define va_end(v)
Definition: stdarg.h:28
#define va_start(v, l)
Definition: stdarg.h:26
char * va_list
Definition: vadefs.h:50
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 188 of file xmlstring.c.

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

Referenced by xmlDictFindEntry(), 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 347 of file xmlstring.c.

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

Referenced by xmlCanonicPath(), xsltCheckRead(), 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 403 of file xmlstring.c.

403 {
404 int i;
405
406 if (str == NULL) return(NULL);
407 if (start < 0) return(NULL);
408 if (len < 0) return(NULL);
409
410 for (i = 0;i < start;i++) {
411 if (*str == 0) return(NULL);
412 str++;
413 }
414 if (*str == 0) return(NULL);
415 return(xmlStrndup(str, len));
416}
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}
unsigned char ch[4][2]
Definition: console.c:118
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);
875 if (ret == NULL) {
876 return(NULL);
877 }
878 memcpy(ret, utf, i);
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 231 of file xmlstring.c.

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