scuffed-code/icu4c/source/common/unorm.cpp

59 lines
1.6 KiB
C++
Raw Normal View History

/*
*******************************************************************************
* Copyright <EFBFBD> {1996-2001}, International Business Machines Corporation and others. All Rights Reserved.
*******************************************************************************
* File unorm.cpp
*
* Created by: Vladimir Weinstein 12052000
*
*/
#include "unicode/unorm.h"
#include "unicode/normlzr.h"
#include "unicode/ustring.h"
#include "cpputils.h"
U_CAPI int32_t
u_normalize(const UChar* source,
int32_t sourceLength,
UNormalizationMode mode,
int32_t option,
UChar* result,
int32_t resultLength,
UErrorCode* status)
{
if(U_FAILURE(*status)) return -1;
Normalizer::EMode normMode;
switch(mode) {
case UCOL_NO_NORMALIZATION:
normMode = Normalizer::NO_OP;
break;
case UCOL_DECOMP_CAN:
normMode = Normalizer::DECOMP;
break;
case UCOL_DECOMP_COMPAT:
normMode = Normalizer::DECOMP_COMPAT;
break;
case UCOL_DECOMP_CAN_COMP_COMPAT:
normMode = Normalizer::COMPOSE;
break;
case UCOL_DECOMP_COMPAT_COMP_CAN:
normMode = Normalizer::COMPOSE_COMPAT;
break;
default:
*status = U_ILLEGAL_ARGUMENT_ERROR;
return -1;
}
int32_t len = (sourceLength == -1 ? u_strlen(source) : sourceLength);
const UnicodeString src((UChar*)source, len, len);
UnicodeString dst(result, 0, resultLength);
Normalizer::normalize(src, normMode, option, dst, *status);
int32_t actualLen;
T_fillOutputParams(&dst, result, resultLength, &actualLen, status);
return actualLen;
}