Logo Search packages:      
Sourcecode: icu version File versions

U_STABLE UBreakIterator* U_EXPORT2 ubrk_open ( UBreakIteratorType  type,
const char *  locale,
const UChar *  text,
int32_t  textLength,
UErrorCode status 
)

Open a new UBreakIterator for locating text boundaries for a specified locale. A UBreakIterator may be used for detecting character, line, word, and sentence breaks in text.

Parameters:
type The type of UBreakIterator to open: one of UBRK_CHARACTER, UBRK_WORD, UBRK_LINE, UBRK_SENTENCE
locale The locale specifying the text-breaking conventions.
text The text to be iterated over.
textLength The number of characters in text, or -1 if null-terminated.
status A UErrorCode to receive any errors.
Returns:
A UBreakIterator for the specified locale.
See also:
ubrk_openRules ICU 2.0

Definition at line 31 of file ubrk.cpp.

References BreakIterator::createCharacterInstance(), BreakIterator::createLineInstance(), BreakIterator::createSentenceInstance(), BreakIterator::createTitleInstance(), BreakIterator::createWordInstance(), NULL, U_FAILURE, U_ILLEGAL_ARGUMENT_ERROR, U_MEMORY_ALLOCATION_ERROR, UBRK_CHARACTER, UBRK_LINE, UBRK_SENTENCE, UBRK_TITLE, and UBRK_WORD.

{

  if(U_FAILURE(*status)) return 0;

  BreakIterator *result = 0;

  switch(type) {

  case UBRK_CHARACTER:
    result = BreakIterator::createCharacterInstance(Locale(locale), *status);
    break;

  case UBRK_WORD:
    result = BreakIterator::createWordInstance(Locale(locale), *status);
    break;

  case UBRK_LINE:
    result = BreakIterator::createLineInstance(Locale(locale), *status);
    break;

  case UBRK_SENTENCE:
    result = BreakIterator::createSentenceInstance(Locale(locale), *status);
    break;

  case UBRK_TITLE:
    result = BreakIterator::createTitleInstance(Locale(locale), *status);
    break;

  default:
    *status = U_ILLEGAL_ARGUMENT_ERROR;
  }

  // check for allocation error
  if (U_FAILURE(*status)) {
     return 0;
  }
  if(result == 0) {
    *status = U_MEMORY_ALLOCATION_ERROR;
    return 0;
  }


  UBreakIterator *uBI = (UBreakIterator *)result;
  if (text != NULL) {
      ubrk_setText(uBI, text, textLength, status);
  }
  return uBI;
}


Generated by  Doxygen 1.6.0   Back to index