Example #1
0
        public override BreakIterator CreateBreakIterator(ULocale locale, int kind)
        {
            // TODO: convert to ULocale when service switches over
            if (service.IsDefault())
            {
                return(CreateBreakInstance(locale, kind));
            }
            ULocale[]     actualLoc = new ULocale[1];
            BreakIterator iter      = (BreakIterator)service.Get(locale, kind,
                                                                 actualLoc);

            iter.SetLocale(actualLoc[0], actualLoc[0]);     // services make no
                                                            // distinction between
                                                            // actual & valid
            return(iter);
        }
Example #2
0
 /// <summary>
 /// Register a new break iterator of the indicated kind, to use in the given
 /// locale. Clones of the iterator will be returned if a request for a break
 /// iterator of the given kind matches or falls back to this locale.
 /// </summary>
 ///
 /// <param name="iter">the BreakIterator instance to adopt.</param>
 /// <param name="locale">the Locale for which this instance is to be registered</param>
 /// <param name="kind">the type of iterator for which this instance is to beregistered</param>
 /// <returns>a registry key that can be used to unregister this instance</returns>
 /// @stable ICU 3.2
 public static Object RegisterInstance(BreakIterator iter, ULocale locale,
                                       int kind)
 {
     // If the registered object matches the one in the cache, then
     // flush the cached object.
     if (iterCache[kind] != null)
     {
         BreakIterator.BreakIteratorCache cache = (BreakIterator.BreakIteratorCache)iterCache[kind].Target;
         if (cache != null)
         {
             if (cache.GetLocale().Equals(locale))
             {
                 iterCache[kind] = null;
             }
         }
     }
     return(GetShim().RegisterInstance(iter, locale, kind));
 }
Example #3
0
        // end of registration

        /// <exclude/>
        /// <summary>
        /// Get a particular kind of BreakIterator for a locale. Avoids writing a
        /// switch statement with getXYZInstance(where) calls.
        /// </summary>
        ///
        public static BreakIterator GetBreakInstance(ULocale where, int kind)
        {
            if (iterCache[kind] != null)
            {
                BreakIterator.BreakIteratorCache cache = (BreakIterator.BreakIteratorCache)iterCache[kind].Target;
                if (cache != null)
                {
                    if (cache.GetLocale().Equals(where))
                    {
                        return(cache.CreateBreakInstance());
                    }
                }
            }

            // sigh, all to avoid linking in ICULocaleData...
            BreakIterator result = GetShim().CreateBreakIterator(where, kind);

            BreakIterator.BreakIteratorCache cache_0 = new BreakIterator.BreakIteratorCache(where, result);
            iterCache[kind] = new WeakReference(cache_0);
            return(result);
        }
Example #4
0
        // protected constructor ----------------------------------------------

        /// <summary>
        /// Protected constructor for use by subclasses. Initializes the iterator
        /// with the argument target text for searching and sets the BreakIterator.
        /// See class documentation for more details on the use of the target text
        /// and BreakIterator.
        /// </summary>
        ///
        /// <param name="target">The target text to be searched.</param>
        /// <param name="breaker">A <see cref="T:IBM.ICU.Text.BreakIterator"/> that is used to determine theboundaries of a logical match. This argument can be null.</param>
        /// <exception cref="IllegalArgumentException">thrown when argument target is null, or of length 0</exception>
        /// <seealso cref="T:IBM.ICU.Text.BreakIterator"/>
        /// @stable ICU 2.0
        protected internal SearchIterator(ICharacterIterator target, BreakIterator breaker)
        {
            if (target == null ||
                (target.GetEndIndex() - target.GetBeginIndex()) == 0)
            {
                throw new ArgumentException("Illegal argument target. "
                                            + " Argument can not be null or of length 0");
            }
            targetText    = target;
            breakIterator = breaker;
            if (breakIterator != null)
            {
                breakIterator.SetText(target);
            }
            matchLength           = 0;
            m_lastMatchStart_     = DONE;
            m_isOverlap_          = false;
            m_isForwardSearching_ = true;
            m_reset_     = true;
            m_setOffset_ = DONE;
        }
Example #5
0
 public abstract Object RegisterInstance(BreakIterator iter_0, ULocale l,
                                         int k);
Example #6
0
 internal BreakIteratorCache(ULocale where_0, BreakIterator iter_1)
 {
     this.where = where_0;
     this.iter  = (BreakIterator)iter_1.Clone();
 }
