This is the rev 502 of the Snowball SVN trunk, but modified: made abstract and introduced abstract method stem to avoid expensive reflection in filter class. refactored StringBuffers to StringBuilder uses char[] as buffer instead of StringBuffer/StringBuilder eq_s,eq_s_b,insert,replace_s take CharSequence like eq_v and eq_v_b reflection calls (Lovins, etc) use EMPTY_ARGS/EMPTY_PARAMS
Ejemplo n.º 1
0
        // find_among_b is for backwards processing. Same comments apply
        protected virtual int FindAmongB(Among[] v, int v_size)
        {
            int i = 0;
            int j = v_size;

            int c  = m_cursor;
            int lb = m_limit_backward;

            int common_i = 0;
            int common_j = 0;

            bool first_key_inspected = false;

            while (true)
            {
                int   k      = i + ((j - i) >> 1);
                int   diff   = 0;
                int   common = common_i < common_j ? common_i : common_j;
                Among w      = v[k];
                int   i2;
                for (i2 = w.Length - 1 - common; i2 >= 0; i2--)
                {
                    if (c - common == lb)
                    {
                        diff = -1;
                        break;
                    }
                    diff = m_current[c - 1 - common] - w.S[i2];
                    if (diff != 0)
                    {
                        break;
                    }
                    common++;
                }
                if (diff < 0)
                {
                    j        = k;
                    common_j = common;
                }
                else
                {
                    i        = k;
                    common_i = common;
                }
                if (j - i <= 1)
                {
                    if (i > 0)
                    {
                        break;
                    }
                    if (j == i)
                    {
                        break;
                    }
                    if (first_key_inspected)
                    {
                        break;
                    }
                    first_key_inspected = true;
                }
            }
            while (true)
            {
                Among w = v[i];
                if (common_i >= w.Length)
                {
                    m_cursor = c - w.Length;
                    if (w.Method == null)
                    {
                        return(w.Result);
                    }

                    bool res;
                    try
                    {
                        object resobj = w.Method.Invoke(w.MethodObject, EMPTY_ARGS);
                        // LUCENENET-542: Fixed case-sensitivity problem
                        res = resobj.ToString().Equals("true", StringComparison.OrdinalIgnoreCase);
                    }
                    catch (TargetInvocationException /*e*/)
                    {
                        res = false;
                        // FIXME - debug message
                    }
                    catch (Exception /*e*/)
                    {
                        res = false;
                        // FIXME - debug message
                    }
                    m_cursor = c - w.Length;
                    if (res)
                    {
                        return(w.Result);
                    }
                }
                i = w.SubstringIndex;
                if (i < 0)
                {
                    return(0);
                }
            }
        }
Ejemplo n.º 2
0
        protected virtual int FindAmong(Among[] v, int v_size)
        {
            int i = 0;
            int j = v_size;

            int c = m_cursor;
            int l = m_limit;

            int common_i = 0;
            int common_j = 0;

            bool first_key_inspected = false;

            while (true)
            {
                int   k      = i + ((j - i) >> 1);
                int   diff   = 0;
                int   common = common_i < common_j ? common_i : common_j; // smaller
                Among w      = v[k];
                int   i2;
                for (i2 = common; i2 < w.Length; i2++)
                {
                    if (c + common == l)
                    {
                        diff = -1;
                        break;
                    }
                    diff = m_current[c + common] - w.S[i2];
                    if (diff != 0)
                    {
                        break;
                    }
                    common++;
                }
                if (diff < 0)
                {
                    j        = k;
                    common_j = common;
                }
                else
                {
                    i        = k;
                    common_i = common;
                }
                if (j - i <= 1)
                {
                    if (i > 0)
                    {
                        break;        // v->s has been inspected
                    }
                    if (j == i)
                    {
                        break;         // only one item in v
                    }
                    // - but now we need to go round once more to get
                    // v->s inspected. This looks messy, but is actually
                    // the optimal approach.

                    if (first_key_inspected)
                    {
                        break;
                    }
                    first_key_inspected = true;
                }
            }
            while (true)
            {
                Among w = v[i];
                if (common_i >= w.Length)
                {
                    m_cursor = c + w.Length;
                    if (w.Method == null)
                    {
                        return(w.Result);
                    }
                    bool res;
                    try
                    {
                        object resobj = w.Method.Invoke(w.MethodObject, EMPTY_ARGS);
                        // LUCENENET-542: Fixed case-sensitivity problem
                        res = resobj.ToString().Equals("true", StringComparison.OrdinalIgnoreCase);
                    }
                    catch (TargetInvocationException /*e*/)
                    {
                        res = false;
                        // FIXME - debug message
                    }
                    catch (Exception /*e*/)
                    {
                        res = false;
                        // FIXME - debug message
                    }
                    m_cursor = c + w.Length;
                    if (res)
                    {
                        return(w.Result);
                    }
                }
                i = w.SubstringIndex;
                if (i < 0)
                {
                    return(0);
                }
            }
        }
