# 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
                                   (Drone|Fuel)\ Bay|
                                   (Low|Medium|High|Rig)\ Slot|
                                   Subsystem|
                                   )\t
                                  ([\d,'\.]+)$""", re.X)
STATION_CONTAINER_RE = re.compile(r"""^([\S ]*)\t
                                       ([\S ]*)\t
                                       ([\d,'\.]+)$""", re.X)


def parse_view_contents(lines):
    """ Parse view contents

    :param string paste_string: String pasted from view contents window
    """
    matches, bad_lines = regex_match_lines(VIEWCONT_LIST_RE, lines)
    matches2, bad_lines2 = regex_match_lines(STATION_CONTAINER_RE, bad_lines)

    items = defaultdict(int)
    for name, group, location, _, _, quantity in matches:
        items[(name, group, location)] += f_int(quantity)

    results = [{'name': name,
                'group': group,
                'location': location,
                'quantity': quantity}
               for (name, group, location), quantity in sorted(items.items())]

    items2 = defaultdict(int)
    for name, group, quantity 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/view_contents.py
from collections import defaultdict
from evepaste.utils import regex_match_lines, f_int
import re

                                   (Drone|Fuel)\ Bay|
                                   (Low|Medium|High|Rig)\ Slot|
                                   Subsystem|
                                   )\t
                                  ([\d,'\.]+)$""", re.X)
STATION_CONTAINER_RE = re.compile(r"""^([\S ]*)\t
                                       ([\S ]*)\t
                                       ([\d,'\.]+)$""", re.X)


def parse_view_contents(lines):
    """ Parse view contents

    :param string paste_string: String pasted from view contents window
    """
    matches, bad_lines = regex_match_lines(VIEWCONT_LIST_RE, lines)
    matches2, bad_lines2 = regex_match_lines(STATION_CONTAINER_RE, bad_lines)

    items = defaultdict(int)
    for name, group, location, _, _, quantity in matches:
        items[(name, group, location)] += f_int(quantity)

    results = [{'name': name,
                'group': group,
                'location': location,
                'quantity': quantity}
               for (name, group, location), quantity in sorted(items.items())]

    items2 = defaultdict(int)
    for name, group, quantity in matches2:

        items2[(name, group)] += f_int(quantity)