本文整理汇总了C++中U_FAILURE函数的典型用法代码示例。如果您正苦于以下问题:C++ U_FAILURE函数的具体用法?C++ U_FAILURE怎么用?C++ U_FAILURE使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了U_FAILURE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: uspoof_areConfusableUnicodeString
U_CAPI int32_t U_EXPORT2
uspoof_areConfusableUnicodeString(const USpoofChecker *sc,
const icu::UnicodeString &id1,
const icu::UnicodeString &id2,
UErrorCode *status) {
const SpoofImpl *This = SpoofImpl::validateThis(sc, *status);
if (U_FAILURE(*status)) {
return 0;
}
//
// See section 4 of UAX 39 for the algorithm for checking whether two strings are confusable,
// and for definitions of the types (single, whole, mixed-script) of confusables.
// We only care about a few of the check flags. Ignore the others.
// If no tests relavant to this function have been specified, return an error.
// TODO: is this really the right thing to do? It's probably an error on the caller's part,
// but logically we would just return 0 (no error).
if ((This->fChecks & USPOOF_CONFUSABLE) == 0) {
*status = U_INVALID_STATE_ERROR;
return 0;
}
// Compute the skeletons and check for confusability.
UnicodeString id1Skeleton;
uspoof_getSkeletonUnicodeString(sc, 0 /* deprecated */, id1, id1Skeleton, status);
UnicodeString id2Skeleton;
uspoof_getSkeletonUnicodeString(sc, 0 /* deprecated */, id2, id2Skeleton, status);
if (U_FAILURE(*status)) { return 0; }
if (id1Skeleton != id2Skeleton) {
return 0;
}
// If we get here, the strings are confusable. Now we just need to set the flags for the appropriate classes
// of confusables according to UTS 39 section 4.
// Start by computing the resolved script sets of id1 and id2.
ScriptSet id1RSS;
This->getResolvedScriptSet(id1, id1RSS, *status);
ScriptSet id2RSS;
This->getResolvedScriptSet(id2, id2RSS, *status);
// Turn on all applicable flags
int32_t result = 0;
if (id1RSS.intersects(id2RSS)) {
result |= USPOOF_SINGLE_SCRIPT_CONFUSABLE;
} else {
result |= USPOOF_MIXED_SCRIPT_CONFUSABLE;
if (!id1RSS.isEmpty() && !id2RSS.isEmpty()) {
result |= USPOOF_WHOLE_SCRIPT_CONFUSABLE;
}
}
// Turn off flags that the user doesn't want
if ((This->fChecks & USPOOF_SINGLE_SCRIPT_CONFUSABLE) == 0) {
result &= ~USPOOF_SINGLE_SCRIPT_CONFUSABLE;
}
if ((This->fChecks & USPOOF_MIXED_SCRIPT_CONFUSABLE) == 0) {
result &= ~USPOOF_MIXED_SCRIPT_CONFUSABLE;
}
if ((This->fChecks & USPOOF_WHOLE_SCRIPT_CONFUSABLE) == 0) {
result &= ~USPOOF_WHOLE_SCRIPT_CONFUSABLE;
}
return result;
}
示例2: apr_pstrdup
//.........这里部分代码省略.........
// Flag that we need to send the cookies, because we have set at least one.
requireSend = true;
}
}
if( requireSend )
{
cookies.sendCookies( req );
}
// Lazy init code.
if( spepConfigData->isLazyInit() )
{
std::string globalESOECookieName( spepConfigData->getGlobalESOECookieName() );
Cookies cookies( req );
std::vector<std::string> cookieValues;
cookies.getCookieValuesByName( cookieValues, globalESOECookieName );
if( cookieValues.empty() ) {
bool matchedLazyInitResource = false;
UnicodeString properURIUnicode( spep::UnicodeStringConversion::toUnicodeString( properURI ) );
std::vector<UnicodeString>::const_iterator lazyInitResourceIterator;
for( lazyInitResourceIterator = spepConfigData->getLazyInitResources().begin();
lazyInitResourceIterator != spepConfigData->getLazyInitResources().end();
++lazyInitResourceIterator )
{
// TODO Opportunity for caching of compiled regex patterns is here.
UParseError parseError;
UErrorCode errorCode = U_ZERO_ERROR;
// Perform the regular expression matching here.
UBool result = RegexPattern::matches( *lazyInitResourceIterator, properURIUnicode, parseError, errorCode );
if ( U_FAILURE( errorCode ) )
{
// TODO throw u_errorName( errorCode )
return HTTP_INTERNAL_SERVER_ERROR;
}
// FALSE is defined by ICU. This line for portability.
if (result != FALSE)
{
matchedLazyInitResource = true;
break;
}
}
if( matchedLazyInitResource )
{
if( !spepConfigData->isLazyInitDefaultPermit() )
{
return DECLINED;
}
}
else
{
if( spepConfigData->isLazyInitDefaultPermit() )
{
return DECLINED;
}
}
}
}
boost::posix_time::ptime epoch( boost::gregorian::date( 1970, 1, 1 ) );
boost::posix_time::time_duration timestamp = boost::posix_time::microsec_clock::local_time() - epoch;
示例3: extractPackageName
void
Package::writePackage(const char *filename, char outType, const char *comment) {
char prefix[MAX_PKG_NAME_LENGTH+4];
UDataOffsetTOCEntry entry;
UDataSwapper *dsLocalToOut, *ds[TYPE_COUNT];
FILE *file;
Item *pItem;
char *name;
UErrorCode errorCode;
int32_t i, length, prefixLength, maxItemLength, basenameOffset, offset, outInt32;
uint8_t outCharset;
UBool outIsBigEndian;
extractPackageName(filename, prefix, MAX_PKG_NAME_LENGTH);
// if there is an explicit comment, then use it, else use what's in the current header
if(comment!=NULL) {
/* get the header size minus the current comment */
DataHeader *pHeader;
int32_t length;
pHeader=(DataHeader *)header;
headerLength=4+pHeader->info.size;
length=(int32_t)strlen(comment);
if((int32_t)(headerLength+length)>=(int32_t)sizeof(header)) {
fprintf(stderr, "icupkg: comment too long\n");
exit(U_BUFFER_OVERFLOW_ERROR);
}
memcpy(header+headerLength, comment, length+1);
headerLength+=length;
if(headerLength&0xf) {
/* NUL-pad the header to a multiple of 16 */
length=(headerLength+0xf)&~0xf;
memset(header+headerLength, 0, length-headerLength);
headerLength=length;
}
pHeader->dataHeader.headerSize=(uint16_t)headerLength;
}
makeTypeProps(outType, outCharset, outIsBigEndian);
// open (TYPE_COUNT-2) swappers
// one is a no-op for local type==outType
// one type (TYPE_LE) is bogus
errorCode=U_ZERO_ERROR;
i=makeTypeEnum(outType);
ds[TYPE_B]= i==TYPE_B ? NULL : udata_openSwapper(TRUE, U_ASCII_FAMILY, outIsBigEndian, outCharset, &errorCode);
ds[TYPE_L]= i==TYPE_L ? NULL : udata_openSwapper(FALSE, U_ASCII_FAMILY, outIsBigEndian, outCharset, &errorCode);
ds[TYPE_LE]=NULL;
ds[TYPE_E]= i==TYPE_E ? NULL : udata_openSwapper(TRUE, U_EBCDIC_FAMILY, outIsBigEndian, outCharset, &errorCode);
if(U_FAILURE(errorCode)) {
fprintf(stderr, "icupkg: udata_openSwapper() failed - %s\n", u_errorName(errorCode));
exit(errorCode);
}
for(i=0; i<TYPE_COUNT; ++i) {
if(ds[i]!=NULL) {
ds[i]->printError=printPackageError;
ds[i]->printErrorContext=stderr;
}
}
dsLocalToOut=ds[makeTypeEnum(U_CHARSET_FAMILY, U_IS_BIG_ENDIAN)];
// create the file and write its contents
file=fopen(filename, "wb");
if(file==NULL) {
fprintf(stderr, "icupkg: unable to create file \"%s\"\n", filename);
exit(U_FILE_ACCESS_ERROR);
}
// swap and write the header
if(dsLocalToOut!=NULL) {
udata_swapDataHeader(dsLocalToOut, header, headerLength, header, &errorCode);
if(U_FAILURE(errorCode)) {
fprintf(stderr, "icupkg: udata_swapDataHeader(local to out) failed - %s\n", u_errorName(errorCode));
exit(errorCode);
}
}
length=(int32_t)fwrite(header, 1, headerLength, file);
if(length!=headerLength) {
fprintf(stderr, "icupkg: unable to write complete header to file \"%s\"\n", filename);
exit(U_FILE_ACCESS_ERROR);
}
// prepare and swap the package name with a tree separator
// for prepending to item names
strcat(prefix, U_TREE_ENTRY_SEP_STRING);
prefixLength=(int32_t)strlen(prefix);
if(dsLocalToOut!=NULL) {
dsLocalToOut->swapInvChars(dsLocalToOut, prefix, prefixLength, prefix, &errorCode);
if(U_FAILURE(errorCode)) {
fprintf(stderr, "icupkg: swapInvChars(output package name) failed - %s\n", u_errorName(errorCode));
exit(errorCode);
}
// swap and sort the item names (sorting needs to be done in the output charset)
dsLocalToOut->swapInvChars(dsLocalToOut, inStrings, inStringTop, inStrings, &errorCode);
if(U_FAILURE(errorCode)) {
fprintf(stderr, "icupkg: swapInvChars(item names) failed - %s\n", u_errorName(errorCode));
exit(errorCode);
//.........这里部分代码省略.........
示例4: loadData
static UBool U_CALLCONV
loadData(UStringPrepProfile* profile,
const char* path,
const char* name,
const char* type,
UErrorCode* errorCode) {
/* load Unicode SPREP data from file */
UTrie _sprepTrie={ 0,0,0,0,0,0,0 };
UDataMemory *dataMemory;
const int32_t *p=NULL;
const uint8_t *pb;
UVersionInfo normUnicodeVersion;
int32_t normUniVer, sprepUniVer, normCorrVer;
if(errorCode==NULL || U_FAILURE(*errorCode)) {
return 0;
}
/* open the data outside the mutex block */
//TODO: change the path
dataMemory=udata_openChoice(path, type, name, isSPrepAcceptable, NULL, errorCode);
if(U_FAILURE(*errorCode)) {
return FALSE;
}
p=(const int32_t *)udata_getMemory(dataMemory);
pb=(const uint8_t *)(p+_SPREP_INDEX_TOP);
utrie_unserialize(&_sprepTrie, pb, p[_SPREP_INDEX_TRIE_SIZE], errorCode);
_sprepTrie.getFoldingOffset=getSPrepFoldingOffset;
if(U_FAILURE(*errorCode)) {
udata_close(dataMemory);
return FALSE;
}
/* in the mutex block, set the data for this process */
umtx_lock(&usprepMutex);
if(profile->sprepData==NULL) {
profile->sprepData=dataMemory;
dataMemory=NULL;
uprv_memcpy(&profile->indexes, p, sizeof(profile->indexes));
uprv_memcpy(&profile->sprepTrie, &_sprepTrie, sizeof(UTrie));
} else {
p=(const int32_t *)udata_getMemory(profile->sprepData);
}
umtx_unlock(&usprepMutex);
/* initialize some variables */
profile->mappingData=(uint16_t *)((uint8_t *)(p+_SPREP_INDEX_TOP)+profile->indexes[_SPREP_INDEX_TRIE_SIZE]);
u_getUnicodeVersion(normUnicodeVersion);
normUniVer = (normUnicodeVersion[0] << 24) + (normUnicodeVersion[1] << 16) +
(normUnicodeVersion[2] << 8 ) + (normUnicodeVersion[3]);
sprepUniVer = (dataVersion[0] << 24) + (dataVersion[1] << 16) +
(dataVersion[2] << 8 ) + (dataVersion[3]);
normCorrVer = profile->indexes[_SPREP_NORM_CORRECTNS_LAST_UNI_VERSION];
if(U_FAILURE(*errorCode)){
udata_close(dataMemory);
return FALSE;
}
if( normUniVer < sprepUniVer && /* the Unicode version of SPREP file must be less than the Unicode Vesion of the normalization data */
normUniVer < normCorrVer && /* the Unicode version of the NormalizationCorrections.txt file should be less than the Unicode Vesion of the normalization data */
((profile->indexes[_SPREP_OPTIONS] & _SPREP_NORMALIZATION_ON) > 0) /* normalization turned on*/
){
*errorCode = U_INVALID_FORMAT_ERROR;
udata_close(dataMemory);
return FALSE;
}
profile->isDataLoaded = TRUE;
/* if a different thread set it first, then close the extra data */
if(dataMemory!=NULL) {
udata_close(dataMemory); /* NULL if it was set correctly */
}
return profile->isDataLoaded;
}
示例5: main
int main(int /* argc*/ , const char * /*argv*/ []) {
UErrorCode status = U_ZERO_ERROR;
int diffs = 0;
int gbaddiffs =0;
setup(status);
if(U_FAILURE(status)) return 1;
int expected = PROVIDER_COUNT;
for(int l=0;l<LOCALE_COUNT;l++) {
printf("\n");
uint8_t oldBytes[200];
int32_t oldLen = -1;
for(int v=0;v<=expected;v++) {
// Construct the locale ID
char locID[200];
strcpy(locID, locale[l]);
if((v!=expected)) { // -1 = no version
strcat(locID, "@sp=icu");
strcat(locID, provider_version[v]);
}
printf("%-28s = ", locID);
UErrorCode subStatus = U_ZERO_ERROR;
uint8_t bytes[200];
uint8_t bytesb[200];
#define USE_CXX 0
#if USE_CXX
Collator *col = Collator::createInstance(Locale(locID),subStatus);
if(U_FAILURE(subStatus)) {
printf("ERR: %s\n", u_errorName(subStatus));
continue;
}
int32_t len = col->getSortKey(stuff, -1, bytes, 200);
#else
#if 1
char xbuf2[200];
strcpy(xbuf2,"X/");
strcat(xbuf2,locID);
strcat(xbuf2,"/");
//printf(" -> %s\n", xbuf2);
UCollator *col = ucol_openFromShortString(xbuf2, FALSE,NULL, &subStatus);
#else
UCollator *col = ucol_open(locID, &subStatus);
#endif
if(U_FAILURE(subStatus)) {
printf("ERR: %s\n", u_errorName(subStatus));
continue;
}
char xbuf3[200];
{
int32_t def = ucol_getShortDefinitionString(col,locID/*NULL*/,xbuf3,200,&subStatus);
if(U_FAILURE(subStatus)) {
printf("Err getting short string name: %s\n", u_errorName(subStatus));
} else {
printf(" --> %s\n", xbuf3);
}
}
int32_t len = ucol_getSortKey(col, stuff, -1, bytes, 200);
#endif
printf(" ");
int tdiffs=0;
for(int i=0;i<len;i++) {
if(i<oldLen&&bytes[i]!=oldBytes[i]) {
diffs++;
printf("*");
} else {
printf(" ");
}
printf("%02X", (0xFF&bytes[i]));
}
printf("\n");
char xbuf4[200];
UCollator *col2 = ucol_openFromShortString(xbuf3, FALSE, NULL, &subStatus);
if(U_FAILURE(subStatus)) {
printf("Err opening from new short string : %s\n", u_errorName(subStatus));
continue;
} else {
int32_t def4 = ucol_getShortDefinitionString(col,locID/*NULL*/,xbuf4,200,&subStatus);
if(strcmp(xbuf4,xbuf3)) {
printf(" --> reopened = %s (%s)\n", xbuf4, u_errorName(subStatus));
}
}
int32_t len2 = ucol_getSortKey(col2, stuff, -1, bytesb, 200);
int baddiffs=0;
for(int i=0;i<len;i++) {
if(i<len&&bytes[i]!=bytesb[i]) {
baddiffs++;
printf("!");
//.........这里部分代码省略.........
示例6: f_intl_is_failure
bool f_intl_is_failure(int64 error_code) {
if (U_FAILURE((UErrorCode)error_code)) return true;
return false;
}
示例7: php_intl_idn_to
Variant php_intl_idn_to(CStrRef domain, Variant errorcode, int mode) {
long option = 0;
UChar* ustring = NULL;
int ustring_len = 0;
UErrorCode status;
char *converted_utf8 = NULL;
int32_t converted_utf8_len;
UChar* converted = NULL;
int32_t converted_ret_len;
// Convert the string to UTF-16
status = U_ZERO_ERROR;
intl_convert_utf8_to_utf16(&ustring, &ustring_len,
(char*)domain.data(), domain.size(), &status);
if (U_FAILURE(status)) {
free(ustring);
errorcode = status;
return false;
}
// Call the appropriate IDN function
int converted_len = (ustring_len > 1) ? ustring_len : 1;
for (;;) {
UParseError parse_error;
status = U_ZERO_ERROR;
converted = (UChar*)malloc(sizeof(UChar)*converted_len);
// If the malloc failed, bail out
if (!converted) {
free(ustring);
errorcode = U_MEMORY_ALLOCATION_ERROR;
return false;
}
if (mode == INTL_IDN_TO_ASCII) {
converted_ret_len = uidna_IDNToASCII(ustring,
ustring_len, converted, converted_len,
(int32_t)option, &parse_error, &status);
} else {
converted_ret_len = uidna_IDNToUnicode(ustring,
ustring_len, converted, converted_len,
(int32_t)option, &parse_error, &status);
}
if (status != U_BUFFER_OVERFLOW_ERROR)
break;
// If we have a buffer overflow error, try again with a larger buffer
free(converted);
converted = NULL;
converted_len = converted_len * 2;
}
free(ustring);
if (U_FAILURE(status)) {
free(converted);
errorcode = status;
return false;
}
// Convert the string back to UTF-8
status = U_ZERO_ERROR;
intl_convert_utf16_to_utf8(&converted_utf8, &converted_utf8_len,
converted, converted_ret_len, &status);
free(converted);
if (U_FAILURE(status)) {
free(converted_utf8);
errorcode = status;
return false;
}
// Return the string
return String(converted_utf8, converted_utf8_len, AttachString);
}
示例8: DECLARE_THROW_SCOPE
void IntlPluralRules::initializePluralRules(ExecState& exec, JSValue locales, JSValue optionsValue)
{
VM& vm = exec.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
// 13.1.1 InitializePluralRules (pluralRules, locales, options)
// https://tc39.github.io/ecma402/#sec-initializepluralrules
Vector<String> requestedLocales = canonicalizeLocaleList(exec, locales);
RETURN_IF_EXCEPTION(scope, void());
JSObject* options;
if (optionsValue.isUndefined())
options = constructEmptyObject(&exec, exec.lexicalGlobalObject()->nullPrototypeObjectStructure());
else {
options = optionsValue.toObject(&exec);
RETURN_IF_EXCEPTION(scope, void());
}
HashMap<String, String> localeOpt;
String localeMatcher = intlStringOption(exec, options, vm.propertyNames->localeMatcher, { "lookup", "best fit" }, "localeMatcher must be either \"lookup\" or \"best fit\"", "best fit");
RETURN_IF_EXCEPTION(scope, void());
localeOpt.add(vm.propertyNames->localeMatcher.string(), localeMatcher);
const HashSet<String> availableLocales = exec.jsCallee()->globalObject(vm)->intlNumberFormatAvailableLocales();
HashMap<String, String> resolved = resolveLocale(exec, availableLocales, requestedLocales, localeOpt, nullptr, 0, IntlPRInternal::localeData);
m_locale = resolved.get(vm.propertyNames->locale.string());
if (m_locale.isEmpty()) {
throwTypeError(&exec, scope, "failed to initialize PluralRules due to invalid locale"_s);
return;
}
String typeString = intlStringOption(exec, options, Identifier::fromString(&vm, "type"), { "cardinal", "ordinal" }, "type must be \"cardinal\" or \"ordinal\"", "cardinal");
RETURN_IF_EXCEPTION(scope, void());
m_type = typeString == "ordinal" ? UPLURAL_TYPE_ORDINAL : UPLURAL_TYPE_CARDINAL;
unsigned minimumIntegerDigits = intlNumberOption(exec, options, Identifier::fromString(&vm, "minimumIntegerDigits"), 1, 21, 1);
RETURN_IF_EXCEPTION(scope, void());
m_minimumIntegerDigits = minimumIntegerDigits;
unsigned minimumFractionDigitsDefault = 0;
unsigned minimumFractionDigits = intlNumberOption(exec, options, Identifier::fromString(&vm, "minimumFractionDigits"), 0, 20, minimumFractionDigitsDefault);
RETURN_IF_EXCEPTION(scope, void());
m_minimumFractionDigits = minimumFractionDigits;
unsigned maximumFractionDigitsDefault = std::max(minimumFractionDigits, 3u);
unsigned maximumFractionDigits = intlNumberOption(exec, options, Identifier::fromString(&vm, "maximumFractionDigits"), minimumFractionDigits, 20, maximumFractionDigitsDefault);
RETURN_IF_EXCEPTION(scope, void());
m_maximumFractionDigits = maximumFractionDigits;
JSValue minimumSignificantDigitsValue = options->get(&exec, Identifier::fromString(&vm, "minimumSignificantDigits"));
RETURN_IF_EXCEPTION(scope, void());
JSValue maximumSignificantDigitsValue = options->get(&exec, Identifier::fromString(&vm, "maximumSignificantDigits"));
RETURN_IF_EXCEPTION(scope, void());
if (!minimumSignificantDigitsValue.isUndefined() || !maximumSignificantDigitsValue.isUndefined()) {
unsigned minimumSignificantDigits = intlNumberOption(exec, options, Identifier::fromString(&vm, "minimumSignificantDigits"), 1, 21, 1);
RETURN_IF_EXCEPTION(scope, void());
unsigned maximumSignificantDigits = intlNumberOption(exec, options, Identifier::fromString(&vm, "maximumSignificantDigits"), minimumSignificantDigits, 21, 21);
RETURN_IF_EXCEPTION(scope, void());
m_minimumSignificantDigits = minimumSignificantDigits;
m_maximumSignificantDigits = maximumSignificantDigits;
}
UErrorCode status = U_ZERO_ERROR;
m_numberFormat = std::unique_ptr<UNumberFormat, UNumberFormatDeleter>(unum_open(UNUM_DECIMAL, nullptr, 0, m_locale.utf8().data(), nullptr, &status));
if (U_FAILURE(status)) {
throwTypeError(&exec, scope, "failed to initialize PluralRules"_s);
return;
}
if (m_minimumSignificantDigits) {
unum_setAttribute(m_numberFormat.get(), UNUM_SIGNIFICANT_DIGITS_USED, true);
unum_setAttribute(m_numberFormat.get(), UNUM_MIN_SIGNIFICANT_DIGITS, m_minimumSignificantDigits.value());
unum_setAttribute(m_numberFormat.get(), UNUM_MAX_SIGNIFICANT_DIGITS, m_maximumSignificantDigits.value());
} else {
unum_setAttribute(m_numberFormat.get(), UNUM_MIN_INTEGER_DIGITS, m_minimumIntegerDigits);
unum_setAttribute(m_numberFormat.get(), UNUM_MIN_FRACTION_DIGITS, m_minimumFractionDigits);
unum_setAttribute(m_numberFormat.get(), UNUM_MAX_FRACTION_DIGITS, m_maximumFractionDigits);
}
status = U_ZERO_ERROR;
m_pluralRules = std::unique_ptr<UPluralRules, UPluralRulesDeleter>(uplrules_openForType(m_locale.utf8().data(), m_type, &status));
if (U_FAILURE(status)) {
throwTypeError(&exec, scope, "failed to initialize PluralRules"_s);
return;
}
m_initializedPluralRules = true;
}
示例9: icu_breakpoints
int icu_breakpoints(lua_State *L) {
const char* input = luaL_checkstring(L, 1);
int input_l = strlen(input);
const char* locale = luaL_checkstring(L, 2);
UChar *buffer;
int32_t l, breakcount = 0;
UErrorCode err = U_ZERO_ERROR;
u_strFromUTF8(NULL, 0, &l, input, input_l, &err);
/* Above call returns an error every time. */
err = U_ZERO_ERROR;
buffer = malloc(l * sizeof(UChar));
u_strFromUTF8(buffer, l, &l, input, input_l, &err);
UBreakIterator* wordbreaks, *linebreaks;
int32_t i, previous;
wordbreaks = ubrk_open(UBRK_WORD, locale, buffer, l, &err);
if(U_FAILURE(err)) {
luaL_error(L, "Word break parser failure: %s", u_errorName(err));
}
linebreaks = ubrk_open(UBRK_LINE, locale, buffer, l, &err);
if(U_FAILURE(err)) {
luaL_error(L, "Line break parser failure: %s", u_errorName(err));
}
previous = 0;
i = 0;
while (i <= l) {
int32_t out_l;
int32_t type;
if (!ubrk_isBoundary(linebreaks, i) && !ubrk_isBoundary(wordbreaks,i)) {
i++; continue;
}
lua_checkstack(L, 3);
/* At some kind of boundary */
lua_newtable(L);
lua_pushstring(L, "type");
lua_pushstring(L, ubrk_isBoundary(linebreaks,i) ? "line" : "word");
lua_settable(L, -3);
int32_t utf8_index = 0;
err = U_ZERO_ERROR;
u_strToUTF8(NULL, 0, &utf8_index, buffer, i, &err);
assert(U_SUCCESS(err) || err == U_BUFFER_OVERFLOW_ERROR);
lua_pushstring(L, "index");
lua_pushinteger(L, utf8_index);
lua_settable(L, -3);
if (ubrk_isBoundary(linebreaks, i)) {
lua_pushstring(L, "subtype");
type = ubrk_getRuleStatus(linebreaks);
if (type >= UBRK_LINE_SOFT && type < UBRK_LINE_SOFT_LIMIT) {
lua_pushstring(L, "soft");
} else {
lua_pushstring(L, "hard");
}
lua_settable(L, -3);
}
lua_pushstring(L, "token");
lua_pushlstring(L, input+previous, utf8_index-previous);
lua_settable(L, -3);
previous = utf8_index;
breakcount++;
i++;
}
ubrk_close(wordbreaks);
ubrk_close(linebreaks);
return breakcount;
}
示例10: TestGetSortKey
static void TestGetSortKey() {
/* This is meant to test a buffer reallocation crash while using
French secondary sorting with a large buffer.
The fact that Japanese characters are used is irrelevant. */
static const UChar pucUTF16[] = {
0x3049,0x30b9,0x3088,0xfffd,0xfffd,0x308f,0xfffd,0x3042,
0xfffd,0xfffd,0x305e,0xfffd,0x30b6,0x30bb,0x305b,0x30b1,
0x3050,0x30af,0x304e,0x30bd,0xfffd,0x30c6,0xfffd,0xfffd,
0x30e1,0xfffd,0xfffd,0x30d9,0xfffd,0x3092,0x3075,0x304a,
0x3074,0x3070,0x30f5,0x30c4,0x306e,0x30df,0x3053,0xfffd,
0x30a6,0x30b6,0x30e0,0xfffd,0x30bc,0x30ef,0x3087,0x30cc,
0x305f,0x30de,0xfffd,0x3090,0x3063,0x30dc,0x30b6,0x30b9,
0x30d2,0x3072,0x3061,0xfffd,0xfffd,0xfffd,0x307b,0x3092,
0x30a5,0x30a9,0x30b1,0x30e7,0xfffd,0xfffd,0xfffd,0xfffd,
0xfffd,0x305e,0xfffd,0x30c7,0x30ae,0x305b,0x308b,0x30c0,
0x30f5,0xfffd,0xfffd,0xfffd,0x307d,0x304e,0xfffd,0xfffd,
0x30c0,0x30c8,0x306f,0x307a,0x30dd,0x30e4,0x3084,0xfffd,
0x308c,0x30f1,0xfffd,0x30c6,0xfffd,0x307a,0xfffd,0x3052,
0x3056,0x305d,0x30b7,0xfffd,0x305b,0x30b0,0x30b9,0xfffd,
0x30b2,0x306d,0x3044,0xfffd,0x3073,0xfffd,0x30be,0x30cf,
0x3080,0xfffd,0x30a8,0x30f5,0x30a5,0x30c7,0x307c,0xfffd,
0x30d1,0x305f,0x30b2,0xfffd,0x3053,0x30ca,0xfffd,0x30dd,
0x3058,0x30c0,0x305d,0x30e1,0xfffd,0x30bb,0x305f,0x30d1,
0x30f2,0x3058,0x3086,0x30ce,0x30db,0x30cb,0x30e9,0xfffd,
0x308c,0xfffd,0xfffd,0x30af,0x30c4,0x3076,0x304c,0x30f5,
0x30e8,0x308c,0xfffd,0x30e2,0x3073,0x30a3,0x304e,0x30ea,
0xfffd,0x304f,0xfffd,0x306c,0x3044,0xfffd,0xfffd,0x30c9,
0xfffd,0x30f5,0xfffd,0xfffd,0xfffd,0x30eb,0x30a8,0xfffd,
0x306d,0x307d,0x30d8,0x3069,0xfffd,0xfffd,0x3086,0x30a9,
0xfffd,0x3076,0x30e9,0x30cc,0x3074,0x30e0,0xfffd,0xfffd,
0xfffd,0x30f0,0x3086,0x30ac,0x3076,0x3068,0x30c7,0xfffd,
0x30b7,0x30d2,0x3048,0x308e,0x30e8,0x30d9,0x30ce,0x30d0,
0x308b,0x30ee,0x30e6,0x3079,0x30f3,0x30af,0xfffd,0x3079,
0xfffd,0xfffd,0x30ca,0x30bf,0xfffd,0x30b5,0xfffd,0xfffd,
0x3093,0xfffd,0x30ba,0xfffd,0x3076,0x3047,0x304a,0xfffd,
0xfffd,0x3086,0xfffd,0x3081,0xfffd,0x30f6,0x3066,0xfffd,
0xfffd,0x30b6,0x30ef,0x30e2,0x30bf,0xfffd,0x3053,0x304a,
0xfffd,0xfffd,0x304a,0x30e8,0xfffd,0x30e2,0xfffd,0xfffd,
0x305c,0x3081,0x30c6,0xfffd,0x3091,0x3046,0x306a,0x3059,
0xfffd,0xfffd,0x30dd,0x30d1,0x308a,0x30ee,0xfffd,0xfffd,
0x308a,0x3042,0x30da,0xfffd,0x3064,0x30ef,0x305c,0x306b,
0xfffd,0x30ca,0x3085,0x3067,0x30ea,0x30c2,0x30c8,0xfffd,
0x30f5,0xfffd,0xfffd,0xfffd,0x30ca,0xfffd,0x3050,0x30f1,
0x3050,0x3053,0x3072,0xfffd,0xfffd,0xfffd,0x3074,0xfffd,
0x304b,0x30dd,0x306d,0xfffd,0x3049,0x30a1,0x30cc,0x30de,
0x30ae,0x307b,0x308a,0xfffd,0x3065,0xfffd,0xfffd,0x30c0,
0xfffd,0x3048,0x30dc,0x304f,0x3085,0x3059,0x304b,0x30d3,
0x30eb,0x30a4,0x3073,0xfffd,0x30ba,0x308f,0x30a7,0x30c3,
0x3074,0x30cf,0x306c,0x3053,0x30c0,0xfffd,0x3066,0xfffd,
0x308f,0xfffd,0x30b5,0xfffd,0x3092,0x30c4,0xfffd,0x30d6,
0x3056,0x30ad,0x30d2,0x30ba,0xfffd,0x30e6,0x304c,0x3088,
0x30b6,0x3048,0x3077,0x30d1,0xfffd,0x3050,0xfffd,0x3042,
0xfffd,0xfffd,0x308f,0xfffd,0x30c1,0xfffd,0x3074,0x3061,
0x3056,0x30e5,0xfffd,0xfffd,0x3057,0xfffd,0xfffd,0xfffd,
0xfffd,0x30bd,0x30b3,0x30ee,0xfffd,0x30f2,0x3084,0x3050,
0xfffd,0x30e7,0xfffd,0xfffd,0x3060,0x3049,0x30f2,0x30ad,
0x30bf,0x30f1,0x30a2,0xfffd,0x30af,0xfffd,0x3060,0x30a1,
0x30e9,0x30c3,0xfffd,0x3072,0x3093,0x3070,0xfffd,0x308f,
0x3060,0xfffd,0x3067,0x306f,0x3082,0x308b,0x3051,0xfffd,
0x3058,0xfffd,0xfffd,0x30a8,0x3051,0x3054,0x30ad,0x30f0,
0x3053,0xfffd,0x30e1,0x30d7,0x308d,0x307f,0x30be,0x30b0,
0xfffd,0x30db,0xfffd,0x30d1,0xfffd,0x3054,0x30a5,0xfffd,
0x306a,0xfffd,0x305c,0xfffd,0x3052,0x3088,0xfffd,0x306e,
0xfffd,0x30a9,0x30a1,0x30b4,0x3083,0x30bd,0xfffd,0xfffd,
0x306a,0x3070,0x30cd,0xfffd,0x3072,0x30ed,0x30c6,0x30be,
0x30c4,0x305e,0x30b3,0x30e1,0x308a,0xfffd,0x305b,0xfffd,
0x3042,0x3088,0xfffd,0x304c,0xfffd,0x3089,0x3071,0xfffd,
0xfffd,0x30c6,0x3062,0x3079,0xfffd,0x304b,0x304a,0xfffd,
0x30ad,0x3045,0x3045,0x3087,0xfffd,0x306a,0x308b,0x0000,
0x30bd,0x3065,0x30b8,0x3086,0x30d3,0x3076,0xfffd,0xfffd,
0x308f,0x3053,0x307c,0x3053,0x3084,0x30ae,0x30c4,0x3045,
0x30a8,0x30d0,0x30e1,0x308c,0x30e6,0x30b7,0xfffd,0xfffd,
0xfffd,0x3046,0x305f,0xfffd,0x3086,0x30ab,0xfffd,0xfffd,
0x30c8,0xfffd,0x30a1,0x3052,0x3059,0xfffd,0x30a4,0xfffd,
0xfffd,0x308c,0x3085,0x30ab,0x30b5,0x3091,0x30bf,0x30e3,
0xfffd,0xfffd,0x3087,0xfffd,0x30f6,0x3051,0x30bd,0x3092,
0x3063,0xfffd,0x30a9,0x3063,0x306e,0xfffd,0xfffd,0xfffd,
0x306c,0xfffd,0x307e,0x30ad,0x3077,0x30c2,0x30e9,0x30d5,
0xfffd,0xfffd,0x30c6,0x305c,0xfffd,0xfffd,0x3089,0xfffd,
0x3048,0x30cb,0x308c,0xfffd,0xfffd,0x3044,0xfffd,0x3080,
0x3063,0x3079,0xfffd,0x308a,0x30cb,0x3042,0x3057,0xfffd,
0x307c,0x30c1,0x30a8,0x30cf,0xfffd,0x3083,0xfffd,0xfffd,
0x306c,0xfffd,0x305e,0x3092,0xfffd,0x30dc,0x30b0,0x3081,
0x30e3,0x30f0,0x304e,0x30cc,0x308e,0x30c4,0x30ad
};
UErrorCode status = U_ZERO_ERROR;
UCollator *pCollator;
int32_t lenActualSortKey;
uint8_t pucSortKey[4096];
static const int32_t LENSORTKEY = (int32_t)sizeof(pucSortKey);
ucol_prepareShortStringOpen("LFR_AN_CX_EX_FO_HX_NX_S3", 0, NULL, &status);
pCollator = ucol_openFromShortString("LFR_AN_CX_EX_FO_HX_NX_S3", 0, NULL, &status);
if (U_FAILURE(status)) {
log_data_err("error opening collator -> %s. (Are you missing data?)\n", u_errorName(status));
return;
}
//.........这里部分代码省略.........
示例11: zap
//--------------------------------------------------------------------------
//
// Assignment Operator
//
//--------------------------------------------------------------------------
RegexPattern &RegexPattern::operator = (const RegexPattern &other) {
if (this == &other) {
// Source and destination are the same. Don't do anything.
return *this;
}
// Clean out any previous contents of object being assigned to.
zap();
// Give target object a default initialization
init();
// Copy simple fields
fDeferredStatus = other.fDeferredStatus;
if (U_FAILURE(fDeferredStatus)) {
return *this;
}
if (other.fPatternString == NULL) {
fPatternString = NULL;
fPattern = utext_clone(fPattern, other.fPattern, FALSE, TRUE, &fDeferredStatus);
} else {
fPatternString = new UnicodeString(*(other.fPatternString));
if (fPatternString == NULL) {
fDeferredStatus = U_MEMORY_ALLOCATION_ERROR;
} else {
fPattern = utext_openConstUnicodeString(NULL, fPatternString, &fDeferredStatus);
}
}
if (U_FAILURE(fDeferredStatus)) {
return *this;
}
fFlags = other.fFlags;
fLiteralText = other.fLiteralText;
fMinMatchLen = other.fMinMatchLen;
fFrameSize = other.fFrameSize;
fDataSize = other.fDataSize;
fStaticSets = other.fStaticSets;
fStaticSets8 = other.fStaticSets8;
fStartType = other.fStartType;
fInitialStringIdx = other.fInitialStringIdx;
fInitialStringLen = other.fInitialStringLen;
*fInitialChars = *other.fInitialChars;
fInitialChar = other.fInitialChar;
*fInitialChars8 = *other.fInitialChars8;
fNeedsAltInput = other.fNeedsAltInput;
// Copy the pattern. It's just values, nothing deep to copy.
fCompiledPat->assign(*other.fCompiledPat, fDeferredStatus);
fGroupMap->assign(*other.fGroupMap, fDeferredStatus);
// Copy the Unicode Sets.
// Could be made more efficient if the sets were reference counted and shared,
// but I doubt that pattern copying will be particularly common.
// Note: init() already added an empty element zero to fSets
int32_t i;
int32_t numSets = other.fSets->size();
fSets8 = new Regex8BitSet[numSets];
if (fSets8 == NULL) {
fDeferredStatus = U_MEMORY_ALLOCATION_ERROR;
return *this;
}
for (i=1; i<numSets; i++) {
if (U_FAILURE(fDeferredStatus)) {
return *this;
}
UnicodeSet *sourceSet = (UnicodeSet *)other.fSets->elementAt(i);
UnicodeSet *newSet = new UnicodeSet(*sourceSet);
if (newSet == NULL) {
fDeferredStatus = U_MEMORY_ALLOCATION_ERROR;
break;
}
fSets->addElement(newSet, fDeferredStatus);
fSets8[i] = other.fSets8[i];
}
// Copy the named capture group hash map.
int32_t hashPos = UHASH_FIRST;
while (const UHashElement *hashEl = uhash_nextElement(other.fNamedCaptureMap, &hashPos)) {
if (U_FAILURE(fDeferredStatus)) {
break;
}
const UnicodeString *name = (const UnicodeString *)hashEl->key.pointer;
UnicodeString *key = new UnicodeString(*name);
int32_t val = hashEl->value.integer;
if (key == NULL) {
fDeferredStatus = U_MEMORY_ALLOCATION_ERROR;
} else {
uhash_puti(fNamedCaptureMap, key, val, &fDeferredStatus);
}
}
return *this;
//.........这里部分代码省略.........
示例12: uspoof_getCheckResultNumerics
U_CAPI const USet* U_EXPORT2
uspoof_getCheckResultNumerics(const USpoofCheckResult *checkResult, UErrorCode *status) {
const CheckResult* This = CheckResult::validateThis(checkResult, *status);
if (U_FAILURE(*status)) { return NULL; }
return This->fNumerics.toUSet();
}
示例13: uspoof_getCheckResultRestrictionLevel
U_CAPI URestrictionLevel U_EXPORT2
uspoof_getCheckResultRestrictionLevel(const USpoofCheckResult *checkResult, UErrorCode *status) {
const CheckResult* This = CheckResult::validateThis(checkResult, *status);
if (U_FAILURE(*status)) { return USPOOF_UNRESTRICTIVE; }
return This->fRestrictionLevel;
}
示例14: uspoof_getCheckResultChecks
U_CAPI int32_t U_EXPORT2
uspoof_getCheckResultChecks(const USpoofCheckResult *checkResult, UErrorCode *status) {
const CheckResult* This = CheckResult::validateThis(checkResult, *status);
if (U_FAILURE(*status)) { return 0; }
return This->fChecks;
}
示例15: uscript_getScript
const LanguageBreakEngine *
ICULanguageBreakFactory::loadEngineFor(UChar32 c, int32_t breakType) {
UErrorCode status = U_ZERO_ERROR;
UScriptCode code = uscript_getScript(c, &status);
if (U_SUCCESS(status)) {
DictionaryMatcher *m = loadDictionaryMatcherFor(code, breakType);
if (m != NULL) {
const LanguageBreakEngine *engine = NULL;
switch(code) {
case USCRIPT_THAI:
engine = new ThaiBreakEngine(m, status);
break;
case USCRIPT_LAO:
engine = new LaoBreakEngine(m, status);
break;
case USCRIPT_MYANMAR:
engine = new BurmeseBreakEngine(m, status);
break;
case USCRIPT_KHMER:
engine = new KhmerBreakEngine(m, status);
break;
#if !UCONFIG_NO_NORMALIZATION
// CJK not available w/o normalization
case USCRIPT_HANGUL:
engine = new CjkBreakEngine(m, kKorean, status);
break;
// use same BreakEngine and dictionary for both Chinese and Japanese
case USCRIPT_HIRAGANA:
case USCRIPT_KATAKANA:
case USCRIPT_HAN:
engine = new CjkBreakEngine(m, kChineseJapanese, status);
break;
#if 0
// TODO: Have to get some characters with script=common handled
// by CjkBreakEngine (e.g. U+309B). Simply subjecting
// them to CjkBreakEngine does not work. The engine has to
// special-case them.
case USCRIPT_COMMON:
{
UBlockCode block = ublock_getCode(code);
if (block == UBLOCK_HIRAGANA || block == UBLOCK_KATAKANA)
engine = new CjkBreakEngine(dict, kChineseJapanese, status);
break;
}
#endif
#endif
default:
break;
}
if (engine == NULL) {
delete m;
}
else if (U_FAILURE(status)) {
delete engine;
engine = NULL;
}
return engine;
}
}
return NULL;
}