• 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
  • core
  • codecs
octalbytecodec.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Core library, made within the KDE community.
3 
4  Copyright 2004,2011 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 "octalbytecodec.h"
24 
25 // Qt
26 #include <QtCore/QString>
27 
28 
29 namespace Okteta
30 {
31 static const Byte octalDigitsFilledLimit = 32;
32 
33 unsigned int OctalByteCodec::encodingWidth() const { return 3; }
34 Byte OctalByteCodec::digitsFilledLimit() const { return octalDigitsFilledLimit; }
35 
36 
37 void OctalByteCodec::encode( QString& digits, unsigned int pos, Byte byte ) const
38 {
39  digits[pos++] = QLatin1Char( '0'+(byte>>6) );
40  digits[pos++] = QLatin1Char( '0'+((byte>>3)&0x07) );
41  digits[pos] = QLatin1Char( '0'+((byte) &0x07) );
42 }
43 
44 
45 void OctalByteCodec::encodeShort( QString& digits, unsigned int pos, Byte byte ) const
46 {
47  const unsigned char firstDigitValue = byte>>6;
48  if( firstDigitValue > 0 )
49  digits[pos++] = QLatin1Char( '0'+firstDigitValue );
50  const unsigned char secondDigitValue = (byte>>3) & 0x07;
51  if( secondDigitValue > 0 || firstDigitValue > 0 )
52  digits[pos++] = QLatin1Char( '0'+secondDigitValue );
53  const unsigned char lastDigitValue = byte & 0x07;
54  digits[pos] = QLatin1Char( '0'+lastDigitValue );
55 }
56 
57 
58 bool OctalByteCodec::isValidDigit( unsigned char digit ) const
59 {
60  return ('0' <= digit && digit <= '7');
61 }
62 
63 
64 bool OctalByteCodec::turnToValue( unsigned char* digit ) const
65 {
66  if( isValidDigit(*digit) )
67  {
68  *digit -= '0';
69  return true;
70  }
71  return false;
72 }
73 
74 
75 bool OctalByteCodec::appendDigit( Byte* byte, unsigned char digit ) const
76 {
77  if( turnToValue(&digit) )
78  {
79  Byte _byte = *byte;
80  if( _byte < octalDigitsFilledLimit )
81  {
82  _byte <<= 3;
83  _byte += digit;
84  *byte = _byte;
85  return true;
86  }
87  }
88  return false;
89 }
90 
91 
92 void OctalByteCodec::removeLastDigit( Byte* byte ) const
93 {
94  *byte >>= 3;
95 }
96 
97 }
Okteta::OctalByteCodec::digitsFilledLimit
virtual Byte digitsFilledLimit() const
Definition: octalbytecodec.cpp:34
Okteta::OctalByteCodec::removeLastDigit
virtual void removeLastDigit(Byte *byte) const
Tries to remove the last (least significant) digit from byte.
Definition: octalbytecodec.cpp:92
Okteta::Byte
unsigned char Byte
Definition: byte.h:29
Okteta::OctalByteCodec::turnToValue
virtual bool turnToValue(unsigned char *digit) const
Turns the digit into a byte with the value of the digit.
Definition: octalbytecodec.cpp:64
Okteta::OctalByteCodec::isValidDigit
virtual bool isValidDigit(unsigned char digit) const
Checks if the given digit is used in the encoding.
Definition: octalbytecodec.cpp:58
Okteta::OctalByteCodec::encodeShort
virtual void encodeShort(QString &digits, unsigned int pos, Byte byte) const
Encodes the byte and writes the result to digits, no leading 0s.
Definition: octalbytecodec.cpp:45
Okteta::OctalByteCodec::encodingWidth
virtual unsigned int encodingWidth() const
Definition: octalbytecodec.cpp:33
octalbytecodec.h
Okteta::OctalByteCodec::encode
virtual void encode(QString &digits, unsigned int pos, Byte byte) const
Encodes the byte using full coding width, prefixing with 0s if needed, and writes the result to digit...
Definition: octalbytecodec.cpp:37
Okteta::octalDigitsFilledLimit
static const Byte octalDigitsFilledLimit
Definition: octalbytecodec.cpp:31
Okteta::OctalByteCodec::appendDigit
virtual bool appendDigit(Byte *byte, unsigned char digit) const
Tries to increase the byte value by appending a digit to the digits of the current encoding...
Definition: octalbytecodec.cpp:75
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:08 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