bintools/rcomp/src/CTABLE.CPP
changeset 0 044383f39525
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 /*
       
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * Implements character set mapping functionality.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "CTABLE.H"
       
    21 
       
    22 
       
    23 
       
    24 // ++++++ Range member functions ++++++
       
    25 
       
    26 
       
    27 
       
    28 Range::Range()
       
    29     {
       
    30     i_first = i_last = 0;
       
    31     }
       
    32 
       
    33 
       
    34 Range::Range( int afirst, int alast )
       
    35     {
       
    36     define(afirst, alast);
       
    37     }
       
    38 
       
    39 void Range::define( int afirst, int alast )
       
    40     {
       
    41     // ensure that the range is stored in the right order.
       
    42     if ( afirst > alast )
       
    43         {
       
    44         i_first = alast;
       
    45         i_last = afirst;
       
    46         }
       
    47     else
       
    48         {
       
    49         i_first = afirst;
       
    50         i_last = alast;
       
    51         }
       
    52     }
       
    53 
       
    54 int Range::count() const
       
    55     {
       
    56     return ( i_last - i_first +1 );
       
    57     }
       
    58 
       
    59 int Range::first() const
       
    60     {
       
    61     return(i_first);
       
    62     }
       
    63 
       
    64 
       
    65 int Range::part_of( int avalue ) const
       
    66     {
       
    67     // return TRUE if the value is in the range, else FALSE
       
    68 
       
    69     if ( (avalue >= i_first) && ( avalue <= i_last ) ) return 1;
       
    70     else return 0;
       
    71 
       
    72     }
       
    73 
       
    74 
       
    75 // ++++++ Mapping_range member functions ++++++
       
    76 
       
    77 
       
    78 Mapping_range::Mapping_range()
       
    79     {
       
    80     mappings = NULL;
       
    81     }
       
    82 
       
    83 Mapping_range::Mapping_range( S_mapping_range *data )
       
    84     {
       
    85     range.define(data->first, data->last);
       
    86     mappings = &data->mappings[0];
       
    87     }
       
    88 
       
    89 
       
    90 
       
    91 int Mapping_range::map(  unsigned char an8_bit_character, UTF16 &aUnicode_character ) const
       
    92     {
       
    93     if ( !range.part_of(an8_bit_character) ) return (0);
       
    94 
       
    95     int index = (int)an8_bit_character - range.first();
       
    96     aUnicode_character = mappings[index];
       
    97     return (1);
       
    98     }
       
    99 
       
   100 
       
   101 
       
   102 
       
   103 
       
   104 // end of CTABLE.CPP