Generator function for iterating through large strings, particularly useful
    as a replacement for str.splitlines().

    See http://stackoverflow.com/a/3865367
193281
def split(orig, sep=None):
    '''
    
    '''
    exp = re.compile(r'\s+' if sep is None else re.escape(sep))
    pos = 0
    length = len(orig)
    while True:
        match = exp.search(orig, pos)
        if not match:
            if pos < length or sep is not None:
                val = orig[pos:]
                if val:
                    # Only yield a value if the slice was not an empty string,
                    # because if it is then we've reached the end. This keeps
                    # us from yielding an extra blank value at the end.
                    yield val
            break
        if pos < match.start() or sep is not None:
            yield orig[pos:match.start()]
        pos = match.end()
7820
def split_lines(source, maxline=79):
    
    result = []
    extend = result.extend
    append = result.append
    line = []
    multiline = False
    count = 0
    find = str.find
    for item in source:
        index = find(item, '\n')
        if index:
            line.append(item)
            multiline = index > 0
            count += len(item)
        else:
            if line:
                if count <= maxline or multiline:
                    extend(line)
                else:
                    wrap_line(line, maxline, result)
                count = 0
                multiline = False
                line = []
            append(item)
    return result
362987
public static String[] splitString(String line) {
		int len=line.length();
		int wordCount=0;
		int pos=0;
		while(pos<len) {
			// Skip past blank space
			while(pos<len&&line.charAt(pos)<=' ') pos++;
			int start=pos;
			// Skip to the next blank space
			while(pos<len&&line.charAt(pos)>' ') pos++;
			if(pos>start) wordCount++;
		}

		String[] words=new String[wordCount];

		int wordPos=0;
		pos=0;
		while(pos<len) {
			// Skip past blank space
			while(pos<len&&line.charAt(pos)<=' ') pos++;
			int start=pos;
			// Skip to the next blank space
			while(pos<len&&line.charAt(pos)>' ') pos++;
			if(pos>start) words[wordPos++]=line.substring(start,pos);
		}

		return words;
	}
949443
def split(self, delimiter=None):
        
        result = []
        strings = self.strings[:]
        current = None

        while strings:
            is_literal, value = strings[0]
            parts = value.split(delimiter, 1)
            if len(parts) > 1:
                value1, value2 = parts
                strings[0] = (is_literal, value2)
                out = EscapedString(value1, is_literal)
                push = True
            else:
                strings = strings[1:]
                out = EscapedString(value, is_literal)
                push = False

            if current is None:
                current = out
            else:
                current = current + out
            if push:
                result.append(current)
                current = None

        if current:
            result.append(current)
        return result
1187445
public static List<String> splitByRegex(String str, String separatorRegex, int limit, boolean isTrim, boolean ignoreEmpty){
		final Pattern pattern = PatternPool.get(separatorRegex);
		return split(str, pattern, limit, isTrim, ignoreEmpty);
	}
494731
async def iter_lines(self, chunk_size=1024):
        
        pending = b''
        async for chunk in self.iter_chunks(chunk_size):
            lines = (pending + chunk).splitlines(True)
            for line in lines[:-1]:
                await yield_(line.splitlines()[0])
            pending = lines[-1]
        if pending:
            await yield_(pending.splitlines()[0])
106091
def _split_out_of_braces(s):
    
    prev = 0
    for m in re.finditer(r"{[^{}]*}|\s*,\s*", s):
        if not m.group().startswith("{"):
            part = s[prev:m.start()]
            if part:
                yield s[prev:m.start()]
            prev = m.end()
    part = s[prev:]
    if part:
        yield part
1117769
function eachLine(str, callback)
    {
        var lines = splitLines(str);

        for (var i = 0; i < lines.length; i++)
            lines[i] = callback(lines[i], i);

        // include \r to enable copy-paste on windows (ie8) without getting everything on one line
        return lines.join('\r\n');
    }
1298035
def iter_lines(file_like: Iterable[str]) -> Generator[str, None, None]:
    
    for line in file_like:
        line = line.rstrip('\r\n')
        if line:
            yield line
467030
function splitInput(str) {
  if (str.slice(0, 3) !== '---') return;

  var matcher = /\n(\.{3}|-{3})/g;
  var metaEnd = matcher.exec(str);

  return metaEnd && [str.slice(0, metaEnd.index), str.slice(matcher.lastIndex)];
}
940490
def chunks_generator(iterable, count_items_in_chunk):
    
    iterator = iter(iterable)
    for first in iterator:  # stops when iterator is depleted
        def chunk():  # construct generator for next chunk
            yield first  # yield element from for loop
            for more in islice(iterator, count_items_in_chunk - 1):
                yield more  # yield more elements from the iterator

        yield chunk()
411981
def common_start(strings):
    

    def gen_start_strings(string):
        """Generator that yield start sub-strings of length 1, 2, ..."""

        for i in xrange(1, len(string) + 1):
            yield string[:i]

    # Empty strings list
    if not strings:
        return ""

    start_string = ""

    # Get sucessively start string of 1st string
    for start_string in gen_start_strings(max(strings)):
        if not all(string.startswith(start_string) for string in strings):
            return start_string[:-1]

    return start_string
1129966
def chunks_str(str, n, separator="\n", fill_blanks_last=True):
    
    return separator.join(chunks(str, n))
572063
def iter_long(self, string):
		
		state = self.root
		last  = None

		index = 0
		while index < len(string):
			c = string[index]

			if c in state.children:
				state = state.children[c]

				if state.output is not nil:
					# save the last node on the path
					last = (state.output, index)

				index += 1
			else:
				if last:
					# return the saved match
					yield last

					# and start over, as we don't want overlapped results
					# Note: this leads to quadratic complexity in the worst case
					index = last[1] + 1
					state = self.root
					last  = None
				else:
					# if no output, perform classic Aho-Corasick algorithm
					while c not in state.children:
						state = state.fail

		# corner case
		if last:
			yield last
875374
function split_newlines(s) {
            //return s.split(/\x0d\x0a|\x0a/);

            s = s.replace(/\x0d/g, '');
            var out = [],
                idx = s.indexOf("\n");
            while (idx !== -1) {
                out.push(s.substring(0, idx));
                s = s.substring(idx + 1);
                idx = s.indexOf("\n");
            }
            if (s.length) {
                out.push(s);
            }
            return out;
        }
698787
def parse_string(self, string=''):
        '''
        
        '''
        self.strings = string.splitlines(1)
        self.strings = [self.__parse(line) for line in self.strings]
        return ''.join(self.strings)
641711
def each_line(text, separator)
      lines = text.split(separator)
      return yield(text) if text.empty?
      lines.reduce([]) do |aligned, line|
        aligned << yield(line)
      end.join(separator)
    end