source: git/factory/gf_tabutil.cc @ fbb0173

spielwiese
Last change on this file since fbb0173 was 650f2d8, checked in by Mohamed Barakat <mohamed.barakat@…>, 13 years ago
renamed assert.h -> cf_assert.h in factory
  • Property mode set to 100644
File size: 984 bytes
RevLine 
[493c477]1/* emacs edit mode for this file is -*- C++ -*- */
[341696]2/* $Id$ */
[2dd068]3
[84250a6]4#include <config.h>
5
[650f2d8]6#include "cf_assert.h"
[84250a6]7
[2dd068]8#include "cf_defs.h"
9#include "gf_tabutil.h"
10
11int gf_tab_numdigits62 ( int q )
12{
13    if ( q < 62 )
[806c18]14        return 1;
[2dd068]15    else  if ( q < 62*62 )
[806c18]16        return 2;
[2dd068]17    else
[806c18]18        return 3;
[2dd068]19}
20
21char conv62 ( int i )
22{
23    if ( i < 10 )
[806c18]24        return '0' + char(i);
[2dd068]25    else  if ( i < 36 )
[806c18]26        return 'A' + char(i-10);
[2dd068]27    else
[806c18]28        return 'a' + char(i-36);
[2dd068]29}
30
31void convert62 ( int i, int n, char * p )
32{
33    for ( int j = n-1; j >= 0; j-- ) {
[806c18]34        p[j] = conv62( i % 62 );
35        i /= 62;
[2dd068]36    }
37}
38
39int convback62 ( char c )
40{
41    if ( c >= '0' && c <= '9' )
[806c18]42        return int(c) - int('0');
[2dd068]43    else  if ( c >= 'A' && c <= 'Z' )
[806c18]44        return int(c) - int('A') + 10;
[2dd068]45    else
[806c18]46        return int(c) - int('a') + 36;
[2dd068]47}
48
49int convertback62 ( char * p, int n )
50{
51    int r = 0;
52    for ( int j = 0; j < n; j++ )
[806c18]53        r = r * 62 + convback62( p[j] );
[2dd068]54    return r;
55}
Note: See TracBrowser for help on using the repository browser.