Step 1
Search for the longest among the following suffixes, and perform the action indicated
15599
private function step1()
    {
        // heden
        //      replace with heid if in R1
        if ( ($position = $this->search(array('heden'))) !== false) {
            if ($this->inR1($position)) {
                $this->word = preg_replace('#(heden)$#u', 'heid', $this->word);
            }
            return true;
        }

        // en   ene
        //      delete if in R1 and preceded by a valid en-ending, and then undouble the ending
        if ( ($position = $this->search(array('ene', 'en'))) !== false) {
            if ($this->inR1($position)) {
                $word = Utf8::substr($this->word, 0, $position);
                if ($this->hasValidEnEnding($word)) {
                    $this->word = $word;
                    $this->unDoubling();
                }
            }
            return true;
        }

        // s   se
        //      delete if in R1 and preceded by a valid s-ending
        if ( ($position = $this->search(array('se', 's'))) !== false) {
            if ($this->inR1($position)) {
                $word = Utf8::substr($this->word, 0, $position);
                if ($this->hasValidSEnding($word)) {
                    $this->word = $word;
                }
            }
            return true;
        }

        return false;
    }
181985
function step1b(token) {   
    if(token.substr(-3) == 'eed') {
	if(measure(token.substr(0, token.length - 3)) > 0)
            return token.replace(/eed$/, 'ee');
    } else {
	var result = attemptReplace(token, /ed|ing$/, '', function(token) {   
	    if(categorizeGroups(token).indexOf('V') > 0) {
		result = attemptReplacePatterns(token, [['at', 'ate'],  ['bl', 'ble'], ['iz', 'ize']]);

		if(result)
		    return result;
		else {
		    if(endsWithDoublCons(token) && token.match(/[^lsz]$/))
			return token.replace(/([^aeiou])\1$/, '$1');

		    if(measure(token) == 1 && categorizeChars(token).substr(-3) == 'CVC' && token.match(/[^wxy]$/))
			return token + 'e';                            
		}

		return token;
	    }
	    
	    return null;
	});
	
	if(result)
	    return result;
    }

    return token;   
}
403481
private void fixActiveEdgeAfterSuffixLink(Suffix<T, S> suffix) {
        while (activeEdge != null && activeLength > activeEdge.getLength()) {
            activeLength = activeLength - activeEdge.getLength();
            activeNode = activeEdge.getTerminal();
            Object item = suffix.getItemXFromEnd(activeLength + 1);
            activeEdge = activeNode.getEdgeStarting(item);
        }
        resetActivePointToTerminal();
    }
1056008
private final void step3() {
        if (k == 0) {
            return;
        }

        switch (b[k - 1]) {
            case 'a':
                if (endWith("ational")) {
                    r("ate");
                    break;
                }
                if (endWith("tional")) {
                    r("tion");
                    break;
                }
                break;
            case 'c':
                if (endWith("enci")) {
                    r("ence");
                    break;
                }
                if (endWith("anci")) {
                    r("ance");
                    break;
                }
                break;
            case 'e':
                if (endWith("izer")) {
                    r("ize");
                    break;
                }
                break;
            case 'l':
                if (endWith("bli")) {
                    r("ble");
                    break;
                }
                if (endWith("alli")) {
                    r("al");
                    break;
                }
                if (endWith("entli")) {
                    r("ent");
                    break;
                }
                if (endWith("eli")) {
                    r("e");
                    break;
                }
                if (endWith("ousli")) {
                    r("ous");
                    break;
                }
                break;
            case 'o':
                if (endWith("ization")) {
                    r("ize");
                    break;
                }
                if (endWith("ation")) {
                    r("ate");
                    break;
                }
                if (endWith("ator")) {
                    r("ate");
                    break;
                }
                break;
            case 's':
                if (endWith("alism")) {
                    r("al");
                    break;
                }
                if (endWith("iveness")) {
                    r("ive");
                    break;
                }
                if (endWith("fulness")) {
                    r("ful");
                    break;
                }
                if (endWith("ousness")) {
                    r("ous");
                    break;
                }
                break;
            case 't':
                if (endWith("aliti")) {
                    r("al");
                    break;
                }
                if (endWith("iviti")) {
                    r("ive");
                    break;
                }
                if (endWith("biliti")) {
                    r("ble");
                    break;
                }
                break;
            case 'g':
                if (endWith("logi")) {
                    r("log");
                    break;
                }
        }
    }
251362
private function step5()
    {
        if ($this->search(array('enn', 'onn', 'ett', 'ell', 'eill')) !== false) {
            $this->word = Utf8::substr($this->word, 0, -1);
        }
    }
255074
def _set_suffix_links(self):
        '''
        
        '''
        self._suffix_links_set = True
        for current, parent in self.bfs():
            # skip the root node
            if parent is None:
                continue
            current.longest_prefix = parent.longest_prefix
            if parent.has_value:
                current.longest_prefix = parent
            # the root doesn't get a suffix link
            # also, skip previously set suffix links
            if current.has_suffix:
                continue
            # current is not the root and has no suffix
            # set current's suffix to parent's suffix
            suffix = parent
            while True:
                if not suffix.has_suffix:
                    current.suffix = self.root
                    break
                else:
                    suffix = suffix.suffix
                if current.uplink in suffix:
                    current.suffix = suffix[current.uplink]
                    break
            # now find the dict_suffix value
            suffix = current.suffix
            while not suffix.has_value and suffix.has_suffix:
                suffix = suffix.suffix
            if suffix.has_value:
                current.dict_suffix = suffix