Ejemplo n.º 3
0
        // find_among_b is for backwards processing. Same comments apply
        protected int find_among_b(Among[] v, int v_size)
        {
            int i = 0;
            int j = v_size;

            int c  = cursor;
            int lb = limit_backward;

            int common_i = 0;
            int common_j = 0;

            bool first_key_inspected = false;

            while (true)
            {
                int   k      = i + ((j - i) >> 1);
                int   diff   = 0;
                int   common = common_i < common_j ? common_i : common_j;
                Among w      = v[k];
                int   i2;
                for (i2 = w.s_size - 1 - common; i2 >= 0; i2--)
                {
                    if (c - common == lb)
                    {
                        diff = -1;
                        break;
                    }
                    diff = current[c - 1 - common] - w.s[i2];
                    if (diff != 0)
                    {
                        break;
                    }
                    common++;
                }
                if (diff < 0)
                {
                    j        = k;
                    common_j = common;
                }
                else
                {
                    i        = k;
                    common_i = common;
                }
                if (j - i <= 1)
                {
                    if (i > 0)
                    {
                        break;
                    }
                    if (j == i)
                    {
                        break;
                    }
                    if (first_key_inspected)
                    {
                        break;
                    }
                    first_key_inspected = true;
                }
            }
            while (true)
            {
                Among w = v[i];
                if (common_i >= w.s_size)
                {
                    cursor = c - w.s_size;
                    if (w.method == null)
                    {
                        return(w.result);
                    }

                    bool res;
                    try
                    {
                        object resobj = w.method.Invoke(w.methodobject, EMPTY_ARGS);
                        res = resobj.ToString().Equals("true");
                    }
                    catch (TargetInvocationException e)
                    {
                        res = false;
                        // FIXME - debug message
                    }
                    catch (Exception e)
                    {
                        res = false;
                        // FIXME - debug message
                    }
                    cursor = c - w.s_size;
                    if (res)
                    {
                        return(w.result);
                    }
                }
                i = w.substring_i;
                if (i < 0)
                {
                    return(0);
                }
            }
        }
Ejemplo n.º 4
0
        protected int find_among(Among[] v, int v_size)
        {
            int i = 0;
            int j = v_size;

            int c = cursor;
            int l = limit;

            int common_i = 0;
            int common_j = 0;

            bool first_key_inspected = false;

            while (true)
            {
                int   k      = i + ((j - i) >> 1);
                int   diff   = 0;
                int   common = common_i < common_j ? common_i : common_j; // smaller
                Among w      = v[k];
                int   i2;
                for (i2 = common; i2 < w.s_size; i2++)
                {
                    if (c + common == l)
                    {
                        diff = -1;
                        break;
                    }
                    diff = current[c + common] - w.s[i2];
                    if (diff != 0)
                    {
                        break;
                    }
                    common++;
                }
                if (diff < 0)
                {
                    j        = k;
                    common_j = common;
                }
                else
                {
                    i        = k;
                    common_i = common;
                }
                if (j - i <= 1)
                {
                    if (i > 0)
                    {
                        break;        // v->s has been inspected
                    }
                    if (j == i)
                    {
                        break;         // only one item in v
                    }
                    // - but now we need to go round once more to get
                    // v->s inspected. This looks messy, but is actually
                    // the optimal approach.

                    if (first_key_inspected)
                    {
                        break;
                    }
                    first_key_inspected = true;
                }
            }
            while (true)
            {
                Among w = v[i];
                if (common_i >= w.s_size)
                {
                    cursor = c + w.s_size;
                    if (w.method == null)
                    {
                        return(w.result);
                    }
                    bool res;
                    try
                    {
                        Object resobj = w.method.Invoke(w.methodobject, EMPTY_ARGS);
                        res = resobj.ToString().Equals("true");
                    }
                    catch (TargetInvocationException e)
                    {
                        res = false;
                        // FIXME - debug message
                    }
                    catch (Exception e)
                    {
                        res = false;
                        // FIXME - debug message
                    }
                    cursor = c + w.s_size;
                    if (res)
                    {
                        return(w.result);
                    }
                }
                i = w.substring_i;
                if (i < 0)
                {
                    return(0);
                }
            }
        }
