File indexing completed on 2024-05-05 17:57:59
0001 /* 0002 This file is part of the Okteta Core library, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2014 Friedrich W. H. Kossebau <kossebau@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "usasciicharcodec.hpp" 0010 0011 // lib 0012 #include <character.hpp> 0013 // Qt 0014 #include <QString> 0015 0016 namespace Okteta { 0017 0018 bool USASCIICharCodec::encode(Byte* byte, const QChar& _char) const 0019 { 0020 const int unicodeValue = _char.unicode(); 0021 // not in range? 0022 if (0x007F < unicodeValue) { 0023 return false; 0024 } 0025 0026 *byte = unicodeValue; 0027 0028 return true; 0029 } 0030 0031 Character USASCIICharCodec::decode(Byte byte) const 0032 { 0033 return {QChar(ushort(byte)), (byte > 0x007F)}; 0034 } 0035 0036 bool USASCIICharCodec::canEncode(const QChar& _char) const 0037 { 0038 return (_char.unicode() <= 0x007F); 0039 } 0040 0041 const QString& USASCIICharCodec::name() const 0042 { 0043 return codecName(); 0044 } 0045 0046 const QString& USASCIICharCodec::codecName() 0047 { 0048 static const QString name = QStringLiteral("US-ASCII"); 0049 return name; 0050 } 0051 0052 }