Logo Search packages:      
Sourcecode: icu version File versions  Download package

U_CAPI UEnumeration* U_EXPORT2 ucnvsel_selectForString ( const UConverterSelector *  sel,
const UChar *  s,
int32_t  length,
UErrorCode status 
)

Select converters that can map all characters in a UTF-16 string, ignoring the excluded code points.

Parameters:
sel a selector
s UTF-16 string
length length of the string, or -1 if NUL-terminated
status an in/out ICU UErrorCode
Returns:
an enumeration containing encoding names. The returned encoding names and their order will be the same as supplied when building the selector.
ICU 4.2

Definition at line 738 of file ucnvsel.cpp.

References NULL, U_FAILURE, U_ILLEGAL_ARGUMENT_ERROR, U_MEMORY_ALLOCATION_ERROR, and UTRIE2_U16_NEXT16.

                                                                            {
  // check if already failed
  if (U_FAILURE(*status)) {
    return NULL;
  }
  // ensure args make sense!
  if (sel == NULL || (s == NULL && length != 0)) {
    *status = U_ILLEGAL_ARGUMENT_ERROR;
    return NULL;
  }

  int32_t columns = (sel->encodingsCount+31)/32;
  uint32_t* mask = (uint32_t*) uprv_malloc(columns * 4);
  if (mask == NULL) {
    *status = U_MEMORY_ALLOCATION_ERROR;
    return NULL;
  }
  uprv_memset(mask, ~0, columns *4);

  const UChar *limit;
  if (length >= 0) {
    limit = s + length;
  } else {
    limit = NULL;
  }

  while (limit == NULL ? *s != 0 : s != limit) {
    UChar32 c;
    uint16_t pvIndex;
    UTRIE2_U16_NEXT16(sel->trie, s, limit, c, pvIndex);
    if (intersectMasks(mask, sel->pv+pvIndex, columns)) {
      break;
    }
  }
  return selectForMask(sel, mask, status);
}


Generated by  Doxygen 1.6.0   Back to index