From d6d65ed16b4a1c5b4698d19e6725c90eb21b444a Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Wed, 5 Mar 2014 20:44:47 +0000 Subject: [PATCH] ICU-10286 initial stub checkin of FilteredBreakIteratorBuilder (todo: windows proj files) X-SVN-Rev: 35346 --- icu4c/source/i18n/Makefile.in | 2 +- icu4c/source/i18n/filteredbrk.cpp | 33 ++++++++ icu4c/source/i18n/unicode/filteredbrk.h | 104 ++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 icu4c/source/i18n/filteredbrk.cpp create mode 100644 icu4c/source/i18n/unicode/filteredbrk.h diff --git a/icu4c/source/i18n/Makefile.in b/icu4c/source/i18n/Makefile.in index e20bfa35d69..3d0c487bde9 100644 --- a/icu4c/source/i18n/Makefile.in +++ b/icu4c/source/i18n/Makefile.in @@ -94,7 +94,7 @@ uspoof.o uspoof_impl.o uspoof_build.o uspoof_conf.o uspoof_wsconf.o decfmtst.o s ztrans.o zrule.o vzone.o fphdlimp.o fpositer.o locdspnm.o \ decNumber.o decContext.o alphaindex.o tznames.o tznames_impl.o tzgnames.o \ tzfmt.o compactdecimalformat.o gender.o region.o scriptset.o identifier_info.o \ -uregion.o reldatefmt.o quantityformatter.o measunit.o +uregion.o reldatefmt.o quantityformatter.o measunit.o filteredbrk.o ## Header files to install HEADERS = $(srcdir)/unicode/*.h diff --git a/icu4c/source/i18n/filteredbrk.cpp b/icu4c/source/i18n/filteredbrk.cpp new file mode 100644 index 00000000000..fcfa75c5bd2 --- /dev/null +++ b/icu4c/source/i18n/filteredbrk.cpp @@ -0,0 +1,33 @@ +/* +******************************************************************************* +* Copyright (C) 2014, International Business Machines Corporation and +* others. All Rights Reserved. +******************************************************************************* +*/ + +#include "unicode/filteredbrk.h" + +U_NAMESPACE_BEGIN + +FilteredBreakIteratorBuilder::FilteredBreakIteratorBuilder() { +} + +FilteredBreakIteratorBuilder::~FilteredBreakIteratorBuilder() { +} + +FilteredBreakIteratorBuilder * +FilteredBreakIteratorBuilder::createInstance(const Locale& /*where*/, UErrorCode& status) { + if (U_FAILURE(status)) return NULL; + + status = U_UNSUPPORTED_ERROR; + return NULL; +} + + +FilteredBreakIteratorBuilder * +FilteredBreakIteratorBuilder::createInstance(UErrorCode& status) { + status = U_UNSUPPORTED_ERROR; + return NULL; +} + +U_NAMESPACE_END diff --git a/icu4c/source/i18n/unicode/filteredbrk.h b/icu4c/source/i18n/unicode/filteredbrk.h new file mode 100644 index 00000000000..cb2768ca9a7 --- /dev/null +++ b/icu4c/source/i18n/unicode/filteredbrk.h @@ -0,0 +1,104 @@ +/* +******************************************************************************** +* Copyright (C) 1997-2014, International Business Machines +* Corporation and others. All Rights Reserved. +******************************************************************************** +*/ + +#ifndef FILTEREDBRK_H +#define FILTEREDBRK_H + +#include "unicode/brkiter.h" + +#if !UCONFIG_NO_BREAK_ITERATION + +U_NAMESPACE_BEGIN + +/** + * \file + * \brief C++ API: FilteredBreakIteratorBuilder + */ + +/** + * The BreakIteratorFilter is used to modify the behavior of a BreakIterator + * by constructing a new BreakIterator which skips certain breaks as "exceptions". + * See http://www.unicode.org/reports/tr35/tr35-general.html#Segmentation_Exceptions . + * For example, a typical English Sentence Break Iterator would break on the space + * in the string "Mr. Smith" (resulting in two segments), + * but with "Mr." as an exception, a filtered break iterator + * would consider the string "Mr. Smith" to be a single segment. + * + * @internal technology preview + */ +class U_COMMON_API FilteredBreakIteratorBuilder : public UObject { + public: + /** + * destructor. + */ + virtual ~FilteredBreakIteratorBuilder(); + + /** + * Construct a FilteredBreakIteratorBuilder based on rules in a locale. + * The rules are taken from CLDR exception data for the locale, + * see http://www.unicode.org/reports/tr35/tr35-general.html#Segmentation_Exceptions + * This is the equivalent of calling createInstance(UErrorCode&) + * and then repeatedly calling addNoBreakAfter(...) with the contents + * of the CLDR exception data. + * @param where the locale. + * @param status The error code. + * @return the new builder + */ + static FilteredBreakIteratorBuilder *createInstance(const Locale& where, UErrorCode& status); + + /** + * Construct an empty FilteredBreakIteratorBuilder. It will have an empty + * exception list. + * @param status The error code. + * @return the new builder + */ + static FilteredBreakIteratorBuilder *createInstance(UErrorCode &status); + + + /** + * Add an exception. The break iterator will not break after this string. + * @param exception the exception string + * @param status error code + * @return returns TRUE if the exception was not present and added, + * FALSE if the call was a no-op because the exception was already present. + */ + virtual UBool suppressBreakAfter(const UnicodeString& exception, UErrorCode& status) = 0; + + /** + * Remove a single exception. + * @param exception the exception to remove + * @param status error code + * @return returns TRUE if the exception was present and removed, + * FALSE if the call was a no-op because the exception was not present. + */ + virtual UBool unsuppressBreakAfter(const UnicodeString& exception, UErrorCode& status) = 0; + + /** + * build a BreakIterator from this builder. + * The resulting BreakIterator is owned by the caller. + * The BreakIteratorFilter may be destroyed before the BreakIterator is. + * Note that the adoptBreakIterator is adopted by the new BreakIterator + * and should no longer be used by the caller. + * @param adoptBreakIterator the break iterator to adopt + * @param status error code + * @return the new BreakIterator, owned by the caller. + */ + virtual BreakIterator *build(BreakIterator* adoptBreakIterator, UErrorCode& status) = 0; + + protected: + /** + * For subclass use + */ + FilteredBreakIteratorBuilder(); +}; + + +U_NAMESPACE_END + +#endif // #if !UCONFIG_NO_BREAK_ITERATION + +#endif // #ifndef FILTEREDBRK_H -- 2.40.0