// projectname
package clear

import (
	"regexp"

	"github.com/dlclark/regexp2"
)

//清理项目名称

var clearPreRegNameCode = regexp.MustCompile(`([\(\)\-\[\]【】（）a-zA-Z0-9_—:：]{10,30})?(.+)?`)
var clearEndRegNameCode = regexp.MustCompile(`(.+?)?([\(\)\-\[\]【】（）a-zA-Z0-9_—:：]{8,100})$`)
var clearSymbol = regexp.MustCompile(`["“”]`)
var noclearNum = regexp2.MustCompile(`^(?!.+(?:标段|包|子项目|升级改造)[0-9１２３４５６７８９]{1,5})(.*)[0-9１２３４５６７８９]$`, regexp2.None)
var mustHan = regexp.MustCompile(`[\p{Han}]+`) //项目名称必须包含汉子

func ClearProjectName(data []interface{}) []interface{} {
	value := clearPreRegNameCode.ReplaceAllString(CutSpace(data)[0].(string), "$2")
	value = clearEndRegNameCode.ReplaceAllString(value, "$1")
	b := mustHan.MatchString(value)
	if !b {
		value = ""
	}
	tmp := value
	for i := 0; i < 5; i++ {
		tmpval, _ := noclearNum.Replace(tmp, "$1", -1, -1)
		if tmpval == tmp {
			value = tmp
			break
		} else {
			tmp = tmpval
		}
	}
	return []interface{}{value, data[1]}
}
