home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / i18n / unicdcm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-16  |  4.2 KB  |  101 lines

  1. /*
  2. *****************************************************************************************
  3. *                                                                                       *
  4. * COPYRIGHT:                                                                            *
  5. *   (C) Copyright Taligent, Inc.,  1997                                                 *
  6. *   (C) Copyright International Business Machines Corporation,  1997-1998                    *
  7. *   Licensed Material - Program-Property of IBM - All Rights Reserved.                  *
  8. *   US Government Users Restricted Rights - Use, duplication, or disclosure             *
  9. *   restricted by GSA ADP Schedule Contract with IBM Corp.                              *
  10. *                                                                                       *
  11. *****************************************************************************************
  12. *
  13. * File UNICDCM.CPP
  14. *
  15. * Modification History:
  16. *
  17. *   Date        Name        Description
  18. *   02/18/97    aliu        Converted from OpenClass.
  19. *   03/11/97    aliu        Recoded mappedChar() slightly to clean up code and improve
  20. *                           performance.
  21. *   04/15/97    aliu        Worked around bug in AIX xlC compiler which occurs if static
  22. *                           arrays contain const elements.
  23. *   05/06/97    aliu        Made SpecialMapping an array of objects instead of pointers,
  24. *                           to help out non-compliant compilers.
  25. *****************************************************************************************
  26. */
  27.  
  28. // *****************************************************************************
  29. // This file was generated from the java source file UnicodeClassMapping.java
  30. // *****************************************************************************
  31.  
  32. #include "unicdcm.h"
  33. #include "unicode.h"
  34.  
  35. // *****************************************************************************
  36. // class UnicodeClassMapping
  37. // This class maps categories to state change inputs for the
  38. // WordBreakTable.  An entire category is mapped to the same
  39. // value unless the character in question appears in the exception list.
  40. // *****************************************************************************
  41.  
  42. // -------------------------------------
  43.  
  44. UnicodeClassMapping::UnicodeClassMapping(Type* mappedValue, 
  45.                      int32_t mappedValue_length,
  46.                                          const SpecialMapping* exceptionChars,
  47.                                          int32_t exceptionChars_length,
  48.                                          const bool_t *hasException,
  49.                                          Type* asciiValues)
  50. :   fMappedValue(mappedValue),
  51.     fMappedValue_length(mappedValue_length),
  52.     fExceptionChars(exceptionChars),
  53.     fExceptionChars_length(exceptionChars_length),
  54.     fHasException(hasException),
  55.     fAsciiValues(asciiValues)
  56. {
  57. }
  58.  
  59. // -------------------------------------
  60.  
  61. TextBoundaryData::Type
  62. UnicodeClassMapping::mappedChar(UChar ch) const
  63. {
  64.     if (ch <= 255) {
  65.         return fAsciiValues[ ch ];
  66.     }
  67.  
  68.     // get an appropriate category based on the character's Unicode class
  69.     // if there's no entry in the exception table for that Unicode class,
  70.     // we're done; otherwise we have to look in the exception table for
  71.     // the character's category (\uffff is treated here as a sentinel
  72.     // value meaning "end of the string"-- we always look in the exception
  73.     // table for its category)
  74.     Type chType = Unicode::getType(ch);
  75.     if ((fExceptionChars_length == 0) ||
  76.         (!fHasException[chType] && (ch != (UChar)0xFFFF)))
  77.     {
  78.         return fMappedValue[chType];
  79.     }
  80.  
  81.     // The invariant during this loop is that the character ch is <= max and
  82.     // >= min.  We iterate until min == max.
  83.     int32_t min = 0;
  84.     int32_t max = fExceptionChars_length - 1;
  85.     while (max > min) {
  86.         int32_t pos = (max + min) >> 1;
  87.         if (ch > fExceptionChars[pos].fEndChar) {
  88.             min = pos + 1; 
  89.         }else{
  90.             max = pos;
  91.         }
  92.     }
  93.     const SpecialMapping* sm = &fExceptionChars[min];
  94.     if (sm->fStartChar <= ch && ch <= sm->fEndChar)
  95.         return sm->fNewValue;
  96.     else
  97.         return fMappedValue[chType];
  98. }
  99.  
  100. //eof
  101.