代码拉取完成,页面将自动刷新
package pinyin
import (
"bufio"
"bytes"
"os"
"regexp"
"strings"
)
// ReadDickFromIni read file and parse from ini files
func ReadDickFromIni(filename string) map[string]map[string]string {
dick := map[string]map[string]string{}
fh, err := os.Open(filename)
if err == nil {
buf := bufio.NewReader(fh)
var mapKey string
var regKey = regexp.MustCompile(`^\[[^\[\]]+]+`)
var regStr = regexp.MustCompile(`\[|]`)
var equalStr = "="
for {
line, err2 := buf.ReadString('\n')
line = strings.TrimSpace(line)
// "#/;" 开头含忽略
w := ""
if line != "" {
w = line[:1]
}
if w == "#" || w == ";" {
line = ""
}
if line != "" {
if regKey.MatchString(line) {
mapKey = regStr.ReplaceAllString(line, "")
} else if mapKey != "" {
idx := strings.Index(line, equalStr)
if idx > -1 {
tKey := strings.TrimSpace(line[:idx])
tValue := strings.TrimSpace(line[idx+1:])
v, has := dick[mapKey]
if has {
v[tKey] = tValue
dick[mapKey] = v
} else {
dick[mapKey] = map[string]string{
tKey: tValue,
}
}
}
}
}
// 错误
if err2 != nil {
break
}
}
}
return dick
}
// ReadDickFromByteKv read file and parse from ini files
func ReadDickFromByteKv(content []byte) map[string]string {
dick := map[string]string{}
bf := bytes.NewBuffer(content)
buf := bufio.NewReader(bf)
var equalStr = "="
for {
line, err2 := buf.ReadString('\n')
line = strings.TrimSpace(line)
// "#/;" 开头含忽略
w := ""
if line != "" {
w = line[:1]
}
if w == "#" || w == ";" {
line = ""
}
if line != "" {
idx := strings.Index(line, equalStr)
if idx > -1 {
tKey := strings.TrimSpace(line[:idx])
tValue := strings.TrimSpace(line[idx+1:])
dick[tKey] = tValue
}
}
// 错误
if err2 != nil {
break
}
}
return dick
}
// ReadIniLines read ini file as line array, support [key], and repeat parse line.
func ReadIniLines(lines []string) map[string]map[string]string {
dick := map[string]map[string]string{}
var mapKey string
var regKey = regexp.MustCompile(`^\[[^\[\]]+]+`)
var regStr = regexp.MustCompile(`\[|]`)
var equalStr = "="
for _, line := range lines {
line = strings.TrimSpace(line)
// "#/;" 开头含忽略
w := ""
if line != "" {
w = line[:1]
}
if w == "#" || w == ";" {
line = ""
}
if line != "" {
if regKey.MatchString(line) {
mapKey = regStr.ReplaceAllString(line, "")
} else if mapKey != "" {
idx := strings.Index(line, equalStr)
if idx > -1 {
tKey := strings.TrimSpace(line[:idx])
tValue := strings.TrimSpace(line[idx+1:])
v, has := dick[mapKey]
if has {
//同一队列,支持多次重复写如:
// key = 22222,sdsd,
// key = 3333,cdd
// ;等同 key = 22222,sdsd,3333,cdd
cv, cHas := v[tKey]
if cHas {
cv = v[tKey] + tValue
v[tKey] = cv
} else {
v[tKey] = tValue
}
dick[mapKey] = v
} else {
dick[mapKey] = map[string]string{
tKey: tValue,
}
}
}
}
}
}
return dick
}
// IsChineseCharacters check if the string is chinese character
func IsChineseCharacters(word string) bool {
return CcReg.MatchString(word)
}
// GetLinesFromFile the line from file
func GetLinesFromFile(filename string) []string {
fh, err := os.Open(filename)
if err == nil {
buf := bufio.NewReader(fh)
var lines []string
var linesCase []string
for {
line, err2 := buf.ReadString('\n')
line = strings.TrimSpace(line)
// "#/;" 开头含忽略
w := ""
if line != "" {
w = line[:1]
}
if w == "#" || w == ";" {
line = ""
}
if line != "" {
lines = append(lines, line)
linesCase = append(linesCase, line)
}
// 错误
if err2 != nil {
break
}
}
return lines
}
return nil
}
// GetLinesFromByte the line byte
func GetLinesFromByte(content []byte) []string {
bf := bytes.NewBuffer(content)
buf := bufio.NewReader(bf)
var lines []string
var linesCase []string
for {
line, err2 := buf.ReadString('\n')
line = strings.TrimSpace(line)
// "#/;" 开头含忽略
w := ""
if line != "" {
w = line[:1]
}
if w == "#" || w == ";" {
line = ""
}
if line != "" {
lines = append(lines, line)
linesCase = append(linesCase, line)
}
// 错误
if err2 != nil {
break
}
}
return lines
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。