FreeBSD/contrib/subversion/subversion/libsvn_subr/utf.c
/* Convert SRC_LENGTH bytes of SRC_DATA in NODE->handle, store the result
   in *DEST, which is allocated in POOL. */
Convert SRC_LENGTH bytes of SRC_DATA in NODE->handle, store the result
in *DEST, which is allocated in POOL.
Convert SRC_LENGTH bytes of SRC_DATA in NODE - > handle store the result in * DEST which is allocated in POOL .
static svn_error_t *
convert_to_stringbuf(xlate_handle_node_t *node,
                     const char *src_data,
                     apr_size_t src_length,
                     svn_stringbuf_t **dest,
                     apr_pool_t *pool)
{
#ifdef WIN32
  apr_status_t apr_err;
  apr_err = svn_subr__win32_xlate_to_stringbuf(node->handle, src_data,
                                               src_length, dest, pool);
#else
  apr_size_t buflen = src_length * 2;
  apr_status_t apr_err;
  apr_size_t srclen = src_length;
  apr_size_t destlen = buflen;
  *dest = svn_stringbuf_create_ensure(buflen + 1, pool);
  if (src_length == 0)
    return SVN_NO_ERROR;
  do
    {
      destlen = buflen - (*dest)->len;
      apr_err = apr_xlate_conv_buffer(node->handle,
                                      src_data + (src_length - srclen),
                                      &srclen,
                                      (*dest)->data + (*dest)->len,
                                      &destlen);
      (*dest)->len += ((buflen - (*dest)->len) - destlen);
      buflen += srclen * 3; 
    } while (apr_err == APR_SUCCESS && srclen != 0);
#endif
  if (apr_err)
    {
      const char *errstr;
      svn_error_t *err;
      if (node->frompage == SVN_APR_LOCALE_CHARSET)
        errstr = apr_psprintf
          (pool, _("Can't convert string from native encoding to '%s':"),
           node->topage);
      else if (node->topage == SVN_APR_LOCALE_CHARSET)
        errstr = apr_psprintf
          (pool, _("Can't convert string from '%s' to native encoding:"),
           node->frompage);
      else
        errstr = apr_psprintf
          (pool, _("Can't convert string from '%s' to '%s':"),
           node->frompage, node->topage);
      err = svn_error_create(
          apr_err, NULL, svn_utf__fuzzy_escape(src_data, src_length, pool));
      return svn_error_create(apr_err, err, errstr);
    }
  (*dest)->data[(*dest)->len] = '\0';
  return SVN_NO_ERROR;
}
static svn_error_t * convert_to_stringbuf ( xlate_handle_node_t * node , const char * src_data , apr_size_t src_length , svn_stringbuf_t * * dest , apr_pool_t * pool ) { #ifdef WIN32 apr_status_t apr_err ; apr_err = svn_subr__win32_xlate_to_stringbuf ( node -> handle , src_data , src_length , dest , pool ) ; #else apr_size_t buflen = src_length * 2 ; apr_status_t apr_err ; apr_size_t srclen = src_length ; apr_size_t destlen = buflen ; * dest = svn_stringbuf_create_ensure ( buflen + 1 , pool ) ; if ( src_length == 0 ) return SVN_NO_ERROR ; do { destlen = buflen - ( * dest ) -> len ; apr_err = apr_xlate_conv_buffer ( node -> handle , src_data + ( src_length - srclen ) , & srclen , ( * dest ) -> data + ( * dest ) -> len , & destlen ) ; ( * dest ) -> len += ( ( buflen - ( * dest ) -> len ) - destlen ) ; buflen += srclen * 3 ; } while ( apr_err == APR_SUCCESS && srclen != 0 ) ; #endif if ( apr_err ) { const char * errstr ; svn_error_t * err ; if ( node -> frompage == SVN_APR_LOCALE_CHARSET ) errstr = apr_psprintf ( pool , _ ( " " ) , node -> topage ) ; else if ( node -> topage == SVN_APR_LOCALE_CHARSET ) errstr = apr_psprintf ( pool , _ ( " " ) , node -> frompage ) ; else errstr = apr_psprintf ( pool , _ ( " " ) , node -> frompage , node -> topage ) ; err = svn_error_create ( apr_err , NULL , svn_utf__fuzzy_escape ( src_data , src_length , pool ) ) ; return svn_error_create ( apr_err , err , errstr ) ; } ( * dest ) -> data [ ( * dest ) -> len ] = ' \0 ' ; return SVN_NO_ERROR ; }
Convert SRC_LENGTH bytes of SRC_DATA in NODE->handle, store the result
in *DEST, which is allocated in POOL.
Convert SRC_LENGTH bytes of SRC_DATA in NODE - > handle store the result in * DEST which is allocated in POOL .
/* Initialize *DEST to an empty stringbuf.
     A 1:2 ratio of input bytes to output bytes (as assigned above)
     should be enough for most translations, and if it turns out not
     to be enough, we'll grow the buffer again, sizing it based on a
     1:3 ratio of the remainder of the string. */ /* Not only does it not make sense to convert an empty string, but
     apr-iconv is quite unreasonable about not allowing that. */ /* Set up state variables for xlate. */ /* Attempt the conversion. */ /* Now, update the *DEST->len to track the amount of output data
         churned out so far from this loop. */ /* 3 is middle ground, 2 wasn't enough
                               for all characters in the buffer, 4 is
                               maximum character size (currently) */ /* If we exited the loop with an error, return the error. */ /* Can't use svn_error_wrap_apr here because it calls functions in
         this file, leading to infinite recursion. */ /* Else, exited due to success.  Trim the result buffer down to the
     right length. */