lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhershko <...@git.apache.org>
Subject [GitHub] lucenenet pull request: Port CharArrayIterator
Date Thu, 17 Dec 2015 23:27:54 GMT
Github user synhershko commented on a diff in the pull request:

    https://github.com/apache/lucenenet/pull/157#discussion_r47976547
  
    --- Diff: src/Lucene.Net.Analysis.Common/Analysis/Util/CharArrayIterator.cs ---
    @@ -1,276 +1,268 @@
     ´╗┐using System;
    +using ICU4NET;
     
    -namespace org.apache.lucene.analysis.util
    +namespace Lucene.Net.Analysis.Util
     {
     
    -	/*
    -	 * Licensed to the Apache Software Foundation (ASF) under one or more
    -	 * contributor license agreements.  See the NOTICE file distributed with
    -	 * this work for additional information regarding copyright ownership.
    -	 * The ASF licenses this file to You under the Apache License, Version 2.0
    -	 * (the "License"); you may not use this file except in compliance with
    -	 * the License.  You may obtain a copy of the License at
    -	 *
    -	 *     http://www.apache.org/licenses/LICENSE-2.0
    -	 *
    -	 * Unless required by applicable law or agreed to in writing, software
    -	 * distributed under the License is distributed on an "AS IS" BASIS,
    -	 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    -	 * See the License for the specific language governing permissions and
    -	 * limitations under the License.
    -	 */
    +    /*
    +     * Licensed to the Apache Software Foundation (ASF) under one or more
    +     * contributor license agreements.  See the NOTICE file distributed with
    +     * this work for additional information regarding copyright ownership.
    +     * The ASF licenses this file to You under the Apache License, Version 2.0
    +     * (the "License"); you may not use this file except in compliance with
    +     * the License.  You may obtain a copy of the License at
    +     *
    +     *     http://www.apache.org/licenses/LICENSE-2.0
    +     *
    +     * Unless required by applicable law or agreed to in writing, software
    +     * distributed under the License is distributed on an "AS IS" BASIS,
    +     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +     * See the License for the specific language governing permissions and
    +     * limitations under the License.
    +     */
     
     
    -	/// <summary>
    -	/// A CharacterIterator used internally for use with <seealso cref="BreakIterator"/>
    -	/// @lucene.internal
    -	/// </summary>
    -	public abstract class CharArrayIterator //: CharacterIterator
    -	{
    -	  private char[] array;
    -	  private int start;
    -	  private int index;
    -	  private int length;
    -	  private int limit;
    +    /// <summary>
    +    /// A CharacterIterator used internally for use with <seealso cref="BreakIterator"/>
    +    /// @lucene.internal
    +    /// </summary>
    +    public abstract class CharArrayIterator : CharacterIterator
    +    {
    +        private char[] array;
    +        private int start;
    +        private int index;
    +        private int length;
    +        private int limit;
     
    -	  public virtual char [] Text
    -	  {
    -		  get
    -		  {
    -			return array;
    -		  }
    -	  }
    +        public virtual char[] Text
    +        {
    +            get
    +            {
    +                return array;
    +            }
    +        }
     
    -	  public virtual int Start
    -	  {
    -		  get
    -		  {
    -			return start;
    -		  }
    -	  }
    +        public virtual int Start
    +        {
    +            get
    +            {
    +                return start;
    +            }
    +        }
     
    -	  public virtual int Length
    -	  {
    -		  get
    -		  {
    -			return length;
    -		  }
    -	  }
    +        public virtual int Length
    +        {
    +            get
    +            {
    +                return length;
    +            }
    +        }
     
    -	  /// <summary>
    -	  /// Set a new region of text to be examined by this iterator
    -	  /// </summary>
    -	  /// <param name="array"> text buffer to examine </param>
    -	  /// <param name="start"> offset into buffer </param>
    -	  /// <param name="length"> maximum length to examine </param>
    -	  public virtual void setText(char[] array, int start, int length)
    -	  {
    -		this.array = array;
    -		this.start = start;
    -		this.index = start;
    -		this.length = length;
    -		this.limit = start + length;
    -	  }
    +        /// <summary>
    +        /// Set a new region of text to be examined by this iterator
    +        /// </summary>
    +        /// <param name="array"> text buffer to examine </param>
    +        /// <param name="start"> offset into buffer </param>
    +        /// <param name="length"> maximum length to examine </param>
    +        public virtual void SetText(char[] array, int start, int length)
    +        {
    +            this.array = array;
    +            this.start = start;
    +            this.index = start;
    +            this.length = length;
    +            this.limit = start + length;
    +        }
     
    -	  public override char Current()
    -	  {
    -		return (index == limit) ? DONE : jreBugWorkaround(array[index]);
    -	  }
    +        public override char Current()
    +        {
    +            return (index == limit) ? DONE : JreBugWorkaround(array[index]);
    +        }
     
    -	  protected internal abstract char jreBugWorkaround(char ch);
    +        protected internal abstract char JreBugWorkaround(char ch);
     
    -	  public override char First()
    -	  {
    -		index = start;
    -		return Current();
    -	  }
    +        public override char First()
    +        {
    +            index = start;
    +            return Current();
    +        }
     
    -	  public override int BeginIndex
    -	  {
    -		  get
    -		  {
    -			return 0;
    -		  }
    -	  }
    +        public int BeginIndex
    +        {
    +            get
    +            {
    +                return 0;
    +            }
    +        }
     
    -	  public override int EndIndex
    -	  {
    -		  get
    -		  {
    -			return length;
    -		  }
    -	  }
    +        public int EndIndex
    +        {
    +            get
    +            {
    +                return length;
    +            }
    +        }
     
    -	  public override int Index
    -	  {
    -		  get
    -		  {
    -			return index - start;
    -		  }
    -	  }
    +        public int Index
    +        {
    +            get
    +            {
    +                return index - start;
    +            }
    +        }
     
    -	  public override char Last()
    -	  {
    -		index = (limit == start) ? limit : limit - 1;
    -		return current();
    -	  }
    +        public override int GetBeginIndex()
    +        {
    +            return 0;
    +        }
     
    -	  public override char Next()
    -	  {
    -		if (++index >= limit)
    -		{
    -		  index = limit;
    -		  return DONE;
    -		}
    -		else
    -		{
    -		  return current();
    -		}
    -	  }
    +        public override int GetEndIndex()
    +        {
    +            return length;
    +        }
     
    -	  public override char Previous()
    -	  {
    -		if (--index < start)
    -		{
    -		  index = start;
    -		  return DONE;
    -		}
    -		else
    -		{
    -		  return current();
    -		}
    -	  }
    +        public override int GetIndex()
    +        {
    +            return index - start;
    +        }
     
    -	  public override char SetIndex(int position)
    -	  {
    -		if (position < BeginIndex || position > EndIndex)
    -		{
    -		  throw new System.ArgumentException("Illegal Position: " + position);
    -		}
    -		index = start + position;
    -		return current();
    -	  }
     
    -	  public override CharArrayIterator Clone()
    -	  {
    -		try
    -		{
    -		  return (CharArrayIterator)base.clone();
    -		}
    -		catch (CloneNotSupportedException e)
    -		{
    -		  // CharacterIterator does not allow you to throw CloneNotSupported
    -		  throw new Exception(e);
    -		}
    -	  }
    +        public override char Last()
    +        {
    +            index = (limit == start) ? limit : limit - 1;
    +            return Current();
    +        }
     
    -	  /// <summary>
    -	  /// Create a new CharArrayIterator that works around JRE bugs
    -	  /// in a manner suitable for <seealso cref="BreakIterator#getSentenceInstance()"/>
    -	  /// </summary>
    -	  public static CharArrayIterator newSentenceInstance()
    -	  {
    -		if (HAS_BUGGY_BREAKITERATORS)
    -		{
    -		  return new CharArrayIteratorAnonymousInnerClassHelper();
    -		}
    -		else
    -		{
    -		  return new CharArrayIteratorAnonymousInnerClassHelper2();
    -		}
    -	  }
    +        public override char Next()
    +        {
    +            if (++index >= limit)
    +            {
    +                index = limit;
    +                return DONE;
    +            }
    +            else
    +            {
    +                return Current();
    +            }
    +        }
     
    -	  private class CharArrayIteratorAnonymousInnerClassHelper : CharArrayIterator
    -	  {
    -		  public CharArrayIteratorAnonymousInnerClassHelper()
    -		  {
    -		  }
    +        public override char Previous()
    +        {
    +            if (--index < start)
    +            {
    +                index = start;
    +                return DONE;
    +            }
    +            else
    +            {
    +                return Current();
    +            }
    +        }
     
    -			  // work around this for now by lying about all surrogates to 
    -			  // the sentence tokenizer, instead we treat them all as 
    -			  // SContinue so we won't break around them.
    -		  protected internal override char jreBugWorkaround(char ch)
    -		  {
    -			return ch >= 0xD800 && ch <= 0xDFFF ? 0x002C : ch;
    -		  }
    -	  }
    +        public override char SetIndex(int position)
    +        {
    +            if (position < BeginIndex || position > EndIndex)
    +            {
    +                throw new ArgumentException("Illegal Position: " + position);
    +            }
    +            index = start + position;
    +            return Current();
    +        }
     
    -	  private class CharArrayIteratorAnonymousInnerClassHelper2 : CharArrayIterator
    -	  {
    -		  public CharArrayIteratorAnonymousInnerClassHelper2()
    -		  {
    -		  }
    +        public override object Clone()
    +        {
    +            return this.MemberwiseClone();
    +        }
     
    -			  // no bugs
    -		  protected internal override char jreBugWorkaround(char ch)
    -		  {
    -			return ch;
    -		  }
    -	  }
    +        /// <summary>
    +        /// Create a new CharArrayIterator that works around JRE bugs
    +        /// in a manner suitable for <seealso cref="BreakIterator#getSentenceInstance()"/>
    +        /// </summary>
    +        public static CharArrayIterator NewSentenceInstance()
    +        {
    +            if (HAS_BUGGY_BREAKITERATORS)
    +            {
    +                return new CharArrayIteratorAnonymousInnerClassHelper();
    +            }
    +            else
    +            {
    +                return new CharArrayIteratorAnonymousInnerClassHelper2();
    +            }
    +        }
     
    -	  /// <summary>
    -	  /// Create a new CharArrayIterator that works around JRE bugs
    -	  /// in a manner suitable for <seealso cref="BreakIterator#getWordInstance()"/>
    -	  /// </summary>
    -	  public static CharArrayIterator newWordInstance()
    -	  {
    -		if (HAS_BUGGY_BREAKITERATORS)
    -		{
    -		  return new CharArrayIteratorAnonymousInnerClassHelper3();
    -		}
    -		else
    -		{
    -		  return new CharArrayIteratorAnonymousInnerClassHelper4();
    -		}
    -	  }
    +        private class CharArrayIteratorAnonymousInnerClassHelper : CharArrayIterator
    +        {
    +            // work around this for now by lying about all surrogates to 
    +            // the sentence tokenizer, instead we treat them all as 
    +            // SContinue so we won't break around them.
    +            protected internal override char JreBugWorkaround(char ch)
    +            {
    +                return (char)(ch >= 0xD800 && ch <= 0xDFFF ? 0x002C : ch);
    +            }
    +        }
    --- End diff --
    
    Do we really need this on the CLR?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message