# Path: evepaste/utils.py
# def regex_match_lines(regex, lines):
#     """
#     Performs a regex search on each line and returns a list of matched groups
#     and a list of lines which didn't match.
# 
#     :param regex regex: String to be split and stripped
#     :param list lines: A list of strings to perform the regex on.
#     """
#     matches = []
#     bad_lines = []
#     for line in lines:
#         match = regex.search(line)
#         if match:
#             matches.append(match.groups())
#         else:
#             bad_lines.append(line)
#     return matches, bad_lines
# 
# def f_int(num):
#     """ Converts a given numeric string into an integer
# 
#     :param string num: A string of the format "123,456", "123'456", "123 456"
#                     or "123456"
#     """
#     if num is None:
#         return
#     try:
#         return int(sub(r"[,'\. ']", '', num))
# 
#     except ValueError:
#         return 0


from collections import defaultdict
from evepaste.utils import regex_match_lines, f_int
import re
Parse listings including cargo scan results and normal human-readable lists.

"""



# 10 x Cargo Scanner II | 10x Cargo Scanner II | 10 Cargo Scanner II
LISTING_RE = re.compile(r"^([\d,'\.]+?) ?x? ([\S ]+)$")
# Cargo Scanner II x10 | Cargo Scanner II x 10 | Cargo Scanner II 10
LISTING_RE2 = re.compile(r"^([\S ]+?) x? ?([\d,'\.]+)$")
# Cargo Scanner II
LISTING_RE3 = re.compile(r"^([\S ]+)$")


def parse_listing(lines):
    """ Parse Listing and Cargo Scan Results

    :param string paste_string: A raw string pasted from Eve Online of a cargo
                         scan result or a human listing
    """
    matches, bad_lines = regex_match_lines(LISTING_RE, lines)
    matches2, bad_lines2 = regex_match_lines(LISTING_RE2, bad_lines)
    matches3, bad_lines3 = regex_match_lines(LISTING_RE3, bad_lines2)

    items = defaultdict(int)

    for count, name in matches:
        items[name.strip()] += f_int(count) or 1

    for name, count in matches2:

# Path: evepaste/utils.py
# def regex_match_lines(regex, lines):
#     """
#     Performs a regex search on each line and returns a list of matched groups
#     and a list of lines which didn't match.
# 
#     :param regex regex: String to be split and stripped
#     :param list lines: A list of strings to perform the regex on.
#     """
#     matches = []
#     bad_lines = []
#     for line in lines:
#         match = regex.search(line)
#         if match:
#             matches.append(match.groups())
#         else:
#             bad_lines.append(line)
#     return matches, bad_lines
# 
# def f_int(num):
#     """ Converts a given numeric string into an integer
# 
#     :param string num: A string of the format "123,456", "123'456", "123 456"
#                     or "123456"
#     """
#     if num is None:
#         return
#     try:
#         return int(sub(r"[,'\. ']", '', num))
# 
#     except ValueError:
#         return 0


# Path: evepaste/parsers/listing.py
from collections import defaultdict
from evepaste.utils import regex_match_lines, f_int
import re

Parse listings including cargo scan results and normal human-readable lists.

"""



# 10 x Cargo Scanner II | 10x Cargo Scanner II | 10 Cargo Scanner II
LISTING_RE = re.compile(r"^([\d,'\.]+?) ?x? ([\S ]+)$")
# Cargo Scanner II x10 | Cargo Scanner II x 10 | Cargo Scanner II 10
LISTING_RE2 = re.compile(r"^([\S ]+?) x? ?([\d,'\.]+)$")
# Cargo Scanner II
LISTING_RE3 = re.compile(r"^([\S ]+)$")


def parse_listing(lines):
    """ Parse Listing and Cargo Scan Results

    :param string paste_string: A raw string pasted from Eve Online of a cargo
                         scan result or a human listing
    """
    matches, bad_lines = regex_match_lines(LISTING_RE, lines)
    matches2, bad_lines2 = regex_match_lines(LISTING_RE2, bad_lines)
    matches3, bad_lines3 = regex_match_lines(LISTING_RE3, bad_lines2)

    items = defaultdict(int)

    for count, name in matches:
        items[name.strip()] += f_int(count) or 1

    for name, count in matches2:

        items[name.strip()] += f_int(count) or 1