File indexing completed on 2024-11-24 05:09:40
0001 /* 0002 SPDX-FileCopyrightText: 2001-2004,2009 Otto Bruggeman <bruggie@gmail.com> 0003 SPDX-FileCopyrightText: 2001-2003 John Firebaugh <jfirebaugh@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef KOMPAREDIFF2_DIFFERENCESTRING_P_H 0009 #define KOMPAREDIFF2_DIFFERENCESTRING_P_H 0010 0011 // lib 0012 #include "marker.h" 0013 // Qt 0014 #include <QString> 0015 0016 namespace KompareDiff2 0017 { 0018 0019 class DifferenceStringPrivate 0020 { 0021 public: 0022 DifferenceStringPrivate() = default; 0023 DifferenceStringPrivate(const QString &string, const MarkerList &markerList); 0024 DifferenceStringPrivate(const DifferenceStringPrivate &ds) = default; 0025 0026 ~DifferenceStringPrivate(); 0027 0028 bool operator==(const DifferenceStringPrivate &ks) const; 0029 0030 public: 0031 void calculateHash(); 0032 0033 public: 0034 QString string; 0035 QString conflict; 0036 unsigned int hash; 0037 MarkerList markerList; 0038 }; 0039 0040 inline DifferenceStringPrivate::DifferenceStringPrivate(const QString &string, const MarkerList &markerList) 0041 : string(string) 0042 , markerList(markerList) 0043 { 0044 calculateHash(); 0045 } 0046 0047 inline DifferenceStringPrivate::~DifferenceStringPrivate() 0048 { 0049 qDeleteAll(markerList); 0050 } 0051 0052 inline bool DifferenceStringPrivate::operator==(const DifferenceStringPrivate &ks) const 0053 { 0054 if (hash != ks.hash) { 0055 return false; 0056 } 0057 return (string == ks.string); 0058 } 0059 0060 inline void DifferenceStringPrivate::calculateHash() 0061 { 0062 unsigned short const *str = reinterpret_cast<unsigned short const *>(string.unicode()); 0063 const unsigned int len = string.length(); 0064 0065 hash = 1315423911; 0066 0067 for (unsigned int i = 0; i < len; ++i) { 0068 hash ^= (hash << 5) + str[i] + (hash >> 2); 0069 } 0070 } 0071 0072 } 0073 0074 #endif