summaryrefslogtreecommitdiff
path: root/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp')
-rw-r--r--Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp79
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