Tesseract  3.02
tesseract-ocr/ccutil/unicharmap.h
Go to the documentation of this file.
00001 
00002 // File:        unicharmap.h
00003 // Description: Unicode character/ligature to integer id class.
00004 // Author:      Thomas Kielbus
00005 // Created:     Wed Jun 28 17:05:01 PDT 2006
00006 //
00007 // (C) Copyright 2006, Google Inc.
00008 // Licensed under the Apache License, Version 2.0 (the "License");
00009 // you may not use this file except in compliance with the License.
00010 // You may obtain a copy of the License at
00011 // http://www.apache.org/licenses/LICENSE-2.0
00012 // Unless required by applicable law or agreed to in writing, software
00013 // distributed under the License is distributed on an "AS IS" BASIS,
00014 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 // See the License for the specific language governing permissions and
00016 // limitations under the License.
00017 //
00019 
00020 #ifndef TESSERACT_CCUTIL_UNICHARMAP_H__
00021 #define TESSERACT_CCUTIL_UNICHARMAP_H__
00022 
00023 #include "unichar.h"
00024 
00025 // A UNICHARMAP stores unique unichars. Each of them is associated with one
00026 // UNICHAR_ID.
00027 class UNICHARMAP {
00028  public:
00029 
00030   // Create an empty UNICHARMAP
00031   UNICHARMAP();
00032 
00033   ~UNICHARMAP();
00034 
00035   // Insert the given unichar represention in the UNICHARMAP and associate it
00036   // with the given id. The length of the representation MUST be non-zero.
00037   void insert(const char* const unichar_repr, UNICHAR_ID id);
00038 
00039   // Return the id associated with the given unichar representation,
00040   // this representation MUST exist within the UNICHARMAP.
00041   // The length of the representation MUST be non-zero.
00042   UNICHAR_ID unichar_to_id(const char* const unichar_repr) const;
00043 
00044   // Return the id associated with the given unichar representation,
00045   // this representation MUST exist within the UNICHARMAP. The first
00046   // length characters (maximum) from unichar_repr are used. The length
00047   // MUST be non-zero.
00048   UNICHAR_ID unichar_to_id(const char* const unichar_repr, int length) const;
00049 
00050   // Return true if the given unichar representation is already present in the
00051   // UNICHARMAP. The length of the representation MUST be non-zero.
00052   bool contains(const char* const unichar_repr) const;
00053 
00054   // Return true if the given unichar representation is already present in the
00055   // UNICHARMAP. The first length characters (maximum) from unichar_repr are
00056   // used. The length MUST be non-zero.
00057   bool contains(const char* const unichar_repr, int length) const;
00058 
00059   // Return the minimum number of characters that must be used from this string
00060   // to obtain a match in the UNICHARMAP.
00061   int minmatch(const char* const unichar_repr) const;
00062 
00063   // Clear the UNICHARMAP. All previous data is lost.
00064   void clear();
00065 
00066  private:
00067 
00068   // The UNICHARMAP is represented as a tree whose nodes are of type
00069   // UNICHARMAP_NODE.
00070   struct UNICHARMAP_NODE {
00071 
00072     UNICHARMAP_NODE();
00073     ~UNICHARMAP_NODE();
00074 
00075     UNICHARMAP_NODE* children;
00076     UNICHAR_ID id;
00077   };
00078 
00079   UNICHARMAP_NODE* nodes;
00080 };
00081 
00082 #endif  // TESSERACT_CCUTIL_UNICHARMAP_H__