#!/usr/bin/python


"""
Do not call std::string::find_first_of or std::string::find with a string of
characters to locate that has the size 1. Use the version of
std::string::find that takes a single character to locate instead. Same for
find_last_of/rfind.
"""

error_msg = "Do not use find(\"a\"), use find('a')."

regexp = r"""r?find(_(first|last)_of)? *\("([^\]|\\[nt\"])"[,)]"""

forbidden = [
    'find_first_of("a")',
    'find_last_of("a")',
    'find("a")',
    'rfind("a")',
    'find_first_of("\\n")',
    'find_last_of("\\n")',
    'find("\\n")',
    'rfind("\\n")',
    'find_first_of("\\t")',
    'find_last_of("\\t")',
    'find("\\t")',
    'rfind("\\t")',
    'find_first_of("\\\\")',
    'find_last_of("\\\\")',
    'find("\\\\")',
    'rfind("\\\\")',
    'find_first_of("\\"")',
    'find_last_of("\\"")',
    'find("\\"")',
    'rfind("\\"")',
    'find_first_of("a", 1)',
    'find_last_of("a", 1)',
    'find("a", 1)',
    'rfind("a", 1)',
]

allowed = [
    'find("ab")',
    "find('a')",
    "rfind('a')",
    'rfind("ab")',
    "find('\\n')",
    'find("\\nx")',
    "rfind('\\n')",
    'rfind("\\nx")',
    "find('\\t')",
    'find("\\tx")',
    "rfind('\\t')",
    'rfind("\\tx")',
    "find('\\\\')",
    'find("\\\\x")',
    "rfind('\\\\')",
    'rfind("\\\\x")',
    "find('\\\"')",
    'find("\\"x")',
    "rfind('\\\"')",
    'rfind("\\"x")',
    "find('a', 1)",
    'find("ab", 1)',
    "rfind('a', 1)",
    'rfind("ab", 1)',
]
