# Copyright (C) 2007-2026 Ahmet Öztürk (aoz_2@yahoo.com)
#
# This file is part of Lifeograph.
#
# Lifeograph is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Lifeograph is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Lifeograph.  If not, see <http://www.gnu.org/licenses/>.

from LoG import *

VERSION="0.1"

def get_code_from_str(code_str):
    CODE_LANG_MAP = {
        None: VT.QT.GENERIC,
        "": VT.QT.GENERIC,
        "text": VT.QT.GENERIC,
        "plain": VT.QT.GENERIC,

        "sh": VT.QT.BASH,
        "bash": VT.QT.BASH,

        "c": VT.QT.CPP,
        "cpp": VT.QT.CPP,
        "c++": VT.QT.CPP,

        "fortran": VT.QT.FORTRAN,

        "go": VT.QT.GO,
        "golang": VT.QT.GO,

        "haskell": VT.QT.HASKELL,
        "hs": VT.QT.HASKELL,

        "html": VT.QT.HTML,

        "java": VT.QT.JAVA,

        "js": VT.QT.JAVASCRIPT,
        "javascript": VT.QT.JAVASCRIPT,

        "kotlin": VT.QT.KOTLIN,
        "kt": VT.QT.KOTLIN,

        "lisp": VT.QT.LISP,

        "lua": VT.QT.LUA,

        "pascal": VT.QT.PASCAL,

        "perl": VT.QT.PERL,

        "py": VT.QT.PYTHON,
        "python": VT.QT.PYTHON,

        "ruby": VT.QT.RUBY,

        "rust": VT.QT.RUST,

        "scala": VT.QT.SCALA,

        "sql": VT.QT.SQL,
    }

    return CODE_LANG_MAP.get(code_str.strip().lower(), VT.QT.GENERIC)


def is_boundary_alnum_before(text, i):
    before = text[i - 1] if i > 0 else " "
    return before.isalnum()

def is_boundary_alnum_after(text, i, length):
    after = text[i + length] if i + length < len(text) else " "
    return after.isalnum()
