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