~ubuntu-branches/ubuntu/raring/clucene-core/raring-proposed

« back to all changes in this revision

Viewing changes to src/core/CLucene/document/NumberTools.cpp

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2012-08-11 09:33:38 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20120811093338-fgrx41ftqew3qt6a
Tags: 2.3.3.4-1
* New upstream release (Closes: #661703).
* Convert package to multiarch.
* Drop obsolete patches:
  - 01_add_missing_include_bug505667.diff
  - 02_posixness_fix_bug530308.diff
* Add patches:
  - Fixing_ZLIB_configuration_in_shared_CMakeLists.patch
  - Fix-pkgconfig-file-by-adding-clucene-shared-library.patch
  - Install-contribs-lib.patch
  - multiarch.patch
* Update debian/compat: bump to 8.
* Update debian/control:
  - update build dependencies (add cmake, libboost-dev and libz-dev).
  - bump Standards-Version to 3.9.3.
  - rename packages due to ABI bump: libclucene0ldbl -> libclucene-core1.
  - add libclucene-contribs1 package.
* Update debian/rules:
  - rewrite to use CMake.
  - add multiarch support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*------------------------------------------------------------------------------
 
2
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
 
3
*
 
4
* Distributable under the terms of either the Apache License (Version 2.0) or
 
5
* the GNU Lesser General Public License, as specified in the COPYING file.
 
6
------------------------------------------------------------------------------*/
 
7
#include "CLucene/_ApiHeader.h"
 
8
 
 
9
#include "NumberTools.h"
 
10
#include "CLucene/util/Misc.h"
 
11
 
 
12
CL_NS_DEF(document)
 
13
 
 
14
const TCHAR* NumberTools::MIN_STRING_VALUE = NEGATIVE_PREFIX _T("0000000000000");
 
15
const TCHAR* NumberTools::MAX_STRING_VALUE = POSITIVE_PREFIX _T("1y2p0ij32e8e7");
 
16
 
 
17
TCHAR* NumberTools::longToString(int64_t l)
 
18
{
 
19
        if (l == LUCENE_INT64_MIN_SHOULDBE) {
 
20
                // special case, because long is not symetric around zero
 
21
                return stringDuplicate(MIN_STRING_VALUE);
 
22
        }
 
23
 
 
24
        TCHAR* buf = _CL_NEWARRAY(TCHAR, STR_SIZE + 1);
 
25
        if (l < 0) {
 
26
                buf[0] = NEGATIVE_PREFIX[0];
 
27
                l = LUCENE_INT64_MAX_SHOULDBE + l + 1;
 
28
        } else {
 
29
                buf[0] = POSITIVE_PREFIX[0];
 
30
        }
 
31
 
 
32
        TCHAR tmp[STR_SIZE];
 
33
        _i64tot(l, tmp, NUMBERTOOLS_RADIX);
 
34
        size_t len = _tcslen(tmp);
 
35
        _tcscpy(buf+(STR_SIZE-len),tmp);
 
36
        for ( size_t i=1;i<STR_SIZE-len;i++ )
 
37
                buf[i] = (int)'0';
 
38
 
 
39
        buf[STR_SIZE] = 0;
 
40
 
 
41
        return buf;
 
42
}
 
43
 
 
44
int64_t NumberTools::stringToLong(const TCHAR* str) {
 
45
        if (str == NULL) {
 
46
                _CLTHROWA(CL_ERR_NullPointer,"string cannot be null");
 
47
        }
 
48
        if (_tcslen(str) != STR_SIZE) {
 
49
                _CLTHROWA(CL_ERR_NumberFormat,"string is the wrong size");
 
50
        }
 
51
 
 
52
        if (_tcscmp(str, MIN_STRING_VALUE) == 0) {
 
53
                return LUCENE_INT64_MIN_SHOULDBE;
 
54
        }
 
55
 
 
56
        TCHAR prefix = str[0];
 
57
 
 
58
        TCHAR* sentinel = NULL;
 
59
        int64_t l = _tcstoi64(++str, &sentinel, NUMBERTOOLS_RADIX);
 
60
 
 
61
        if (prefix == POSITIVE_PREFIX[0]) {
 
62
                // nop
 
63
        } else if (prefix == NEGATIVE_PREFIX[0]) {
 
64
                l = l - LUCENE_INT64_MAX_SHOULDBE - 1;
 
65
        } else {
 
66
                _CLTHROWA(CL_ERR_NumberFormat,"string does not begin with the correct prefix");
 
67
        }
 
68
 
 
69
        return l;
 
70
}
 
71
 
 
72
NumberTools::~NumberTools(){
 
73
}
 
74
 
 
75
CL_NS_END