]> granicus.if.org Git - icu/commitdiff
ICU-10286 initial stub checkin of FilteredBreakIteratorBuilder (todo: windows proj...
authorSteven R. Loomis <srl@icu-project.org>
Wed, 5 Mar 2014 20:44:47 +0000 (20:44 +0000)
committerSteven R. Loomis <srl@icu-project.org>
Wed, 5 Mar 2014 20:44:47 +0000 (20:44 +0000)
X-SVN-Rev: 35346

icu4c/source/i18n/Makefile.in
icu4c/source/i18n/filteredbrk.cpp [new file with mode: 0644]
icu4c/source/i18n/unicode/filteredbrk.h [new file with mode: 0644]

index e20bfa35d693148699846ccf6a34326adea323ed..3d0c487bde97202c90f4f094082d51bc87c05205 100644 (file)
@@ -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 (file)
index 0000000..fcfa75c
--- /dev/null
@@ -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 (file)
index 0000000..cb2768c
--- /dev/null
@@ -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