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 | * Changes are Copyright(C) 2007, 2008 by Nokia Corporation and/or its subsidiary(-ies), all rights reserved. |
8 | */ |
9 | #ifndef _lucene_util_Misc_H |
10 | #define _lucene_util_Misc_H |
11 | |
12 | #if defined(_LUCENE_PRAGMA_ONCE) |
13 | # pragma once |
14 | #endif |
15 | |
16 | #include <QtCore/QString> |
17 | |
18 | CL_NS_DEF(util) |
19 | |
20 | class Misc |
21 | { |
22 | public: |
23 | static uint64_t currentTimeMillis(); |
24 | |
25 | static size_t ahashCode(const char* str); |
26 | static size_t ahashCode(const char* str, size_t len); |
27 | static char* ajoin(const char* a, const char* b, const char* c = NULL, |
28 | const char* d = NULL, const char* e = NULL, const char* f = NULL); |
29 | static char* segmentname(const char* segment, const char* ext, int32_t x = -1); |
30 | static void segmentname(char* buffer, int32_t bufferLen, const char* segment, |
31 | const char* ext, int32_t x = -1); |
32 | |
33 | static size_t qhashCode(const QString& str); |
34 | static size_t qhashCode(const QString& str, size_t len); |
35 | static QString qjoin(const QString& a, const QString& b, |
36 | const QString& c = QString(), const QString& d = QString(), |
37 | const QString& e = QString(), const QString& f = QString()); |
38 | static QString segmentname(const QString& segment, const QString& ext, |
39 | int32_t x = -1 ); |
40 | static void segmentname(QString& buffer, int32_t bufferLen, |
41 | const QString& Segment, const QString& ext, int32_t x = -1); |
42 | |
43 | // Compares two strings, character by character, and returns the |
44 | // first position where the two strings differ from one another. |
45 | // |
46 | // @param s1 The first string to compare |
47 | // @param s1Len The length of the first string to compare |
48 | // @param s2 The second string to compare |
49 | // @param s2Len The length of the second string to compare |
50 | // @return The first position where the two strings differ. |
51 | static int32_t stringDifference(const TCHAR* s1, int32_t s1Len, |
52 | const TCHAR* s2, int32_t s2Len); |
53 | static TCHAR* join (const TCHAR* a, const TCHAR* b, const TCHAR* c = NULL, |
54 | const TCHAR* d = NULL, const TCHAR* e = NULL, const TCHAR* f = NULL ); |
55 | |
56 | #ifdef _UCS2 |
57 | static size_t whashCode(const wchar_t* str); |
58 | static size_t whashCode(const wchar_t* str, size_t len); |
59 | |
60 | # define thashCode whashCode |
61 | |
62 | static char* _wideToChar(const wchar_t* s CL_FILELINEPARAM); |
63 | static void _cpywideToChar(const wchar_t* s, char* d, size_t len); |
64 | |
65 | static wchar_t* _charToWide(const char* s CL_FILELINEPARAM); |
66 | static void _cpycharToWide(const char* s, wchar_t* d, size_t len); |
67 | |
68 | #else |
69 | # define thashCode ahashCode |
70 | #endif |
71 | }; |
72 | |
73 | CL_NS_END |
74 | |
75 | #endif |
76 | |