File indexing completed on 2024-04-28 12:42:32
0001 /* 0002 SPDX-FileCopyrightText: 2020 Elvis Angelaccio <elvis.angelaccio@kde.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "s3url.h" 0007 0008 S3Url::S3Url(const QUrl &url) 0009 : m_url(url) 0010 {} 0011 0012 bool S3Url::isRoot() const 0013 { 0014 return bucketName().isEmpty() && key().isEmpty(); 0015 } 0016 0017 bool S3Url::isBucket() const 0018 { 0019 return !bucketName().isEmpty() && key().isEmpty(); 0020 } 0021 0022 bool S3Url::isKey() const 0023 { 0024 return !bucketName().isEmpty() && !key().isEmpty(); 0025 } 0026 0027 QString S3Url::bucketName() const 0028 { 0029 return m_url.host(); 0030 } 0031 0032 QString S3Url::key() const 0033 { 0034 return m_url.path(); 0035 } 0036 0037 QString S3Url::prefix() const 0038 { 0039 if (!isKey() || key() == QLatin1String("/")) { 0040 return QString(); 0041 } 0042 0043 QString prefix = key().mid(1); 0044 if (!prefix.endsWith(QLatin1Char('/'))) { 0045 prefix += QLatin1Char('/'); 0046 } 0047 0048 return prefix; 0049 } 0050 0051 QUrl S3Url::url() const 0052 { 0053 return m_url; 0054 } 0055 0056 Aws::String S3Url::BucketName() const 0057 { 0058 // Bucket names can consist only of lowercase letters, numbers, dots and hyphens, so Latin-1 is enough. 0059 const QByteArray bucket = bucketName().toLatin1(); 0060 return Aws::String(bucket.constData(), bucket.size()); 0061 } 0062 0063 Aws::String S3Url::Key() const 0064 { 0065 // The S3 object key name is a sequence of Unicode characters with UTF-8 encoding. 0066 const QByteArray _key = key().toUtf8(); 0067 return Aws::String(_key.constData(), _key.size()); 0068 } 0069 0070 Aws::String S3Url::Prefix() const 0071 { 0072 const QByteArray _prefix = prefix().toUtf8(); 0073 return Aws::String(_prefix.constData(), _prefix.size()); 0074 } 0075 0076 QDebug operator<<(QDebug debug, const S3Url &s3url) 0077 { 0078 QDebugStateSaver stateSaver(debug); 0079 debug.nospace() << s3url.url().toDisplayString() << " (bucket: " << s3url.bucketName() << ", key: " << s3url.key() << ")"; 0080 return debug.maybeSpace(); 0081 } 0082