1/* -*- C++ -*-
2 SPDX-FileCopyrightText: 1998 Netscape Communications Corporation <developer@mozilla.org>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#ifndef nsHebrewProber_h__
8#define nsHebrewProber_h__
9
10#include "nsSBCharSetProber.h"
11namespace kencodingprober
12{
13// This prober doesn't actually recognize a language or a charset.
14// It is a helper prober for the use of the Hebrew model probers
15class KCODECS_NO_EXPORT nsHebrewProber : public nsCharSetProber
16{
17public:
18 nsHebrewProber(void)
19 : mLogicalProb(nullptr)
20 , mVisualProb(nullptr)
21 {
22 Reset();
23 }
24
25 ~nsHebrewProber(void) override
26 {
27 }
28 nsProbingState HandleData(const char *aBuf, unsigned int aLen) override;
29 const char *GetCharSetName() override;
30 void Reset(void) override;
31
32 nsProbingState GetState(void) override;
33
34 float GetConfidence(void) override
35 {
36 return (float)0.0;
37 }
38 void SetOpion() override
39 {
40 }
41
42 void SetModelProbers(nsCharSetProber *logicalPrb, nsCharSetProber *visualPrb)
43 {
44 mLogicalProb = logicalPrb;
45 mVisualProb = visualPrb;
46 }
47
48#ifdef DEBUG_PROBE
49 void DumpStatus() override;
50#endif
51
52protected:
53 static bool isFinal(char c);
54 static bool isNonFinal(char c);
55
56 int mFinalCharLogicalScore, mFinalCharVisualScore;
57
58 // The two last characters seen in the previous buffer.
59 char mPrev, mBeforePrev;
60
61 // These probers are owned by the group prober.
62 nsCharSetProber *mLogicalProb, *mVisualProb;
63};
64}
65
66/**
67 * ** General ideas of the Hebrew charset recognition **
68 *
69 * Four main charsets exist in Hebrew:
70 * "ISO-8859-8" - Visual Hebrew
71 * "windows-1255" - Logical Hebrew
72 * "ISO-8859-8-I" - Logical Hebrew
73 * "x-mac-hebrew" - ?? Logical Hebrew ??
74 *
75 * Both "ISO" charsets use a completely identical set of code points, whereas
76 * "windows-1255" and "x-mac-hebrew" are two different proper supersets of
77 * these code points. windows-1255 defines additional characters in the range
78 * 0x80-0x9F as some misc punctuation marks as well as some Hebrew-specific
79 * diacritics and additional 'Yiddish' ligature letters in the range 0xc0-0xd6.
80 * x-mac-hebrew defines similar additional code points but with a different
81 * mapping.
82 *
83 * As far as an average Hebrew text with no diacritics is concerned, all four
84 * charsets are identical with respect to code points. Meaning that for the
85 * main Hebrew alphabet, all four map the same values to all 27 Hebrew letters
86 * (including final letters).
87 *
88 * The dominant difference between these charsets is their directionality.
89 * "Visual" directionality means that the text is ordered as if the renderer is
90 * not aware of a BIDI rendering algorithm. The renderer sees the text and
91 * draws it from left to right. The text itself when ordered naturally is read
92 * backwards. A buffer of Visual Hebrew generally looks like so:
93 * "[last word of first line spelled backwards] [whole line ordered backwards
94 * and spelled backwards] [first word of first line spelled backwards]
95 * [end of line] [last word of second line] ... etc' "
96 * adding punctuation marks, numbers and English text to visual text is
97 * naturally also "visual" and from left to right.
98 *
99 * "Logical" directionality means the text is ordered "naturally" according to
100 * the order it is read. It is the responsibility of the renderer to display
101 * the text from right to left. A BIDI algorithm is used to place general
102 * punctuation marks, numbers and English text in the text.
103 *
104 * Texts in x-mac-hebrew are almost impossible to find on the Internet. From
105 * what little evidence I could find, it seems that its general directionality
106 * is Logical.
107 *
108 * To sum up all of the above, the Hebrew probing mechanism knows about two
109 * charsets:
110 * Visual Hebrew - "ISO-8859-8" - backwards text - Words and sentences are
111 * backwards while line order is natural. For charset recognition purposes
112 * the line order is unimportant (In fact, for this implementation, even
113 * word order is unimportant).
114 * Logical Hebrew - "windows-1255" - normal, naturally ordered text.
115 *
116 * "ISO-8859-8-I" is a subset of windows-1255 and doesn't need to be
117 * specifically identified.
118 * "x-mac-hebrew" is also identified as windows-1255. A text in x-mac-hebrew
119 * that contain special punctuation marks or diacritics is displayed with
120 * some unconverted characters showing as question marks. This problem might
121 * be corrected using another model prober for x-mac-hebrew. Due to the fact
122 * that x-mac-hebrew texts are so rare, writing another model prober isn't
123 * worth the effort and performance hit.
124 *
125 * *** The Prober ***
126 *
127 * The prober is divided between two nsSBCharSetProbers and an nsHebrewProber,
128 * all of which are managed, created, fed data, inquired and deleted by the
129 * nsSBCSGroupProber. The two nsSBCharSetProbers identify that the text is in
130 * fact some kind of Hebrew, Logical or Visual. The final decision about which
131 * one is it is made by the nsHebrewProber by combining final-letter scores
132 * with the scores of the two nsSBCharSetProbers to produce a final answer.
133 *
134 * The nsSBCSGroupProber is responsible for stripping the original text of HTML
135 * tags, English characters, numbers, low-ASCII punctuation characters, spaces
136 * and new lines. It reduces any sequence of such characters to a single space.
137 * The buffer fed to each prober in the SBCS group prober is pure text in
138 * high-ASCII.
139 * The two nsSBCharSetProbers (model probers) share the same language model:
140 * Win1255Model.
141 * The first nsSBCharSetProber uses the model normally as any other
142 * nsSBCharSetProber does, to recognize windows-1255, upon which this model was
143 * built. The second nsSBCharSetProber is told to make the pair-of-letter
144 * lookup in the language model backwards. This in practice exactly simulates
145 * a visual Hebrew model using the windows-1255 logical Hebrew model.
146 *
147 * The nsHebrewProber is not using any language model. All it does is look for
148 * final-letter evidence suggesting the text is either logical Hebrew or visual
149 * Hebrew. Disjointed from the model probers, the results of the nsHebrewProber
150 * alone are meaningless. nsHebrewProber always returns 0.00 as confidence
151 * since it never identifies a charset by itself. Instead, the pointer to the
152 * nsHebrewProber is passed to the model probers as a helper "Name Prober".
153 * When the Group prober receives a positive identification from any prober,
154 * it asks for the name of the charset identified. If the prober queried is a
155 * Hebrew model prober, the model prober forwards the call to the
156 * nsHebrewProber to make the final decision. In the nsHebrewProber, the
157 * decision is made according to the final-letters scores maintained and Both
158 * model probers scores. The answer is returned in the form of the name of the
159 * charset identified, either "windows-1255" or "ISO-8859-8".
160 *
161 */
162#endif /* nsHebrewProber_h__ */
163

source code of kcodecs/src/probers/nsHebrewProber.h