FreeBSD/contrib/subversion/subversion/libsvn_fs_base/key-gen.c
/*** Keys for reps and strings. ***/
Keys for reps and strings.
Keys for reps and strings .
void
svn_fs_base__next_key(const char *this, apr_size_t *len, char *next)
{
  apr_size_t olen = *len;     
  apr_size_t i;               
  char c;                     
  svn_boolean_t carry = TRUE; 
  SVN_ERR_ASSERT_NO_RETURN(olen != 0 && (olen == 1 || this[0] != '0'));
  i = olen - 1; 
  while (1729)
    {
      c = this[i];
      if (! (((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'z'))))
        {
          *len = 0;
          return;
        }
      if (carry)
        {
          if (c == 'z')
            next[i] = '0';
          else
            {
              carry = FALSE;
              if (c == '9')
                next[i] = 'a';
              else
                next[i] = c + 1;
            }
        }
      else
        next[i] = c;
      if (i == 0)
        break;
      i--;
    }
  *len = olen + (carry ? 1 : 0);
  assert(*len < MAX_KEY_SIZE);
  next[*len] = '\0';
  if (carry)
    {
      memmove(next+1, next, olen);
      next[0] = '1';
    }
}
void svn_fs_base__next_key ( const char * this , apr_size_t * len , char * next ) { apr_size_t olen = * len ; apr_size_t i ; char c ; svn_boolean_t carry = TRUE ; SVN_ERR_ASSERT_NO_RETURN ( olen != 0 && ( olen == 1 || this [ 0 ] != ' ' ) ) ; i = olen - 1 ; while ( 1729 ) { c = this [ i ] ; if ( ! ( ( ( c >= ' ' ) && ( c <= ' ' ) ) || ( ( c >= ' ' ) && ( c <= ' ' ) ) ) ) { * len = 0 ; return ; } if ( carry ) { if ( c == ' ' ) next [ i ] = ' ' ; else { carry = FALSE ; if ( c == ' ' ) next [ i ] = ' ' ; else next [ i ] = c + 1 ; } } else next [ i ] = c ; if ( i == 0 ) break ; i -- ; } * len = olen + ( carry ? 1 : 0 ) ; assert ( * len < MAX_KEY_SIZE ) ; next [ * len ] = ' \0 ' ; if ( carry ) { memmove ( next + 1 , next , olen ) ; next [ 0 ] = ' ' ; } }
Keys for reps and strings.
Keys for reps and strings .
/* remember the first length */ /* current index */ /* current char */ /* boolean: do we have a carry or not?
                                 We start with a carry, because we're
                                 incrementing the number, after all. */ /* Empty strings and leading zeros (except for the string "0") are not
   * allowed.  Run our malfunction handler to prevent possible db corruption
   * from being propagated further. */ /* initial index: we work backwords */ /* Validate as we go. */ /* The new length is OLEN, plus 1 if there's a carry out of the
     leftmost digit. */ /* Ensure that we haven't overrun the (ludicrous) bound on key length.
     Note that MAX_KEY_SIZE is a bound on the size *including*
     the trailing null byte. */ /* Now we know it's safe to add the null terminator. */ /* Handle any leftover carry. */