Example #7
0
 /// <summary>
 /// Register a new break iterator of the indicated kind, to use in the given
 /// locale. Clones of the iterator will be returned if a request for a break
 /// iterator of the given kind matches or falls back to this locale.
 /// </summary>
 ///
 /// <param name="iter">the BreakIterator instance to adopt.</param>
 /// <param name="locale">the Locale for which this instance is to be registered</param>
 /// <param name="kind">the type of iterator for which this instance is to beregistered</param>
 /// <returns>a registry key that can be used to unregister this instance</returns>
 /// @stable ICU 2.4
 public static Object RegisterInstance(BreakIterator iter, ILOG.J2CsMapping.Util.Locale locale,
                                       int kind)
 {
     return(RegisterInstance(iter, IBM.ICU.Util.ULocale.ForLocale(locale), kind));
 }
Example #8
0
 public override Object RegisterInstance(BreakIterator iter, ULocale locale, int kind)
 {
     iter.SetText(new ILOG.J2CsMapping.Text.StringCharacterIterator(""));
     return(service.RegisterObject(iter, locale, kind));
 }
Example #9
0
        private static BreakIterator CreateBreakInstance(ULocale locale, int kind)
        {
            BreakIterator     iter = null;
            ICUResourceBundle rb   = (ICUResourceBundle)IBM.ICU.Util.UResourceBundle
                                     .GetBundleInstance(IBM.ICU.Impl.ICUResourceBundle.ICU_BRKITR_BASE_NAME,
                                                        locale);

            //
            // Get the binary rules. These are needed for both normal
            // RulesBasedBreakIterators
            // and for Dictionary iterators.
            //
            Stream ruleStream = null;

            try {
                String typeKey       = KIND_NAMES[kind];
                String brkfname      = rb.GetStringWithFallback("boundaries/" + typeKey);
                String rulesFileName = IBM.ICU.Impl.ICUResourceBundle.ICU_BASE_NAME /*+
                                                                                     * IBM.ICU.Impl.ICUResourceBundle.ICU_BUNDLE*/
                                       + IBM.ICU.Impl.ICUResourceBundle.ICU_BRKITR_NAME + "/" + brkfname;
                ruleStream = IBM.ICU.Impl.ICUData.GetStream(rulesFileName);
            } catch (Exception e) {
                throw new MissingManifestResourceException(e.ToString());
            }

            //
            // Check whether a dictionary exists, and create a DBBI iterator is
            // one does.
            //
            if (DICTIONARY_POSSIBLE[kind])
            {
                // This type of break iterator could potentially use a dictionary.
                //
                try {
                    // ICUResourceBundle dictRes =
                    // (ICUResourceBundle)rb.getObject("BreakDictionaryData");
                    // byte[] dictBytes = null;
                    // dictBytes = dictRes.getBinary(dictBytes);
                    // TODO: Hard code this for now! fix it once
                    // CompactTrieDictionary is ported
                    if (locale.Equals("th"))
                    {
                        String fileName = "data/th.brk";
                        Stream mask0    = IBM.ICU.Impl.ICUData.GetStream(fileName);
                        iter = new DictionaryBasedBreakIterator(ruleStream, mask0);
                    }
                } catch (MissingManifestResourceException e_0) {
                    // Couldn't find a dictionary.
                    // This is normal, and will occur whenever creating a word or
                    // line
                    // break iterator for a locale that does not have a
                    // BreakDictionaryData
                    // resource - meaning for all but Thai.
                    // Fall through to creating a normal RulebasedBreakIterator.
                } catch (IOException e_1) {
                    IBM.ICU.Impl.Assert.Fail(e_1);
                }
            }

            if (iter == null)
            {
                //
                // Create a normal RuleBasedBreakIterator.
                // We have determined that this is not supposed to be a dictionary
                // iterator.
                //
                try {
                    iter = IBM.ICU.Text.RuleBasedBreakIterator
                           .GetInstanceFromCompiledRules(ruleStream);
                } catch (IOException e_2) {
                    // Shouldn't be possible to get here.
                    // If it happens, the compiled rules are probably corrupted in
                    // some way.
                    IBM.ICU.Impl.Assert.Fail(e_2);
                }
            }
            // TODO: Determine valid and actual locale correctly.
            ULocale uloc = IBM.ICU.Util.ULocale.ForLocale(rb.GetLocale());

            iter.SetLocale(uloc, uloc);

            return(iter);
        }
Example #10
0
 public void SetBreakIterator(BreakIterator bi_0)
 {
     this.bi = bi_0;
 }