home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / i18n / ubrk.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  3.3 KB  |  143 lines

  1. /*
  2. *****************************************************************************************
  3. *                                                                                       *
  4. * COPYRIGHT:                                                                            *
  5. *   (C) Copyright Taligent, Inc.,  1996                                                 *
  6. *   (C) Copyright International Business Machines Corporation,  1998-1999               *
  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.  
  14. #include "ubrk.h"
  15.  
  16. #include "brkiter.h"
  17. #include "uloc.h"
  18. #include "ustring.h"
  19. #include "uchriter.h"
  20.  
  21. U_CAPI UBreakIterator*
  22. ubrk_open(UBreakIteratorType type,
  23.       const char *locale,
  24.       const UChar *text,
  25.       int32_t textLength,
  26.       UErrorCode *status)
  27. {
  28.   if(U_FAILURE(*status)) return 0;
  29.   
  30.   BreakIterator *result = 0;
  31.   
  32.   switch(type) {
  33.  
  34.   case UBRK_CHARACTER:
  35.     result = BreakIterator::createCharacterInstance(Locale().init(locale));
  36.     break;
  37.  
  38.   case UBRK_WORD:
  39.     result = BreakIterator::createWordInstance(Locale().init(locale));
  40.     break;
  41.  
  42.   case UBRK_LINE:
  43.     result = BreakIterator::createLineInstance(Locale().init(locale));
  44.     break;
  45.  
  46.   case UBRK_SENTENCE:
  47.     result = BreakIterator::createSentenceInstance(Locale().init(locale));
  48.     break;
  49.   }
  50.  
  51.   // check for allocation error
  52.   if(result == 0) {
  53.     *status = U_MEMORY_ALLOCATION_ERROR;
  54.     return 0;
  55.   }
  56.  
  57.   int32_t textLen = (textLength == -1 ? u_strlen(text) : textLength);
  58.   UCharCharacterIterator *iter = 0;
  59.   iter = new UCharCharacterIterator(text, textLen);
  60.   if(iter == 0) {
  61.     *status = U_MEMORY_ALLOCATION_ERROR;
  62.     delete result;
  63.     return 0;
  64.   }
  65.   result->adoptText(iter);
  66.  
  67.   return (UBreakIterator*)result;
  68. }
  69.  
  70. U_CAPI UBreakIterator*
  71. ubrk_openRules(const UChar *rules,
  72.            int32_t rulesLength,
  73.            const UChar *text,
  74.            int32_t textLength,
  75.            UErrorCode *status)
  76. {
  77.   if(U_FAILURE(*status)) return 0;
  78.  
  79.   return 0;
  80. }
  81.  
  82. U_CAPI void
  83. ubrk_close(UBreakIterator *bi)
  84. {
  85.   delete (BreakIterator*) bi;
  86. }
  87.  
  88. U_CAPI UTextOffset
  89. ubrk_current(const UBreakIterator *bi)
  90. {
  91.   return ((BreakIterator*)bi)->current();
  92. }
  93.  
  94. U_CAPI UTextOffset
  95. ubrk_next(UBreakIterator *bi)
  96. {
  97.   return ((BreakIterator*)bi)->next();
  98. }
  99.  
  100. U_CAPI UTextOffset
  101. ubrk_previous(UBreakIterator *bi)
  102. {
  103.   return ((BreakIterator*)bi)->previous();
  104. }
  105.  
  106. U_CAPI UTextOffset
  107. ubrk_first(UBreakIterator *bi)
  108. {
  109.   return ((BreakIterator*)bi)->first();
  110. }
  111.  
  112. U_CAPI UTextOffset
  113. ubrk_last(UBreakIterator *bi)
  114. {
  115.   return ((BreakIterator*)bi)->last();
  116. }
  117.  
  118. U_CAPI UTextOffset
  119. ubrk_preceding(UBreakIterator *bi,
  120.            UTextOffset offset)
  121. {
  122.   return ((BreakIterator*)bi)->preceding(offset);
  123. }
  124.  
  125. U_CAPI UTextOffset
  126. ubrk_following(UBreakIterator *bi,
  127.            UTextOffset offset)
  128. {
  129.   return ((BreakIterator*)bi)->following(offset);
  130. }
  131.  
  132. U_CAPI const char*
  133. ubrk_getAvailable(int32_t index)
  134. {
  135.   return uloc_getAvailable(index);
  136. }
  137.  
  138. U_CAPI int32_t
  139. ubrk_countAvailable()
  140. {
  141.   return uloc_countAvailable();
  142. }
  143.