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

« back to all changes in this revision

Viewing changes to src/CLucene/document/DateField.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/StdHeader.h"
8
 
 
9
 
#include "DateField.h"
10
 
#include "CLucene/util/Misc.h"
11
 
CL_NS_USE(util)
12
 
CL_NS_DEF(document)
13
 
 
14
 
DateField::~DateField(){
15
 
}
16
 
 
17
 
TCHAR* DateField::timeToString(const int64_t time) {
18
 
    TCHAR* buf = _CL_NEWARRAY(TCHAR,DATEFIELD_DATE_LEN + 1);
19
 
    timeToString(time,buf);
20
 
    return buf;
21
 
}
22
 
void DateField::timeToString(const int64_t time, TCHAR* buf) {
23
 
    CND_PRECONDITION (buf, "buf == NULL");
24
 
    *buf = '\0';
25
 
        if (time < 0)
26
 
          _CLTHROWA (CL_ERR_IllegalArgument,"time too early"); //todo: make richer error
27
 
 
28
 
        if (time > DATEFIELD_DATE_MAX)
29
 
          _CLTHROWA (CL_ERR_IllegalArgument, "time too late (past DATEFIELD_DATE_MAX"); //todo: make richer error
30
 
        
31
 
        _i64tot(time, buf, 36);
32
 
        int32_t bufLen = _tcslen(buf);
33
 
        
34
 
        CND_PRECONDITION (bufLen <= DATEFIELD_DATE_LEN, "timeToString length is greater than 9");
35
 
        
36
 
        /* Supply leading zeroes if necessary. */
37
 
        if (bufLen < DATEFIELD_DATE_LEN) {
38
 
          const int32_t nMissingZeroes = DATEFIELD_DATE_LEN - bufLen;
39
 
          /* Move buffer contents forward to make room for leading zeroes. */
40
 
          for (int32_t i = DATEFIELD_DATE_LEN - 1; i >= nMissingZeroes; i--)
41
 
            buf[i] = buf[i - nMissingZeroes];
42
 
          
43
 
          /* Insert leading zeroes. */
44
 
          {// MSVC6 scoping fix
45
 
          for (int32_t i = 0; i < nMissingZeroes; i++)
46
 
            buf[i] = '0';
47
 
          }
48
 
        
49
 
          buf[DATEFIELD_DATE_LEN] = 0;
50
 
        }
51
 
        
52
 
        CND_PRECONDITION (_tcslen(buf) == DATEFIELD_DATE_LEN, "timeToString return is not equal to DATEFIELD_DATE_LEN");
53
 
}
54
 
 
55
 
int64_t DateField::stringToTime(const TCHAR* time) {
56
 
        TCHAR* end;
57
 
        return _tcstoi64(time, &end, 36);
58
 
}
59
 
 
60
 
CL_NS_END