• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • kasten
  • controllers
  • view
  • poddecoder
  • typecodecs
utf8codec.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Kasten module, made within the KDE community.
3 
4  Copyright 2009 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "utf8codec.h"
24 
25 // tool
26 #include "../types/utf8.h"
27 #include "../poddata.h"
28 // KDE
29 #include <KLocale>
30 // Qt
31 #include <QtCore/QTextCodec>
32 
33 
34 namespace Okteta
35 {
36 static const unsigned char PrimitivesDefaultUndefinedChar = '?';
37 
38 
39 Utf8Codec::Utf8Codec()
40  : AbstractTypeCodec( i18nc("@label:textbox","UTF-8") ),
41  mUtf8Codec( QTextCodec::codecForName( "UTF-8" ) )
42 {}
43 
44 QVariant Utf8Codec::value( const PODData& data, int* byteCount ) const
45 {
46  // UTF-8
47  // interpreted as a sequence of bytes, there is no endian problem
48  // source: http://unicode.org/faq/utf_bom.html#3
49  const QChar replacementChar( QChar::ReplacementCharacter );
50  const char* originalData = (const char*)data.originalData();
51  const int maxUtf8DataSize = data.size();
52 
53  QString utf8;
54  bool isUtf8 = false;
55  *byteCount = 0;
56  for( int i=1; i<=maxUtf8DataSize; ++i )
57  {
58  utf8 = mUtf8Codec->toUnicode( originalData, i );
59  if( utf8.size() == 1 && utf8[0] != replacementChar )
60  {
61  isUtf8 = true;
62  *byteCount = i;
63  break;
64  }
65  }
66 
67  return isUtf8 ? QVariant::fromValue<Utf8>( Utf8(utf8[0]) ) : QVariant();
68 }
69 
70 QByteArray Utf8Codec::valueToBytes( const QVariant& value ) const
71 {
72  const QChar valueChar = value.value<Utf8>().value;
73 
74  return mUtf8Codec->fromUnicode( valueChar );
75 }
76 
77 bool Utf8Codec::areEqual( const QVariant& value, QVariant& otherValue ) const
78 {
79  return ( value.value<Utf8>().value == otherValue.value<Utf8>().value );
80 }
81 
82 Utf8Codec::~Utf8Codec() {}
83 
84 }
Okteta::AbstractTypeCodec
Definition: abstracttypecodec.h:38
Okteta::PODData::originalData
const Byte * originalData() const
Definition: poddata.cpp:45
Okteta::Utf8Codec::mUtf8Codec
QTextCodec * mUtf8Codec
Definition: utf8codec.h:49
Utf8::value
QChar value
Definition: utf8.h:41
Okteta::PODData
Definition: poddata.h:34
Okteta::Utf8Codec::~Utf8Codec
virtual ~Utf8Codec()
Definition: utf8codec.cpp:82
utf8codec.h
Okteta::Utf8Codec::areEqual
virtual bool areEqual(const QVariant &value, QVariant &otherValue) const
Definition: utf8codec.cpp:77
Utf8
Definition: utf8.h:31
Okteta::PODData::size
int size() const
Definition: poddata.cpp:48
Okteta::Utf8Codec::value
virtual QVariant value(const PODData &data, int *byteCount) const
Definition: utf8codec.cpp:44
Okteta::Utf8Codec::Utf8Codec
Utf8Codec()
Definition: utf8codec.cpp:39
Okteta::PrimitivesDefaultUndefinedChar
static const unsigned char PrimitivesDefaultUndefinedChar
Definition: utf8codec.cpp:36
Okteta::Utf8Codec::valueToBytes
virtual QByteArray valueToBytes(const QVariant &value) const
Definition: utf8codec.cpp:70
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal