unknown hace 6 años
padre
commit
5a04de6394
Se han modificado 3 ficheros con 65 adiciones y 44 borrados
  1. 1 1
      src/jy/admin/version.go
  2. 64 35
      src/jy/clear/specialsymbols.go
  3. 0 8
      src/specialsymbols.json

+ 1 - 1
src/jy/admin/version.go

@@ -84,7 +84,7 @@ func init() {
 		_id, _ := c.GetPostForm("_id")
 		isuse, _ := c.GetPostForm("isuse")
 		if isuse == "true" { //启用确保只有一个版本
-			l, _ := Mgo.Find("version", `{"isuse":true}`, nil, nil, false, -1, -1)
+			l, _ := Mgo.Find("version", `{"isuse":true,"delete":false}`, nil, nil, false, -1, -1)
 			if len(*l) > 0 {
 				c.JSON(200, gin.H{"rep": false})
 				return

+ 64 - 35
src/jy/clear/specialsymbols.go

@@ -58,7 +58,8 @@ func init() {
 
 	//
 	SymInterCon = qu.ObjArrToStringArr(SpecialSymbols["symintercon"].([]interface{}))
-	//log.Println(string(AnotherRemoveStart([]rune("“教育部高等教育教学评估中心数据中心升级改造”项目"))))
+
+	//log.Println(string(DealSinAndDouQuotes([]rune("安顺市西\"秀区园林局\"环卫设备\"项目"))))
 }
 
 //去除首尾空格、换行、回车
@@ -82,6 +83,8 @@ func RemoveHESymCode(val string) string {
 			}
 		}
 	}
+	//单引号和双引号特殊处理
+	text = DealSinAndDouQuotes(text)
 	return string(text)
 }
 
@@ -250,48 +253,44 @@ func AnotherRemoveStart(text []rune) []rune {
 					lock.Lock()
 					fdSymbol := SymmetricMap[now]
 					lock.Unlock()
-					if fdSymbol != now { //(fdSymbol != now:处理正反向符号是"或者')
-						if fdSymbol != "" { //去除第一个反符号
-							text = text[1:len(text)]
-						} else if len(now) > 0 { //第一个是正符号,记录索引位置
-							tmpArr := []int{index}
-							symbolIndex[now] = tmpArr
-						}
+					if fdSymbol != "" { //去除第一个反符号
+						text = text[1:len(text)]
+					} else if len(now) > 0 { //第一个是正符号,记录索引位置
+						tmpArr := []int{index}
+						symbolIndex[now] = tmpArr
 					}
 				} else {
 					lock.Lock()
 					fdSymbol := SymmetricMap[now]
 					lock.Unlock()
-					if fdSymbol != now { //(fdSymbol != now:处理正反向符号是"或者')
-						if fdSymbol != "" { //反向符号,找出对称的正向符号
-							tmp := symbolIndex[fdSymbol]
-							if len(tmp) == 0 { //多出来的反向符号,记录最大值
-								if index > surplusMax {
-									surplusMax = index
-								}
-							} else {
-								nowIndex := tmp[len(tmp)-1]              //索引位置
-								symbolIndex[fdSymbol] = tmp[:len(tmp)-1] //匹配索引位置后,删除之前的记录
-								if len(symbolIndex[fdSymbol]) == 0 {
-									delete(symbolIndex, fdSymbol)
-								}
-								//将成对的符号的index记录,
-								if index == length-1 {
-									pairedIndex[index] = nowIndex
-								}
-								pairedIndex[nowIndex] = index
-								tmpLength = tmpLength + len(text[nowIndex:index+1])
+					if fdSymbol != "" { //反向符号,找出对称的正向符号
+						tmp := symbolIndex[fdSymbol]
+						if len(tmp) == 0 { //多出来的反向符号,记录最大值
+							if index > surplusMax {
+								surplusMax = index
+							}
+						} else {
+							nowIndex := tmp[len(tmp)-1]              //索引位置
+							symbolIndex[fdSymbol] = tmp[:len(tmp)-1] //匹配索引位置后,删除之前的记录
+							if len(symbolIndex[fdSymbol]) == 0 {
+								delete(symbolIndex, fdSymbol)
 							}
-						} else { //正向符号,加入symbolIndex记录索引
-							tmpArr := []int{}
-							if len(symbolIndex[now]) > 0 { //有该符号的索引位置
-								tmpArr = symbolIndex[now]
-								tmpArr = append(tmpArr, index)
-							} else { //没有该符号的索引位置
-								tmpArr = []int{index}
+							//将成对的符号的index记录,
+							if index == length-1 {
+								pairedIndex[index] = nowIndex
 							}
-							symbolIndex[now] = tmpArr
+							pairedIndex[nowIndex] = index
+							tmpLength = tmpLength + len(text[nowIndex:index+1])
+						}
+					} else { //正向符号,加入symbolIndex记录索引
+						tmpArr := []int{}
+						if len(symbolIndex[now]) > 0 { //有该符号的索引位置
+							tmpArr = symbolIndex[now]
+							tmpArr = append(tmpArr, index)
+						} else { //没有该符号的索引位置
+							tmpArr = []int{index}
 						}
+						symbolIndex[now] = tmpArr
 					}
 				}
 			}
@@ -380,3 +379,33 @@ func DelContext(pairedIndex map[int]int, text []rune) []rune {
 	}
 	return result
 }
+
+func DealSinAndDouQuotes(text []rune) []rune {
+	stext := string(text)
+	for _, v := range []string{"\"", "'"} {
+		sReg := regexp.MustCompile(v)
+		sIndex := sReg.FindAllStringIndex(stext, -1)
+		length := len(sIndex)
+		if length > 0 {
+			if len(sIndex)%2 == 0 { //符号是成对出现的
+				si := sIndex[0][0]
+				ei := sIndex[length-1][1]
+				//val := stext[si:ei]
+				if si == 0 { //以单双引号开头
+					end := stext[ei:]
+					for _, r := range SymInterCon {
+						if r == string(end) {
+							tmptext := stext[1 : ei-1]
+							tmptext += end
+							return []rune(tmptext)
+						}
+					}
+				}
+			} else { //符号是非成对出现的(将最后一个符号前内容清理掉)
+				i := sIndex[length-1][1]
+				return []rune(stext[i:])
+			}
+		}
+	}
+	return text
+}

+ 0 - 8
src/specialsymbols.json

@@ -24,10 +24,6 @@
                 "{",
                 "}"
             ],
-            [
-                "'",
-                "'"
-            ],
             [
                 "‘",
                 "’"
@@ -36,10 +32,6 @@
                 "“",
                 "”"
             ],
-            [
-                "\"",
-                "\""
-            ],
             [
                 "【",
                 "】"