1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * Pierre Phaneuf <pp@ludusdesign.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
38 #include "nsICharsetConverterManager.h"
40 #include "nsISupports.h"
41 #include "nsIComponentManager.h"
42 #include "nsIServiceManager.h"
43 #include "nsIUnicodeDecoder.h"
44 #include "nsIUnicodeEncoder.h"
48 #if defined(XP_WIN) || defined(XP_OS2)
55 //---------------------------------------------------------------------------
59 "#ifndef nsCyrillicClass_h__\n"
60 "#define nsCyrillicClass_h__\n"
61 "/* PLEASE DO NOT EDIT THIS FILE DIRECTLY. THIS FILE IS GENERATED BY \n"
62 " GenCyrllicClass found in mozilla/intl/chardet/tools\n"
66 //---------------------------------------------------------------------------
71 //---------------------------------------------------------------------------
75 "/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */\n"
76 "/* ***** BEGIN LICENSE BLOCK *****\n"
77 " * Version: MPL 1.1/GPL 2.0/LGPL 2.1\n"
79 " * The contents of this file are subject to the Mozilla Public License Version\n"
80 " * 1.1 (the \"License\"); you may not use this file except in compliance with\n"
81 " * the License. You may obtain a copy of the License at\n"
82 " * http://www.mozilla.org/MPL/\n"
84 " * Software distributed under the License is distributed on an \"AS IS\" basis,\n"
85 " * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License\n"
86 " * for the specific language governing rights and limitations under the\n"
89 " * The Original Code is mozilla.org code.\n"
91 " * The Initial Developer of the Original Code is\n"
92 " * Netscape Communications Corporation.\n"
93 " * Portions created by the Initial Developer are Copyright (C) 2001\n"
94 " * the Initial Developer. All Rights Reserved.\n"
96 " * Contributor(s):\n"
98 " * Alternatively, the contents of this file may be used under the terms of\n"
99 " * either the GNU General Public License Version 2 or later (the \"GPL\"), or\n"
100 " * the GNU Lesser General Public License Version 2.1 or later (the \"LGPL\"),\n"
101 " * in which case the provisions of the GPL or the LGPL are applicable instead\n"
102 " * of those above. If you wish to allow use of your version of this file only\n"
103 " * under the terms of either the GPL or the LGPL, and not to allow others to\n"
104 " * use your version of this file under the terms of the MPL, indicate your\n"
105 " * decision by deleting the provisions above and replace them with the notice\n"
106 " * and other provisions required by the GPL or the LGPL. If you do not delete\n"
107 " * the provisions above, a recipient may use your version of this file under\n"
108 " * the terms of any one of the MPL, the GPL or the LGPL.\n"
110 " * ***** END LICENSE BLOCK ***** */\n";
113 //---------------------------------------------------------------------------
114 static nsIUnicodeEncoder
* gKOI8REncoder
= nsnull
;
115 static nsICharsetConverterManager
* gCCM
= nsnull
;
117 //---------------------------------------------------------------------------
118 PRUint8
CyrillicClass(nsIUnicodeDecoder
* decoder
, PRUint8 byte
)
125 nsresult res
= decoder
->Convert((char*)&byte
, &blen
, ubuf
, &ulen
);
126 if(NS_SUCCEEDED(res
) && (1 == ulen
))
128 ubuf
[0] = nsCRT::ToUpper(ubuf
[0]);
130 res
= gKOI8REncoder
->Convert(ubuf
,&ulen
,(char*)bbuf
,&blen
);
131 if(NS_SUCCEEDED(res
) && (1 == blen
))
135 return bbuf
[0] - (PRUint8
)0xdf;
141 //---------------------------------------------------------------------------
142 void genCyrillicClass(const char* name
, const char* charset
)
144 nsIUnicodeDecoder
*decoder
= nsnull
;
145 nsresult res
= NS_OK
;
146 nsAutoString
str(charset
);
147 res
= gCCM
->GetUnicodeDecoder(&str
, &decoder
);
150 printf("cannot locate %s Decoder\n", charset
);
153 printf("static const PRUint8 %sMap [128] = {\n",name
);
155 for(i
=0x80;i
!=0x00;i
+=0x10)
159 PRUint8 cls
= CyrillicClass(decoder
, i
+j
);
160 printf(" %2d, ",cls
);
165 NS_IF_RELEASE(decoder
);
167 //---------------------------------------------------------------------------
170 int main(int argc
, char** argv
) {
171 nsresult res
= nsnull
;
173 nsCOMPtr
<nsICharsetConverterManager
> gCCM
= do_GetService(kCharsetConverterManagerCID
, &res
);
175 if(NS_FAILED(res
) && (nsnull
!= gCCM
))
177 printf("cannot locate CharsetConverterManager\n");
180 nsAutoString
koi8r("KOI8-R");
181 res
= gCCM
->GetUnicodeEncoder(&koi8r
,&gKOI8REncoder
);
182 if(NS_FAILED(res
) && (nsnull
!= gKOI8REncoder
))
184 printf("cannot locate KOI8-R Encoder\n");
192 genCyrillicClass("KOI8", "KOI8-R");
193 genCyrillicClass("CP1251", "windows-1251");
194 genCyrillicClass("IBM866", "IBM866");
195 genCyrillicClass("ISO88595", "ISO-8859-5");
196 genCyrillicClass("MacCyrillic", "x-mac-cyrillic");
198 NS_IF_RELEASE(gKOI8REncoder
);