/src/libwpd/src/lib/WP3Part.cpp
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ |
2 | | /* libwpd |
3 | | * Version: MPL 2.0 / LGPLv2.1+ |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * Major Contributor(s): |
10 | | * Copyright (C) 2004 Marc Maurer (uwog@uwog.net) |
11 | | * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch) |
12 | | * |
13 | | * For minor contributions see the git repository. |
14 | | * |
15 | | * Alternatively, the contents of this file may be used under the terms |
16 | | * of the GNU Lesser General Public License Version 2.1 or later |
17 | | * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are |
18 | | * applicable instead of those above. |
19 | | * |
20 | | * For further information visit http://libwpd.sourceforge.net |
21 | | */ |
22 | | |
23 | | /* "This product is not manufactured, approved, or supported by |
24 | | * Corel Corporation or Corel Corporation Limited." |
25 | | */ |
26 | | |
27 | | #include "WP3Part.h" |
28 | | #include "WP3VariableLengthGroup.h" |
29 | | #include "WP3FixedLengthGroup.h" |
30 | | #include "WP3SingleByteFunction.h" |
31 | | #include "libwpd_internal.h" |
32 | | |
33 | | // constructPart: constructs a parseable low-level representation of part of the document |
34 | | // returns the part if it successfully creates the part, returns 0 if it can't |
35 | | // throws an exception if there is an error |
36 | | // precondition: readVal is between 0xC0 and 0xEF |
37 | | WP3Part *WP3Part::constructPart(librevenge::RVNGInputStream *input, WPXEncryption *encryption, const unsigned char readVal) |
38 | 0 | { |
39 | 0 | WPD_DEBUG_MSG(("WordPerfect: ConstructPart for group 0x%x\n", readVal)); |
40 | |
|
41 | 0 | if (readVal >= (unsigned char)0x80 && readVal <= (unsigned char)0xBF) |
42 | 0 | { |
43 | | // single-byte function |
44 | 0 | WPD_DEBUG_MSG(("WordPerfect: constructSingleByteFunction(input, val)\n")); |
45 | 0 | return WP3SingleByteFunction::constructSingleByteFunction(input, encryption, readVal); |
46 | 0 | } |
47 | 0 | else if (readVal >= (unsigned char)0xC0 && readVal <= (unsigned char)0xCF) |
48 | 0 | { |
49 | | // fixed length multi-byte function |
50 | |
|
51 | 0 | if (!WP3FixedLengthGroup::isGroupConsistent(input, encryption, readVal)) |
52 | 0 | { |
53 | 0 | WPD_DEBUG_MSG(("WordPerfect: Consistency Check (fixed length) failed; ignoring this byte\n")); |
54 | 0 | return nullptr; |
55 | 0 | } |
56 | 0 | WPD_DEBUG_MSG(("WordPerfect: constructFixedLengthGroup(input, val)\n")); |
57 | 0 | return WP3FixedLengthGroup::constructFixedLengthGroup(input, encryption, readVal); |
58 | 0 | } |
59 | 0 | else if (readVal >= (unsigned char)0xD0 && readVal <= (unsigned char)0xEF) |
60 | 0 | { |
61 | | // variable length multi-byte function |
62 | |
|
63 | 0 | if (!WP3VariableLengthGroup::isGroupConsistent(input, encryption, readVal)) |
64 | 0 | { |
65 | 0 | WPD_DEBUG_MSG(("WordPerfect: Consistency Check (variable length) failed; ignoring this byte\n")); |
66 | 0 | return nullptr; |
67 | 0 | } |
68 | 0 | WPD_DEBUG_MSG(("WordPerfect: constructVariableLengthGroup(input, val)\n")); |
69 | 0 | return WP3VariableLengthGroup::constructVariableLengthGroup(input, encryption, readVal); |
70 | 0 | } |
71 | | |
72 | 0 | WPD_DEBUG_MSG(("WordPerfect: Returning 0 from constructPart\n")); |
73 | 0 | return nullptr; |
74 | 0 | } |
75 | | /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |