From 85556de57eba48e1d1b62de51629ea8b957cd148 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Mon, 12 Feb 2024 11:47:12 +0800 Subject: [PATCH] =?UTF-8?q?database=5Ftools=E6=96=B0=E5=A2=9E=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E5=92=8C=E6=8B=AC=E5=8F=B7=E9=85=8D=E5=AF=B9,=20?= =?UTF-8?q?=E6=95=B0=E5=AD=A6=E7=8E=AF=E5=A2=83=E9=89=B4=E5=88=AB=E6=9C=89?= =?UTF-8?q?=E5=85=B3=E7=9A=84=E5=85=B1=E9=9E=A5=E4=BD=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v2/database_tools.py | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index 1adea771..4e90cf1a 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -1912,5 +1912,51 @@ def CheckUsagesValidity(data): #检查使用记录数据是否合理(没有超 return 1 return 0 +def pairingbraces(string_raw,leftbracepos): #根据字符串中的左括号的位置寻找配对的右括号 + types = {"(":"()","[":"[]","{":"{}"} + braces = "".join([types[i] for i in types]) + string = string_raw + for i in braces: + string = string.replace("\\"+i," ") #去除LaTeX的括号 + if not string[leftbracepos] in ("(","[","{"): + print("位置上的字符不是左括号") + return -1 #位置上不是括号, 返回-1 + else: + braces = types[string[leftbracepos]] + lbrace = braces[0] + rbrace = braces[1] + count = 1 + currentpos = leftbracepos + 1 + while not currentpos == len(string): + if string[currentpos] == lbrace: + count += 1 + elif string[currentpos] == rbrace: + count -= 1 + if count == 0: + return currentpos # 返回配对的右括号位置 + currentpos += 1 + return -1 #未找到配对括号 + +def InMathEnv(string,pos): #判断string的pos位置上的字符是否在math环境中 + string = string.repalce("\$"," ") + if not string[pos] == "$" and string[:pos].count("$") % 2 == 1: + return True + else: + return False + + +def MaskingMathEnv(string_raw): #把string_raw中数学环境中的符号都转为$后以新字符串的形式返回 + string_raw = string_raw.replace(r"\$"," ") + countdollars = 0 + string = "" + for i in range(len(string_raw)): + if string_raw[i] == "$": + countdollars = 1 - countdollars + if countdollars == 0: + string += string_raw[i] + else: + string += "$" + return string + if __name__ == "__main__": print("数据库工具, import用.") \ No newline at end of file