697985
def find_next_word_ending(self, include_current_position=False, count=1, WORD=False):
        
        if count < 0:
            return self.find_previous_word_ending(count=-count, WORD=WORD)

        if include_current_position:
            text = self.text_after_cursor
        else:
            text = self.text_after_cursor[1:]

        regex = _FIND_BIG_WORD_RE if WORD else _FIND_WORD_RE
        iterable = regex.finditer(text)

        try:
            for i, match in enumerate(iterable):
                if i + 1 == count:
                    value = match.end(1)

                    if include_current_position:
                        return value
                    else:
                        return value + 1

        except StopIteration:
            pass
551372
def keys_with_suffix(self, suffix):
        
        return [k.rstrip(suffix) for k in self.keys() if k.endswith(suffix)]
849670
private static int suffixLength(byte[] needle, int p) {
        int len = 0;
        for (int i = p, j = needle.length - 1; i >= 0 && needle[i] == needle[j]; --i, --j) {
            len++;
        }
        return len;
    }
48797
def find_regions(self, word):
        
        length = len(word)

        for index, match in enumerate(re.finditer("[aeiouy][^aeiouy]", word)):
            if index == 0:
                if match.end() < length:
                    self.r1 = match.end()
            if index == 1:
                if match.end() < length:
                    self.r2 = match.end()
                break
578368
void advance() {
    if (tc.isEntryEnabled())
      tc.entry(this,cclass, "advance");
    if (!prefixDone) {
      Pattern.Clause prefix = pattern.getPrefix();
      if (prefix == null || next >= prefix.items.length) {
        Pattern.Clause suffix = pattern.getSuffix();
        if (suffix != null && suffix != prefix) {
          // SWITCH_TO_SUFFIX
          prefixDone = true;
          next = suffix.items.length-1;
        }
        // else in one of the FINAL_ states, so do nothing
      }
      else
        // somewhere in the body of the prefix, so advance by incrementing
        next++;
    }
    else
      // somewhere in the suffix, so advance by decrementing
      next--;
    if (tc.isEntryEnabled())
      tc.exit(this,cclass, "advance");
  }
319177
function endshere(subword) {
		var nextindex = charindex + 1;
		return input.length === nextindex ||
			!input[nextindex].match(METHODNAME);
	}
896178
def can_handle_suffix(self, suffix):
        
        for index in self._indexes:
            if index.can_handle_suffix(suffix):
                return True

        return False
363600
def main():
    
    (options, strings) = parseArgv()
    global _suffixArray, _trace

    #############
    # Verbosity #
    #############
    _trace = options.verbose

    ###################
    # Processing unit #
    ###################
    if options.unit == "byte":
        options.unit = UNIT_BYTE
    elif options.unit == "character":
        options.unit = UNIT_CHARACTER
    elif options.unit == "word":
        options.unit = UNIT_WORD
    else:
        print >> _stderr, "Please specify a valid unit type."
        exit(EXIT_BAD_OPTION)

    ######################
    # Build suffix array #
    ######################
    if not options.SAFile:  # Build the suffix array from INPUT
        if not options.input:  # default is standard input
            options.input = "-"
        try:
            string = _open(options.input, "r").read()
        except IOError:
            print >> _stderr, "File %s does not exist." % options.input
            exit(EXIT_ERROR_FILE)

        SA = SuffixArray(string, options.unit, options.encoding, options.noLCPs)
    ########################
    # Or load suffix array #
    ########################
    elif not options.input and options.SAFile:  # Load suffix array from SA_FILE
        try:
            SA = SuffixArray.fromFile(options.SAFile)
        except IOError:
            print >> _stderr, "SA_FILE %s does not exist." % options.SAFile
            exit(EXIT_ERROR_FILE)
    else:
        print >> _stderr, "Please set only one option amongst --input and --load.\n" + \
        "Type %s --help for more details." % _argv[0]
        exit(EXIT_BAD_OPTION)

    ######################
    # Print suffix array #
    ######################
    if options.printSA:
        # Buffered ouptut
        deltaLength = 1000
        start = 0
        while start < SA.length:
            print >> _stderr, SA.__str__(start, start + deltaLength)
            start += deltaLength

    ####################################
    # Look for every string in strings #
    ####################################
    for string in strings:
        print >> _stderr, ""
        print >> _stderr, "Positions of %s:" % string
        print >> _stderr, "  %s" % list(SA.find(string))

    #########################
    # Save SAFILE if needed #
    #########################
    if options.output:
        SA.toFile(options.output)

    if _trace: print >> _stderr, "Done\r\n"
549874
private final void step4() {
        switch (sb.charAt(k)) {
        case 'e':
            if (ends("icate")) 
                r("ic");
            else if (ends("ative"))
                r("");
            else if (ends("alize")) 
                r("al");
            break;
        case 'i':
            if (ends("iciti")) 
                r("ic");
            break;
        case 'l':
            if (ends("ical")) 
                r("ic");
            else if (ends("ful")) 
                r("");
            break;
        case 's':
            if (ends("ness")) r("");
            break;
        }
    }
865356
def suffix?(suffix, text)
      len = suffix.length
      len <= text.length and suffix == text[-len, len]
    end
607103
def replace_suffixes_1(self, word):
        
        length = len(word)

        if word.endswith("sses"):
            return word[:-2]

        elif word.endswith("ied") or word.endswith("ies"):
            word = word[:-3]
            if len(word) == 1:
                word += 'ie'
            else:
                word += 'i'
            return word

        # This ensures that words like conspicous stem properly
        elif word.endswith('us') or word.endswith('ss'):
            return word

        # From spec: 'delete if the preceding word part contains a vowel
        # not immediately before the s (so gas and this retain the s,
        # gaps and kiwis lose it)
        elif word[length - 1] == 's':
            for letter in word[:-2]:
                if letter in self.vowels:
                    return word[:-1]

        return word