webengine/wmlengine/src/hed/src/EntitySet.c
changeset 74 91031d3aab7d
parent 68 92a765b5b3e7
child 85 e358f2276d3f
equal deleted inserted replaced
68:92a765b5b3e7 74:91031d3aab7d
     1 /*
       
     2 * Copyright (c) 2000 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 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "nw_hed_entityseti.h"
       
    20 
       
    21 /* ------------------------------------------------------------------------- *
       
    22    class definition
       
    23  * ------------------------------------------------------------------------- */
       
    24 
       
    25 /* ------------------------------------------------------------------------- */
       
    26 const
       
    27 NW_HED_EntitySet_Class_t NW_HED_EntitySet_Class = {
       
    28   { /* NW_Object_Core            */
       
    29     /* super                     */ &NW_Object_Base_Class,
       
    30     /* queryInterface            */ _NW_Object_Base_QueryInterface
       
    31   },
       
    32   { /* NW_HED_EntitySet          */
       
    33     /* numEntries                */ 0,
       
    34     /* numCaseInsensitiveEntries */ 0,
       
    35     /* entries                   */ NULL,
       
    36     /* getEntityChar	         */ _NW_HED_EntitySet_GetEntityChar
       
    37   }
       
    38 };
       
    39 
       
    40 /* ------------------------------------------------------------------------- *
       
    41    virtual methods
       
    42  * ------------------------------------------------------------------------- */
       
    43 
       
    44 /* ------------------------------------------------------------------------- */
       
    45 NW_Ucs2
       
    46 _NW_HED_EntitySet_GetEntityChar (const NW_HED_EntitySet_t* entitySet,
       
    47                                  NW_Ucs2 *name)
       
    48 {
       
    49   NW_Int32 index;
       
    50   const NW_HED_EntitySet_Entry_t* entry;
       
    51 
       
    52   /* First do a binary search search in the case sensitive part of the array */
       
    53   NW_Int32 low = 0;
       
    54   NW_Int32 high = NW_HED_EntitySet_GetClassPart(entitySet).numEntries 
       
    55 				  - NW_HED_EntitySet_GetClassPart(entitySet).numCaseInsensitiveEntries - 1;
       
    56   NW_Int32 res = 0;
       
    57 
       
    58   while (low <= high ) {
       
    59     index = (high + low) / 2;
       
    60     entry = & (NW_HED_EntitySet_GetClassPart(entitySet).entries[index]);
       
    61 
       
    62     /* do a case sensitive string comparison */
       
    63     res = NW_Str_StrcmpConst( name, entry->name );
       
    64 
       
    65     if ( res > 0 ) {
       
    66       /* name is ahead of this slot.  Increase low bound. */
       
    67       low = index + 1;
       
    68     } else if ( res < 0 ) {
       
    69       /* name is behind this slot.  Decrease high bound. */
       
    70       high = index - 1;
       
    71     } else {
       
    72       /* Found the entity name.  Return its value. */
       
    73       return entry->value;
       
    74     }
       
    75   }
       
    76 
       
    77   /* if no match was found search in the case insensitive part of the table. */
       
    78   low = NW_HED_EntitySet_GetClassPart(entitySet).numEntries 
       
    79 				 - NW_HED_EntitySet_GetClassPart(entitySet).numCaseInsensitiveEntries;
       
    80   high = NW_HED_EntitySet_GetClassPart(entitySet).numEntries - 1;
       
    81   res = 0;
       
    82   while (low <= high ) {
       
    83     index = (high + low) / 2;
       
    84     entry = & (NW_HED_EntitySet_GetClassPart(entitySet).entries[index]);
       
    85 
       
    86     // do a case insensitive string comparison
       
    87     res = NW_Str_StricmpConst( name, entry->name );
       
    88 
       
    89     if ( res > 0 ) {
       
    90       /* name is ahead of this slot.  Increase low bound. */
       
    91       low = index + 1;
       
    92     } else if ( res < 0 ) {
       
    93       /* name is behind this slot.  Decrease high bound. */
       
    94       high = index - 1;
       
    95     } else {
       
    96       /* Found the entity name.  Return its value. */
       
    97       return entry->value;
       
    98     }
       
    99   }
       
   100 
       
   101   /* if no match were found we return 0 */
       
   102   return 0;
       
   103 }