Diff for /embedaddon/libxml2/triostr.c between versions 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 2012/02/21 23:37:58 version 1.1.1.2, 2014/06/15 19:53:28
Line 165  TRIO_ARGS1((string), Line 165  TRIO_ARGS1((string),
 #if !defined(TRIO_MINIMAL)  #if !defined(TRIO_MINIMAL)
 /**  /**
    Append @p source at the end of @p target.     Append @p source at the end of @p target.
   
    @param target Target string.     @param target Target string.
    @param source Source string.     @param source Source string.
    @return Boolean value indicating success or failure.     @return Boolean value indicating success or failure.
   
    @pre @p target must point to a memory chunk with sufficient room to     @pre @p target must point to a memory chunk with sufficient room to
    contain the @p target string and @p source string.     contain the @p target string and @p source string.
    @pre No boundary checking is performed, so insufficient memory will     @pre No boundary checking is performed, so insufficient memory will
Line 184  TRIO_ARGS2((target, source), Line 184  TRIO_ARGS2((target, source),
 {  {
   assert(target);    assert(target);
   assert(source);    assert(source);
  
   return (strcat(target, source) != NULL);    return (strcat(target, source) != NULL);
 }  }
 #endif /* !defined(TRIO_MINIMAL) */  #endif /* !defined(TRIO_MINIMAL) */
Line 192  TRIO_ARGS2((target, source), Line 192  TRIO_ARGS2((target, source),
 #if !defined(TRIO_MINIMAL)  #if !defined(TRIO_MINIMAL)
 /**  /**
    Append at most @p max characters from @p source to @p target.     Append at most @p max characters from @p source to @p target.
   
    @param target Target string.     @param target Target string.
    @param max Maximum number of characters to append.     @param max Maximum number of characters to append.
    @param source Source string.     @param source Source string.
    @return Boolean value indicating success or failure.     @return Boolean value indicating success or failure.
   
    @pre @p target must point to a memory chuck with sufficient room to     @pre @p target must point to a memory chuck with sufficient room to
    contain the @p target string and the @p source string (at most @p max     contain the @p target string and the @p source string (at most @p max
    characters).     characters).
Line 213  TRIO_ARGS3((target, max, source), Line 213  TRIO_ARGS3((target, max, source),
            TRIO_CONST char *source)             TRIO_CONST char *source)
 {  {
   size_t length;    size_t length;
  
   assert(target);    assert(target);
   assert(source);    assert(source);
   
   length = trio_length(target);    length = trio_length(target);
  
   if (max > length)    if (max > length)
     {      {
       strncat(target, source, max - length - 1);        strncat(target, source, max - length - 1);
Line 244  TRIO_ARGS2((string, substring), Line 244  TRIO_ARGS2((string, substring),
 {  {
   assert(string);    assert(string);
   assert(substring);    assert(substring);
  
   return (0 != strstr(string, substring));    return (0 != strstr(string, substring));
 }  }
 #endif /* !defined(TRIO_MINIMAL) */  #endif /* !defined(TRIO_MINIMAL) */
Line 253  TRIO_ARGS2((string, substring), Line 253  TRIO_ARGS2((string, substring),
 #if !defined(TRIO_MINIMAL)  #if !defined(TRIO_MINIMAL)
 /**  /**
    Copy @p source to @p target.     Copy @p source to @p target.
   
    @param target Target string.     @param target Target string.
    @param source Source string.     @param source Source string.
    @return Boolean value indicating success or failure.     @return Boolean value indicating success or failure.
   
    @pre @p target must point to a memory chunk with sufficient room to     @pre @p target must point to a memory chunk with sufficient room to
    contain the @p source string.     contain the @p source string.
    @pre No boundary checking is performed, so insufficient memory will     @pre No boundary checking is performed, so insufficient memory will
Line 272  TRIO_ARGS2((target, source), Line 272  TRIO_ARGS2((target, source),
 {  {
   assert(target);    assert(target);
   assert(source);    assert(source);
     
   (void)strcpy(target, source);    (void)strcpy(target, source);
   return TRUE;    return TRUE;
 }  }
Line 281  TRIO_ARGS2((target, source), Line 281  TRIO_ARGS2((target, source),
   
 /**  /**
    Copy at most @p max characters from @p source to @p target.     Copy at most @p max characters from @p source to @p target.
   
    @param target Target string.     @param target Target string.
    @param max Maximum number of characters to append.     @param max Maximum number of characters to append.
    @param source Source string.     @param source Source string.
    @return Boolean value indicating success or failure.     @return Boolean value indicating success or failure.
   
    @pre @p target must point to a memory chunk with sufficient room to     @pre @p target must point to a memory chunk with sufficient room to
    contain the @p source string (at most @p max characters).     contain the @p source string (at most @p max characters).
    @pre No boundary checking is performed, so insufficient memory will     @pre No boundary checking is performed, so insufficient memory will
Line 336  TRIO_ARGS2((source, size), Line 336  TRIO_ARGS2((source, size),
   
 /**  /**
    Duplicate @p source.     Duplicate @p source.
   
    @param source Source string.     @param source Source string.
    @return A copy of the @p source string.     @return A copy of the @p source string.
   
    @post @p target will be zero terminated.     @post @p target will be zero terminated.
 */  */
 TRIO_STRING_PUBLIC char *  TRIO_STRING_PUBLIC char *
Line 354  TRIO_ARGS1((source), Line 354  TRIO_ARGS1((source),
 #if !defined(TRIO_MINIMAL)  #if !defined(TRIO_MINIMAL)
 /**  /**
    Duplicate at most @p max characters of @p source.     Duplicate at most @p max characters of @p source.
   
    @param source Source string.     @param source Source string.
    @param max Maximum number of characters to duplicate.     @param max Maximum number of characters to duplicate.
    @return A copy of the @p source string.     @return A copy of the @p source string.
   
    @post @p target will be zero terminated.     @post @p target will be zero terminated.
 */  */
 TRIO_STRING_PUBLIC char *  TRIO_STRING_PUBLIC char *
Line 383  trio_duplicate_max TRIO_ARGS2((source, max), Line 383  trio_duplicate_max TRIO_ARGS2((source, max),
   
 /**  /**
    Compare if two strings are equal.     Compare if two strings are equal.
   
    @param first First string.     @param first First string.
    @param second Second string.     @param second Second string.
    @return Boolean indicating whether the two strings are equal or not.     @return Boolean indicating whether the two strings are equal or not.
   
    Case-insensitive comparison.     Case-insensitive comparison.
 */  */
 TRIO_STRING_PUBLIC int  TRIO_STRING_PUBLIC int
Line 422  TRIO_ARGS2((first, second), Line 422  TRIO_ARGS2((first, second),
   
 /**  /**
    Compare if two strings are equal.     Compare if two strings are equal.
   
    @param first First string.     @param first First string.
    @param second Second string.     @param second Second string.
    @return Boolean indicating whether the two strings are equal or not.     @return Boolean indicating whether the two strings are equal or not.
   
    Case-sensitive comparison.     Case-sensitive comparison.
 */  */
 TRIO_STRING_PUBLIC int  TRIO_STRING_PUBLIC int
Line 449  TRIO_ARGS2((first, second), Line 449  TRIO_ARGS2((first, second),
 #if !defined(TRIO_MINIMAL)  #if !defined(TRIO_MINIMAL)
 /**  /**
    Compare if two strings up until the first @p max characters are equal.     Compare if two strings up until the first @p max characters are equal.
   
    @param first First string.     @param first First string.
    @param max Maximum number of characters to compare.     @param max Maximum number of characters to compare.
    @param second Second string.     @param second Second string.
    @return Boolean indicating whether the two strings are equal or not.     @return Boolean indicating whether the two strings are equal or not.
   
    Case-sensitive comparison.     Case-sensitive comparison.
 */  */
 TRIO_STRING_PUBLIC int  TRIO_STRING_PUBLIC int
Line 478  TRIO_ARGS3((first, max, second), Line 478  TRIO_ARGS3((first, max, second),
   
 /**  /**
    Compare if two strings are equal.     Compare if two strings are equal.
   
    @param first First string.     @param first First string.
    @param second Second string.     @param second Second string.
    @return Boolean indicating whether the two strings are equal or not.     @return Boolean indicating whether the two strings are equal or not.
Line 504  TRIO_ARGS2((first, second), Line 504  TRIO_ARGS2((first, second),
   
 /**  /**
    Compare if two strings up until the first @p max characters are equal.     Compare if two strings up until the first @p max characters are equal.
   
    @param first First string.     @param first First string.
    @param max Maximum number of characters to compare.     @param max Maximum number of characters to compare.
    @param second Second string.     @param second Second string.
    @return Boolean indicating whether the two strings are equal or not.     @return Boolean indicating whether the two strings are equal or not.
   
    Case-insensitive comparison.     Case-insensitive comparison.
 */  */
 TRIO_STRING_PUBLIC int  TRIO_STRING_PUBLIC int
Line 558  TRIO_ARGS1((error_number), Line 558  TRIO_ARGS1((error_number),
            int error_number)             int error_number)
 {  {
 #if defined(USE_STRERROR)  #if defined(USE_STRERROR)
  
   return strerror(error_number);    return strerror(error_number);
   
 #elif defined(USE_SYS_ERRLIST)  #elif defined(USE_SYS_ERRLIST)
Line 569  TRIO_ARGS1((error_number), Line 569  TRIO_ARGS1((error_number),
   return ((error_number < 0) || (error_number >= sys_nerr))    return ((error_number < 0) || (error_number >= sys_nerr))
     ? "unknown"      ? "unknown"
     : sys_errlist[error_number];      : sys_errlist[error_number];
 
 #else  #else
  
   return "unknown";    return "unknown";
  
 #endif  #endif
 }  }
   
Line 603  TRIO_ARGS4((target, max, format, datetime), Line 603  TRIO_ARGS4((target, max, format, datetime),
   assert(format);    assert(format);
   assert(datetime);    assert(datetime);
   assert(max > 0);    assert(max > 0);
  
   return strftime(target, max, format, datetime);    return strftime(target, max, format, datetime);
 }  }
 #endif /* !defined(TRIO_MINIMAL) */  #endif /* !defined(TRIO_MINIMAL) */
Line 630  TRIO_ARGS2((string, type), Line 630  TRIO_ARGS2((string, type),
   char ch;    char ch;
   
   assert(string);    assert(string);
  
   switch (type)    switch (type)
     {      {
     case TRIO_HASH_PLAIN:      case TRIO_HASH_PLAIN:
Line 719  TRIO_ARGS1((target), Line 719  TRIO_ARGS1((target),
    @return Boolean value indicating success or failure.     @return Boolean value indicating success or failure.
   
    Case-insensitive comparison.     Case-insensitive comparison.
   
    The following wildcards can be used     The following wildcards can be used
    @li @c * Match any number of characters.     @li @c * Match any number of characters.
    @li @c ? Match a single character.     @li @c ? Match a single character.
Line 732  TRIO_ARGS2((string, pattern), Line 732  TRIO_ARGS2((string, pattern),
 {  {
   assert(string);    assert(string);
   assert(pattern);    assert(pattern);
  
   for (; ('*' != *pattern); ++pattern, ++string)    for (; ('*' != *pattern); ++pattern, ++string)
     {      {
       if (NIL == *string)        if (NIL == *string)
Line 757  TRIO_ARGS2((string, pattern), Line 757  TRIO_ARGS2((string, pattern),
         }          }
     }      }
   while (*string++);    while (*string++);
  
   return FALSE;    return FALSE;
 }  }
 #endif /* !defined(TRIO_MINIMAL) */  #endif /* !defined(TRIO_MINIMAL) */
Line 772  TRIO_ARGS2((string, pattern), Line 772  TRIO_ARGS2((string, pattern),
    @return Boolean value indicating success or failure.     @return Boolean value indicating success or failure.
   
    Case-sensitive comparison.     Case-sensitive comparison.
   
    The following wildcards can be used     The following wildcards can be used
    @li @c * Match any number of characters.     @li @c * Match any number of characters.
    @li @c ? Match a single character.     @li @c ? Match a single character.
Line 785  TRIO_ARGS2((string, pattern), Line 785  TRIO_ARGS2((string, pattern),
 {  {
   assert(string);    assert(string);
   assert(pattern);    assert(pattern);
  
   for (; ('*' != *pattern); ++pattern, ++string)    for (; ('*' != *pattern); ++pattern, ++string)
     {      {
       if (NIL == *string)        if (NIL == *string)
Line 810  TRIO_ARGS2((string, pattern), Line 810  TRIO_ARGS2((string, pattern),
         }          }
     }      }
   while (*string++);    while (*string++);
  
   return FALSE;    return FALSE;
 }  }
 #endif /* !defined(TRIO_MINIMAL) */  #endif /* !defined(TRIO_MINIMAL) */
Line 837  TRIO_ARGS3((target, source, Function), Line 837  TRIO_ARGS3((target, source, Function),
   assert(target);    assert(target);
   assert(source);    assert(source);
   assert(Function);    assert(Function);
  
   while (*source != NIL)    while (*source != NIL)
     {      {
       *target++ = Function(*source++);        *target++ = Function(*source++);
Line 894  TRIO_ARGS3((string, max, substring), Line 894  TRIO_ARGS3((string, max, substring),
   
   assert(string);    assert(string);
   assert(substring);    assert(substring);
  
   size = trio_length(substring);    size = trio_length(substring);
   if (size <= max)    if (size <= max)
     {      {
Line 929  TRIO_ARGS2((string, delimiters), Line 929  TRIO_ARGS2((string, delimiters),
            TRIO_CONST char *delimiters)             TRIO_CONST char *delimiters)
 {  {
   assert(delimiters);    assert(delimiters);
  
   return strtok(string, delimiters);    return strtok(string, delimiters);
 }  }
 #endif /* !defined(TRIO_MINIMAL) */  #endif /* !defined(TRIO_MINIMAL) */
Line 1064  TRIO_ARGS2((source, endp), Line 1064  TRIO_ARGS2((source, endp),
             }              }
         }          }
     }      }
  
   value = integer + fraction;    value = integer + fraction;
   if (exponent != 0)    if (exponent != 0)
     {      {
Line 1146  TRIO_ARGS3((string, endp, base), Line 1146  TRIO_ARGS3((string, endp, base),
 {  {
   assert(string);    assert(string);
   assert((base >= 2) && (base <= 36));    assert((base >= 2) && (base <= 36));
  
   return strtol(string, endp, base);    return strtol(string, endp, base);
 }  }
   
Line 1164  TRIO_ARGS1((source), Line 1164  TRIO_ARGS1((source),
            int source)             int source)
 {  {
 #if defined(USE_TOLOWER)  #if defined(USE_TOLOWER)
  
   return tolower(source);    return tolower(source);
  
 #else  #else
   
   /* Does not handle locales or non-contiguous alphabetic characters */    /* Does not handle locales or non-contiguous alphabetic characters */
   return ((source >= (int)'A') && (source <= (int)'Z'))    return ((source >= (int)'A') && (source <= (int)'Z'))
     ? source - 'A' + 'a'      ? source - 'A' + 'a'
     : source;      : source;
  
 #endif  #endif
 }  }
 #endif /* !defined(TRIO_MINIMAL) */  #endif /* !defined(TRIO_MINIMAL) */
Line 1195  TRIO_ARGS3((string, endp, base), Line 1195  TRIO_ARGS3((string, endp, base),
 {  {
   assert(string);    assert(string);
   assert((base >= 2) && (base <= 36));    assert((base >= 2) && (base <= 36));
  
   return strtoul(string, endp, base);    return strtoul(string, endp, base);
 }  }
 #endif /* !defined(TRIO_MINIMAL) */  #endif /* !defined(TRIO_MINIMAL) */
Line 1213  TRIO_ARGS1((source), Line 1213  TRIO_ARGS1((source),
            int source)             int source)
 {  {
 #if defined(USE_TOUPPER)  #if defined(USE_TOUPPER)
  
   return toupper(source);    return toupper(source);
  
 #else  #else
   
   /* Does not handle locales or non-contiguous alphabetic characters */    /* Does not handle locales or non-contiguous alphabetic characters */
   return ((source >= (int)'a') && (source <= (int)'z'))    return ((source >= (int)'a') && (source <= (int)'z'))
     ? source - 'a' + 'A'      ? source - 'a' + 'A'
     : source;      : source;
  
 #endif  #endif
 }  }
   
Line 1266  TRIO_STRING_PRIVATE trio_string_t * Line 1266  TRIO_STRING_PRIVATE trio_string_t *
 TrioStringAlloc(TRIO_NOARGS)  TrioStringAlloc(TRIO_NOARGS)
 {  {
   trio_string_t *self;    trio_string_t *self;
  
   self = (trio_string_t *)TRIO_MALLOC(sizeof(trio_string_t));    self = (trio_string_t *)TRIO_MALLOC(sizeof(trio_string_t));
   if (self)    if (self)
     {      {
Line 1297  TRIO_ARGS2((self, delta), Line 1297  TRIO_ARGS2((self, delta),
   new_size = (delta == 0)    new_size = (delta == 0)
     ? ( (self->allocated == 0) ? 1 : self->allocated * 2 )      ? ( (self->allocated == 0) ? 1 : self->allocated * 2 )
     : self->allocated + delta;      : self->allocated + delta;
  
   new_content = (char *)TRIO_REALLOC(self->content, new_size);    new_content = (char *)TRIO_REALLOC(self->content, new_size);
   if (new_content)    if (new_content)
     {      {
Line 1334  TRIO_ARGS2((self, length), Line 1334  TRIO_ARGS2((self, length),
 #if !defined(TRIO_MINIMAL)  #if !defined(TRIO_MINIMAL)
 /**  /**
    Create a new dynamic string.     Create a new dynamic string.
   
    @param initial_size Initial size of the buffer.     @param initial_size Initial size of the buffer.
    @return Newly allocated dynamic string, or NULL if memory allocation failed.     @return Newly allocated dynamic string, or NULL if memory allocation failed.
 */  */
Line 1367  TRIO_ARGS1((initial_size), Line 1367  TRIO_ARGS1((initial_size),
   
 /**  /**
    Deallocate the dynamic string and its contents.     Deallocate the dynamic string and its contents.
   
    @param self Dynamic string     @param self Dynamic string
 */  */
 TRIO_STRING_PUBLIC void  TRIO_STRING_PUBLIC void
Line 1376  TRIO_ARGS1((self), Line 1376  TRIO_ARGS1((self),
            trio_string_t *self)             trio_string_t *self)
 {  {
   assert(self);    assert(self);
  
   if (self)    if (self)
     {      {
       trio_destroy(self->content);        trio_destroy(self->content);
Line 1388  TRIO_ARGS1((self), Line 1388  TRIO_ARGS1((self),
 #if !defined(TRIO_MINIMAL)  #if !defined(TRIO_MINIMAL)
 /**  /**
    Get a pointer to the content.     Get a pointer to the content.
   
    @param self Dynamic string.     @param self Dynamic string.
    @param offset Offset into content.     @param offset Offset into content.
    @return Pointer to the content.     @return Pointer to the content.
   
    @p Offset can be zero, positive, or negative. If @p offset is zero,     @p Offset can be zero, positive, or negative. If @p offset is zero,
    then the start of the content will be returned. If @p offset is positive,     then the start of the content will be returned. If @p offset is positive,
    then a pointer to @p offset number of characters from the beginning of the     then a pointer to @p offset number of characters from the beginning of the
Line 1407  TRIO_ARGS2((self, offset), Line 1407  TRIO_ARGS2((self, offset),
            int offset)             int offset)
 {  {
   char *result = NULL;    char *result = NULL;
  
   assert(self);    assert(self);
   
   if (self->content != NULL)    if (self->content != NULL)
Line 1440  TRIO_ARGS2((self, offset), Line 1440  TRIO_ARGS2((self, offset),
   
 /**  /**
    Extract the content.     Extract the content.
   
    @param self Dynamic String     @param self Dynamic String
    @return Content of dynamic string.     @return Content of dynamic string.
   
    The content is removed from the dynamic string. This enables destruction     The content is removed from the dynamic string. This enables destruction
    of the dynamic string without deallocation of the content.     of the dynamic string without deallocation of the content.
 */  */
Line 1453  TRIO_ARGS1((self), Line 1453  TRIO_ARGS1((self),
            trio_string_t *self)             trio_string_t *self)
 {  {
   char *result;    char *result;
  
   assert(self);    assert(self);
   
   result = self->content;    result = self->content;
Line 1467  TRIO_ARGS1((self), Line 1467  TRIO_ARGS1((self),
 #if !defined(TRIO_MINIMAL)  #if !defined(TRIO_MINIMAL)
 /**  /**
    Set the content of the dynamic string.     Set the content of the dynamic string.
   
    @param self Dynamic String     @param self Dynamic String
    @param buffer The new content.     @param buffer The new content.
   
    Sets the content of the dynamic string to a copy @p buffer.     Sets the content of the dynamic string to a copy @p buffer.
    An existing content will be deallocated first, if necessary.     An existing content will be deallocated first, if necessary.
   
    @remark     @remark
    This function will make a copy of @p buffer.     This function will make a copy of @p buffer.
    You are responsible for deallocating @p buffer yourself.     You are responsible for deallocating @p buffer yourself.
Line 1521  TRIO_ARGS1((self), Line 1521  TRIO_ARGS1((self),
 #if !defined(TRIO_MINIMAL)  #if !defined(TRIO_MINIMAL)
 /**  /**
    Append the second string to the first.     Append the second string to the first.
   
    @param self Dynamic string to be modified.     @param self Dynamic string to be modified.
    @param other Dynamic string to copy from.     @param other Dynamic string to copy from.
    @return Boolean value indicating success or failure.     @return Boolean value indicating success or failure.
Line 1533  TRIO_ARGS2((self, other), Line 1533  TRIO_ARGS2((self, other),
            trio_string_t *other)             trio_string_t *other)
 {  {
   size_t length;    size_t length;
  
   assert(self);    assert(self);
   assert(other);    assert(other);
   
Line 1543  TRIO_ARGS2((self, other), Line 1543  TRIO_ARGS2((self, other),
   trio_copy(&self->content[self->length], other->content);    trio_copy(&self->content[self->length], other->content);
   self->length = length;    self->length = length;
   return TRUE;    return TRUE;
  
  error:   error:
   return FALSE;    return FALSE;
 }  }
Line 1561  TRIO_ARGS2((self, other), Line 1561  TRIO_ARGS2((self, other),
            TRIO_CONST char *other)             TRIO_CONST char *other)
 {  {
   size_t length;    size_t length;
  
   assert(self);    assert(self);
   assert(other);    assert(other);
   
Line 1571  TRIO_ARGS2((self, other), Line 1571  TRIO_ARGS2((self, other),
   trio_copy(&self->content[self->length], other);    trio_copy(&self->content[self->length], other);
   self->length = length;    self->length = length;
   return TRUE;    return TRUE;
  
  error:   error:
   return FALSE;    return FALSE;
 }  }
Line 1597  TRIO_ARGS2((self, character), Line 1597  TRIO_ARGS2((self, character),
   self->content[self->length] = character;    self->content[self->length] = character;
   self->length++;    self->length++;
   return TRUE;    return TRUE;
  
  error:   error:
   return FALSE;    return FALSE;
 }  }
Line 1606  TRIO_ARGS2((self, character), Line 1606  TRIO_ARGS2((self, character),
 #if !defined(TRIO_MINIMAL)  #if !defined(TRIO_MINIMAL)
 /**  /**
    Search for the first occurrence of second parameter in the first.     Search for the first occurrence of second parameter in the first.
   
    @param self Dynamic string to be modified.     @param self Dynamic string to be modified.
    @param other Dynamic string to copy from.     @param other Dynamic string to copy from.
    @return Boolean value indicating success or failure.     @return Boolean value indicating success or failure.
Line 1691  TRIO_ARGS1((other), Line 1691  TRIO_ARGS1((other),
            trio_string_t *other)             trio_string_t *other)
 {  {
   trio_string_t *self;    trio_string_t *self;
  
   assert(other);    assert(other);
   
   self = TrioStringAlloc();    self = TrioStringAlloc();
Line 1722  TRIO_ARGS1((other), Line 1722  TRIO_ARGS1((other),
            TRIO_CONST char *other)             TRIO_CONST char *other)
 {  {
   trio_string_t *self;    trio_string_t *self;
  
   assert(other);    assert(other);
   
   self = TrioStringAlloc();    self = TrioStringAlloc();

Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>