Beispiel #1
0
func (c *Cpp_generator) gen_cpp_file(cpp_file *string) bool {
	var text string
	tool.GetFileText(&c.M_cpp_templet_path, &text)

	if text == "" {
		tool.EchoErr("生成c++文件失败:找不到模板文件<%s>", c.M_cpp_templet_path)
		return false
	}

	text = strings.Replace(text, "%cfg%", c.M_cfgbase.Filename, -1)

	text = strings.Replace(text, "%structs_ctor%", splice(c.M_cfgbase, gen_struct_ctor, "\n\n"), -1)
	text = strings.Replace(text, "%structs_print%", splice(c.M_cfgbase, gen_struct_print, "\n\n"), -1)
	text = strings.Replace(text, "%load_funcs%", splice(c.M_cfgbase, gen_load_func, "\n"), -1)
	text = strings.Replace(text, "%clear_funcs%", splice(c.M_cfgbase, gen_clear_func, "\n"), -1)
	text = strings.Replace(text, "%find_funcs%", splice(c.M_cfgbase, gen_find_func, "\n"), -1)

	text = strings.Replace(text, "%mgr%", get_mgr_name(c.M_cfgbase), -1)
	text = strings.Replace(text, "%load_stmt%", splice(c.M_cfgbase, gen_call_load_func_stmt, "\n"), -1)
	text = strings.Replace(text, "%clear_stmt%", splice(c.M_cfgbase, gen_call_clear_func_stmt, "\n"), -1)
	text = strings.Replace(text, "%cfg_member%", get_member_comment_list(c.M_cfgbase), -1)

	enc := mahonia.NewEncoder("GB18030")
	if ret, ok := enc.ConvertStringOK(text); ok {
		// fmt.Println("UTF-8 to GBK: ", ret, " bytes: ", []byte(ret))
		text = string(ret)
	}

	var is_overwrite_file_ok bool = tool.OverWriteFile(cpp_file, &text)
	return is_overwrite_file_ok
}
Beispiel #2
0
func getStockMapByParseFile(localPath string) (stockMap map[string]stockInfo, err error) {
	buf, err := ioutil.ReadFile(localPath)
	if err != nil {
		return stockMap, Error("read remote stock map error")
	}

	enc := mahonia.NewEncoder("gbk")
	remoteStocksText := string(buf)
	//remoteStocksText = enc.ConvertString(remoteStocksText) //转换utf-8编码
	index := strings.Index(remoteStocksText, enc.ConvertString("股票代码查询一览表:"))
	if index == -1 {
		return stockMap, Error("parse remote stock map error")
	}
	remoteStocksText = remoteStocksText[index:]
	index = strings.Index(remoteStocksText, string("<ul>"))
	if index == -1 {
		return stockMap, Error("parse remote stock map error")
	}
	shangHaiEndIndex := strings.Index(remoteStocksText, string("</ul>"))
	if shangHaiEndIndex == -1 || shangHaiEndIndex < index {
		return stockMap, Error("parse remote stock map error")
	}
	shangHaiStocksText := remoteStocksText[index:shangHaiEndIndex]

	remoteStocksText = remoteStocksText[shangHaiEndIndex+1:] //从加1开始查深圳股票,不然shenZhenEndIndex就是0
	index = strings.Index(remoteStocksText, string("<ul>"))
	if index == -1 {
		return stockMap, Error("parse remote stock map error")
	}
	shenZhenEndIndex := strings.Index(remoteStocksText, string("</ul>"))
	if shenZhenEndIndex == -1 || shenZhenEndIndex < index {
		return stockMap, Error("parse remote stock map error")
	}
	shenZhenStocksText := remoteStocksText[index:shenZhenEndIndex]

	shanghaiStocks, err := parseRemoteStockMapByUL(shangHaiStocksText)
	if err != nil {
		return stockMap, err
	}

	shenZhenStocks, err := parseRemoteStockMapByUL(shenZhenStocksText)
	if err != nil {
		return stockMap, err
	}

	stockMap = make(map[string]stockInfo)
	for key, info := range shanghaiStocks {
		info.address = 1
		stockMap[key] = info
	}
	//充分利用深圳股票的枚举是0
	for key, info := range shenZhenStocks {
		stockMap[key] = info
	}
	return stockMap, err
}
Beispiel #3
0
func iconv(str string) string {
	enc := mahonia.NewEncoder("gb2312")
	return enc.ConvertString(str)
}