diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp')
-rw-r--r-- | Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp | 79 |
1 files changed, 77 insertions, 2 deletions
diff --git a/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp b/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp index af1fb296b..7132edb81 100644 --- a/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp +++ b/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp @@ -28,8 +28,28 @@ #if ENABLE(INDEXED_DATABASE) +#include "IDBKey.h" + namespace WebCore { +IDBKeyRangeData::IDBKeyRangeData(IDBKey* key) + : isNull(!key) + , lowerKey(key) + , upperKey(key) + , lowerOpen(false) + , upperOpen(false) +{ +} + +IDBKeyRangeData::IDBKeyRangeData(const IDBKeyData& keyData) + : isNull(keyData.isNull()) + , lowerKey(keyData) + , upperKey(keyData) + , lowerOpen(false) + , upperOpen(false) +{ +} + IDBKeyRangeData IDBKeyRangeData::isolatedCopy() const { IDBKeyRangeData result; @@ -43,13 +63,68 @@ IDBKeyRangeData IDBKeyRangeData::isolatedCopy() const return result; } -PassRefPtr<IDBKeyRange> IDBKeyRangeData::maybeCreateIDBKeyRange() const +RefPtr<IDBKeyRange> IDBKeyRangeData::maybeCreateIDBKeyRange() const { if (isNull) return nullptr; - return IDBKeyRange::create(lowerKey.maybeCreateIDBKey(), upperKey.maybeCreateIDBKey(), lowerOpen ? IDBKeyRange::LowerBoundOpen : IDBKeyRange::LowerBoundClosed, upperOpen ? IDBKeyRange::UpperBoundOpen : IDBKeyRange::UpperBoundClosed); + return IDBKeyRange::create(lowerKey.maybeCreateIDBKey(), upperKey.maybeCreateIDBKey(), lowerOpen, upperOpen); +} + +bool IDBKeyRangeData::isExactlyOneKey() const +{ + if (isNull || lowerOpen || upperOpen || !upperKey.isValid() || !lowerKey.isValid()) + return false; + + return !lowerKey.compare(upperKey); +} + +bool IDBKeyRangeData::containsKey(const IDBKeyData& key) const +{ + if (lowerKey.isValid()) { + auto compare = lowerKey.compare(key); + if (compare > 0) + return false; + if (lowerOpen && !compare) + return false; + } + if (upperKey.isValid()) { + auto compare = upperKey.compare(key); + if (compare < 0) + return false; + if (upperOpen && !compare) + return false; + } + + return true; +} + +bool IDBKeyRangeData::isValid() const +{ + if (isNull) + return false; + + if (!lowerKey.isValid() && !lowerKey.isNull()) + return false; + + if (!upperKey.isValid() && !upperKey.isNull()) + return false; + + return true; +} + +#if !LOG_DISABLED +String IDBKeyRangeData::loggingString() const +{ + auto result = makeString(lowerOpen ? "( " : "[ ", lowerKey.loggingString(), ", ", upperKey.loggingString(), upperOpen ? " )" : " ]"); + if (result.length() > 400) { + result.truncate(397); + result.append(WTF::ASCIILiteral("...")); + } + + return result; } +#endif } // namespace WebCore |