IDBKeyRangeData.cpp [plain text]
#include "config.h"
#include "IDBKeyRangeData.h"
#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;
result.isNull = isNull;
result.lowerKey = lowerKey.isolatedCopy();
result.upperKey = upperKey.isolatedCopy();
result.lowerOpen = lowerOpen;
result.upperOpen = upperOpen;
return result;
}
RefPtr<IDBKeyRange> IDBKeyRangeData::maybeCreateIDBKeyRange() const
{
if (isNull)
return nullptr;
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("..."_s);
}
return result;
}
#endif
}
#endif // ENABLE(INDEXED_DATABASE)