source: git/factory/gf_tabutil.cc @ 9f7665

spielwiese
Last change on this file since 9f7665 was 9f7665, checked in by Oleksandr Motsak <motsak@…>, 10 years ago
Removed HAVE_CONFIG guards fix: fixed the inclusion of configure-generated *config.h's
  • Property mode set to 100644
File size: 975 bytes
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2
3
4#include "config.h"
5
6
7#include "cf_assert.h"
8
9#include "cf_defs.h"
10#include "gf_tabutil.h"
11
12int gf_tab_numdigits62 ( int q )
13{
14    if ( q < 62 )
15        return 1;
16    else  if ( q < 62*62 )
17        return 2;
18    else
19        return 3;
20}
21
22char conv62 ( int i )
23{
24    if ( i < 10 )
25        return '0' + char(i);
26    else  if ( i < 36 )
27        return 'A' + char(i-10);
28    else
29        return 'a' + char(i-36);
30}
31
32void convert62 ( int i, int n, char * p )
33{
34    for ( int j = n-1; j >= 0; j-- ) {
35        p[j] = conv62( i % 62 );
36        i /= 62;
37    }
38}
39
40int convback62 ( char c )
41{
42    if ( c >= '0' && c <= '9' )
43        return int(c) - int('0');
44    else  if ( c >= 'A' && c <= 'Z' )
45        return int(c) - int('A') + 10;
46    else
47        return int(c) - int('a') + 36;
48}
49
50int convertback62 ( char * p, int n )
51{
52    int r = 0;
53    for ( int j = 0; j < n; j++ )
54        r = r * 62 + convback62( p[j] );
55    return r;
56}
Note: See TracBrowser for help on using the repository browser.