blob: 246d66c8093e8bf4f9c7f216657add3ff3b2b0fe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
/*------------------------------------------------------------------------------
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
*
* Distributable under the terms of either the Apache License (Version 2.0) or
* the GNU Lesser General Public License, as specified in the COPYING file.
------------------------------------------------------------------------------*/
#include "CLucene/StdHeader.h"
int64_t lucene_tcstoi64(const TCHAR* str, TCHAR**end, int radix){
#define LUCENE_TCSTOI64_RADIX(x,r) ((x>=_T('0') && x<=_T('9'))?x-_T('0'):((x>=_T('a') && x<=_T('z'))?x-_T('a')+10:((x>=_T('A') && x<=_T('Z'))?x-_T('A')+10:1000)))
if (radix < 2 || radix > 36)
return 0;
/* Skip white space. */
while (_istspace (*str))
++str;
int sign=1;
if ( str[0] == _T('+') )
str++;
else if ( str[0] == _T('-') ){
sign = -1;
str++;
}
*end=(TCHAR*)str;
long r = -1;
while ( (r=LUCENE_TCSTOI64_RADIX(*end[0],radix)) >=0 && r<radix )
(*end)++;
TCHAR* p = (*end)-1;
int64_t ret = 0;
int pos = 0;
for ( ;p>=str;p-- ){
int i=LUCENE_TCSTOI64_RADIX(p[0],radix);
if ( pos == 0 )
ret=i;
else
ret += (int64_t)pow((qreal)radix,(qreal)pos) * i; //todo: might be quicker with a different pow overload
pos++;
}
return sign*ret;
}
|