xref: /aoo41x/main/idl/source/cmptools/char.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_idl.hxx"
30 
31 /****************** I N C L U D E S **************************************/
32 #include <ctype.h>
33 #include <string.h>
34 
35 #ifndef _TABLE_HXX //autogen
36 #include <tools/table.hxx>
37 #endif
38 
39 #include <char.hxx>
40 
41 /****************** D A T E N ********************************************/
42 static unsigned char EqualTab[ 256 ] = {
43   0,   1,   2,   3,   4,   5,   6,   7,   8,   9,
44  10,  11,  12,  13,  14,  15,  16,  17,  18,  19,
45  20,  21,  22,  23,  24,  25,  26,  27,  28,  29,
46  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,
47  40,  41,  42,  43,  44,  45,  46,  47,  48,  49,
48  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,
49  60,  61,  62,  63,  64,  65,  66,  67,  68,  69,
50  70,  71,  72,  73,  74,  75,  76,  77,  78,  79,
51  80,  81,  82,  83,  84,  85,  86,  87,  88,  89,
52  90,  91,  92,  93,  94,  95,  96,  97,  98,  99,
53 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
54 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
55 120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
56 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
57 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
58 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
59 160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
60 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
61 180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
62 190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
63 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
64 210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
65 220, 221, 222, 223, 224, 225, 226, 227, 228, 229,
66 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
67 240, 241, 242, 243, 244, 245, 246, 247, 248, 249,
68 250, 251, 252, 253, 254, 255 };
69 
70 
71 /*************************************************************************
72 |*
73 |*    RscChar::GetTable()
74 |*
75 |*    Beschreibung
76 |*    Ersterstellung    MM 08.08.91
77 |*    Letzte Aenderung  MM 08.08.91
78 |*
79 *************************************************************************/
80 Table *         pCharTable  = NULL;
81 unsigned char * pChange     = EqualTab;
82 char * SvChar::GetTable( CharSet nSource , CharSet nDest )
83 {
84     if( nSource == nDest )
85         return (char *)EqualTab;
86 
87     if( !pCharTable )
88         pCharTable = new Table();
89 
90     sal_uInt8 * pSet;
91     pSet = (sal_uInt8 *)pCharTable->Get( ((sal_uLong)nSource << 16) + (sal_uLong)nDest );
92 
93     if( !pSet )
94     {
95         pSet = new sal_uInt8[ 256 ];
96         memcpy( pSet, EqualTab, sizeof( EqualTab ) );
97         for( sal_uInt16 i = 128; i < 256; i++ )
98         {
99             char c = ByteString::Convert( pSet[i], nSource, nDest );
100             if( c )
101                 pSet[ i ] = (sal_uInt8)c;
102         }
103         pCharTable->Insert( ((sal_uLong)nSource << 16) + (sal_uLong)nDest, pSet );
104     }
105 
106     return (char *)pSet;
107 };
108