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