Ejemplo n.º 5
0
        // find_among_b is for backwards processing. Same comments apply
        protected virtual int FindAmongB(Among[] v, int v_size)
        {
            int i = 0;
            int j = v_size;

            int c  = m_cursor;
            int lb = m_limit_backward;

            int common_i = 0;
            int common_j = 0;

            bool first_key_inspected = false;

            while (true)
            {
                int   k      = i + ((j - i) >> 1);
                int   diff   = 0;
                int   common = common_i < common_j ? common_i : common_j;
                Among w      = v[k];
                int   i2;
                for (i2 = w.SearchString.Length - 1 - common; i2 >= 0; i2--)
                {
                    if (c - common == lb)
                    {
                        diff = -1;
                        break;
                    }
                    diff = m_current[c - 1 - common] - w.SearchString[i2];
                    if (diff != 0)
                    {
                        break;
                    }
                    common++;
                }
                if (diff < 0)
                {
                    j        = k;
                    common_j = common;
                }
                else
                {
                    i        = k;
                    common_i = common;
                }
                if (j - i <= 1)
                {
                    if (i > 0)
                    {
                        break;
                    }
                    if (j == i)
                    {
                        break;
                    }
                    if (first_key_inspected)
                    {
                        break;
                    }
                    first_key_inspected = true;
                }
            }
            while (true)
            {
                Among w = v[i];
                // LUCENENET specific: Refactored Among to remove expensive
                // reflection calls and replaced with Func<bool> as was done in
                // the original code at:
                // https://github.com/snowballstem/snowball
                if (common_i >= w.SearchString.Length)
                {
                    m_cursor = c - w.SearchString.Length;
                    if (w.Action is null)
                    {
                        return(w.Result);
                    }

                    bool res = w.Action.Invoke();
                    m_cursor = c - w.SearchString.Length;
                    if (res)
                    {
                        return(w.Result);
                    }
                }
                i = w.MatchIndex;
                if (i < 0)
                {
                    return(0);
                }
            }
        }
Ejemplo n.º 6
0
        protected virtual int FindAmong(Among[] v, int v_size)
        {
            int i = 0;
            int j = v_size;

            int c = m_cursor;
            int l = m_limit;

            int common_i = 0;
            int common_j = 0;

            bool first_key_inspected = false;

            while (true)
            {
                int   k      = i + ((j - i) >> 1);
                int   diff   = 0;
                int   common = common_i < common_j ? common_i : common_j; // smaller
                Among w      = v[k];
                int   i2;
                for (i2 = common; i2 < w.SearchString.Length; i2++)
                {
                    if (c + common == l)
                    {
                        diff = -1;
                        break;
                    }
                    diff = m_current[c + common] - w.SearchString[i2];
                    if (diff != 0)
                    {
                        break;
                    }
                    common++;
                }
                if (diff < 0)
                {
                    j        = k;
                    common_j = common;
                }
                else
                {
                    i        = k;
                    common_i = common;
                }
                if (j - i <= 1)
                {
                    if (i > 0)
                    {
                        break;        // v->s has been inspected
                    }
                    if (j == i)
                    {
                        break;         // only one item in v
                    }
                    // - but now we need to go round once more to get
                    // v->s inspected. This looks messy, but is actually
                    // the optimal approach.

                    if (first_key_inspected)
                    {
                        break;
                    }
                    first_key_inspected = true;
                }
            }
            while (true)
            {
                Among w = v[i];
                // LUCENENET specific: Refactored Among to remove expensive
                // reflection calls and replaced with Func<bool> as was done in
                // the original code at:
                // https://github.com/snowballstem/snowball
                if (common_i >= w.SearchString.Length)
                {
                    m_cursor = c + w.SearchString.Length;
                    if (w.Action is null)
                    {
                        return(w.Result);
                    }
                    bool res = w.Action.Invoke();
                    m_cursor = c + w.SearchString.Length;
                    if (res)
                    {
                        return(w.Result);
                    }
                }
                i = w.MatchIndex;
                if (i < 0)
                {
                    return(0);
                }
            }
        }