File: HtWordCodec.h

package info (click to toggle)
htdig 1%3A3.2.0b6-12
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 14,996 kB
  • ctags: 9,373
  • sloc: ansic: 49,626; cpp: 46,470; sh: 20,694; xml: 4,180; perl: 2,543; makefile: 887; php: 79; asm: 14
file content (70 lines) | stat: -rw-r--r-- 2,607 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// HtWordCodec.h
//
// HtWordCodec: Given two lists of pair of "words" 'from' and 'to';
//              simple one-to-one translations, use those lists to translate.
//              Only restriction are that no null (0) characters must be
//              used in "words", and that there is a character "joiner" that
//              does not appear in any word.  One-to-one consistency may be
//              checked at construction.
//
// Part of the ht://Dig package   <http://www.htdig.org/>
// Copyright (c) 1999-2004 The ht://Dig Group
// For copyright details, see the file COPYING in your distribution
// or the GNU Library General Public License (LGPL) version 2 or later 
// <http://www.gnu.org/copyleft/lgpl.html>
//
// $Id: HtWordCodec.h,v 1.6 2004/05/28 13:15:21 lha Exp $
//

#ifndef __HtWordCodec_h
#define __HtWordCodec_h

#include "HtCodec.h"
#include "StringList.h"
#include "StringMatch.h"

class HtWordCodec : public HtCodec
{
public:
  HtWordCodec();
  virtual ~HtWordCodec();

  // Set the lists of asymmetric pairs of "words" in "from" and
  // "to", using:
  // * one list of requested encodings with two consecutive
  //   items "to" and "from" per translation
  // * one list of just words which HtWordCodec will generate
  //   space-saving encodings for.
  // Either may be empty.
  //  Items in frequent_substrings will be silently ignored if
  // they collide with anything in requested_encoding_pairs.
  // CodingError is empty on success, or has a failure message.
  HtWordCodec(StringList &requested_encodings,
              StringList &frequest_substrings, String &errmsg);

  // *Or*, set the lists directly, without checking coding
  // consistency.  HtWordCodec will delete these lists when
  // destroyed.  Not really recommended, but this class would be
  // incomplete without it.
  HtWordCodec (StringList *from, StringList *to, char joiner = char(1));

  // Same as those in the parent class.  Each string to
  // encode/decode may contain zero or more of words from the
  // lists.  Those words will be replaced.
  virtual String encode(const String &uncoded) const;
  virtual String decode(const String &coded) const;

private:
  HtWordCodec(const HtWordCodec &); // Not supposed to be implemented.
  void operator= (const HtWordCodec &); // Not supposed to be implemented.
  StringList *myFrom;
  StringList *myTo;
  StringMatch *myFromMatch;
  StringMatch *myToMatch;

  // Do coding/decoding symmetrically using the provided lookup and lists.
  String code(const String &, StringMatch& match, StringList& replacements) const;
};

#endif /* __HtWordCodec_h */