1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/i18n/uspoof_build.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,85 @@ 1.4 +/* 1.5 + *************************************************************************** 1.6 + * Copyright (C) 2008-2009, International Business Machines Corporation 1.7 + * and others. All Rights Reserved. 1.8 + *************************************************************************** 1.9 + * file name: uspoof_build.cpp 1.10 + * encoding: US-ASCII 1.11 + * tab size: 8 (not used) 1.12 + * indentation:4 1.13 + * 1.14 + * created on: 2008 Dec 8 1.15 + * created by: Andy Heninger 1.16 + * 1.17 + * Unicode Spoof Detection Data Builder 1.18 + * Builder-related functions are kept in separate files so that applications not needing 1.19 + * the builder can more easily exclude them, typically by means of static linking. 1.20 + * 1.21 + * There are three relatively independent sets of Spoof data, 1.22 + * Confusables, 1.23 + * Whole Script Confusables 1.24 + * ID character extensions. 1.25 + * 1.26 + * The data tables for each are built separately, each from its own definitions 1.27 + */ 1.28 + 1.29 +#include "unicode/utypes.h" 1.30 +#include "unicode/uspoof.h" 1.31 +#include "unicode/unorm.h" 1.32 +#include "unicode/uregex.h" 1.33 +#include "unicode/ustring.h" 1.34 +#include "cmemory.h" 1.35 +#include "uspoof_impl.h" 1.36 +#include "uhash.h" 1.37 +#include "uvector.h" 1.38 +#include "uassert.h" 1.39 +#include "uarrsort.h" 1.40 +#include "uspoof_conf.h" 1.41 +#include "uspoof_wsconf.h" 1.42 + 1.43 +#if !UCONFIG_NO_NORMALIZATION 1.44 + 1.45 +U_NAMESPACE_USE 1.46 + 1.47 + 1.48 +// The main data building function 1.49 + 1.50 +U_CAPI USpoofChecker * U_EXPORT2 1.51 +uspoof_openFromSource(const char *confusables, int32_t confusablesLen, 1.52 + const char *confusablesWholeScript, int32_t confusablesWholeScriptLen, 1.53 + int32_t *errorType, UParseError *pe, UErrorCode *status) { 1.54 + 1.55 + if (U_FAILURE(*status)) { 1.56 + return NULL; 1.57 + } 1.58 +#if UCONFIG_NO_REGULAR_EXPRESSIONS 1.59 + *status = U_UNSUPPORTED_ERROR; 1.60 + return NULL; 1.61 +#else 1.62 + if (errorType!=NULL) { 1.63 + *errorType = 0; 1.64 + } 1.65 + if (pe != NULL) { 1.66 + pe->line = 0; 1.67 + pe->offset = 0; 1.68 + pe->preContext[0] = 0; 1.69 + pe->postContext[0] = 0; 1.70 + } 1.71 + 1.72 + // Set up a shell of a spoof detector, with empty data. 1.73 + SpoofData *newSpoofData = new SpoofData(*status); 1.74 + SpoofImpl *This = new SpoofImpl(newSpoofData, *status); 1.75 + 1.76 + // Compile the binary data from the source (text) format. 1.77 + ConfusabledataBuilder::buildConfusableData(This, confusables, confusablesLen, errorType, pe, *status); 1.78 + buildWSConfusableData(This, confusablesWholeScript, confusablesWholeScriptLen, pe, *status); 1.79 + 1.80 + if (U_FAILURE(*status)) { 1.81 + delete This; 1.82 + This = NULL; 1.83 + } 1.84 + return (USpoofChecker *)This; 1.85 +#endif // UCONFIG_NO_REGULAR_EXPRESSIONS 1.86 +} 1.87 + 1.88 +#endif