/// <summary> /// 链表添加 /// </summary> /// <param name="input"></param> public void AddNum(string input) { input = DataCheck.RepLanguage(input); string[] str = input.Split(';'); double[] arr = Sort.BubbleSort(Utils.GetStrToDoubleArr(str[0])); double[] num = Utils.GetStrToDoubleArr(str[1]); ResWrite(LinkListAdd(arr, num).ToString(" , ")); }
public void SaveLanJs(Dictionary <string, string> dic) { StringBuilder builder = new StringBuilder(); builder.Append("var lang = '';\n"); builder.Append("/**\n"); builder.Append("* 获取指定名称的cookie的值\n"); builder.Append("* @param {string} objName\n"); builder.Append("*/\n"); builder.Append("function getCookie(objName) {\n"); builder.Append(" var arrStr = document.cookie.split('; ');\n"); builder.Append(" for (var i = 0; i < arrStr.length; i++) {\n"); builder.Append(" var temp = arrStr[i].split('=');\n"); builder.Append(" if (temp[0] == objName) return unescape(temp[1]);\n"); builder.Append(" }\n"); builder.Append(" return '';\n"); builder.Append("}\n"); builder.Append("\n\n"); builder.Append("var CN = {\n"); builder.Append(" GetLang: function (name) {\n"); builder.Append(" // 判断中文英文\n"); builder.Append(" if (lang == '')\n"); builder.Append(" lang = getCookie('culture');\n"); builder.Append(" if (lang != 'zh-CN' || lang != 'en')\n"); builder.Append(" lang = 'zh-CN';\n"); builder.Append("\n"); builder.Append(" if (lang == 'zh-CN')\n"); builder.Append(" return name;\n"); builder.Append(" var str = '';\n"); builder.Append(" switch (name) { \n"); foreach (var item in dic.Keys) { string key = DataCheck.RepLanguage(item).Replace("'", "\\\'"); string val = DataCheck.RepLanguage(dic[item]).Replace("'", "\\\'"); builder.Append($" case '{key}': str = '{val}'; break;\n"); } builder.Append($" default : str = name; break;\n"); builder.Append(" }\n"); builder.Append(" return str;\n"); builder.Append(" }\n"); builder.Append("}\n"); FileAction.AppendStr("F:\\Lang.js", builder.ToString()); }
public void RepFile() { try { List <string> list = FileAction.ReadToArr(file.FullName); string p = file.FullName.Replace(path, outpath); // 匹配注释正则 string regNotes = "([/]{2,}|[*]+).*"; // 匹配中文正则 string regChinese = @"([\u4e00-\u9fa5]{1,}[\s,,‘“;(()):、:.&\\-a-zA-Z0-9\u4e00-\u9fa5]{0,}[。”’!0-9\u4e00-\u9fa5]{1,})|([\u4e00-\u9fa5]{1})"; int index = 0; foreach (var item in list) { index++; // 去掉注释 string str = DataCheck.RepStr(item.Trim(), regNotes, ""); //是否包含中文 if (!DataCheck.CheckReg(str, regChinese)) { FileAction.AppendStr(p, item + "\n"); } else { // 取出中文 string[] strArr = DataCheck.GetRegStrArr(str, regChinese); string temp = str; string get = ""; // 在语言包中寻找匹配 foreach (var chinese in strArr) { // 如果没有包含汉字,查找下一个 if (!DataCheck.CheckReg(chinese, "[\u4e00-\u9fa5]+")) { continue; } // 若语言包中存在对应中文,直接替换 if (dic.ContainsKey(chinese)) { get = dic[chinese]; temp = temp.Replace(chinese, DataCheck.RepLanguage(dic[chinese], false)); errInfo.Add($"{chinese}\t{dic[chinese]}\t{file.FullName}"); } // 否则,去寻找最类似的中文 else { // 获取极限长度 int min = chinese.Length - 2; int max = chinese.Length + 2; // 判断是否替换 bool bl = false; // 循环字典 foreach (var key in dic.Keys) { // 超出极限长度,则跳出 if (max < key.Length || key.Length < min) { continue; } // 若符合极限长度,且包含当前文字 if (key.Contains(chinese)) { // 进行替换 temp = temp.Replace(chinese, DataCheck.RepLanguage(dic[key], false)); errInfo.Insert(0, $"^{chinese}:{index}行\t{dic[key]}\t{file.FullName}"); bl = true; } } if (!bl) { errInfo.Insert(0, $"^^{chinese}:{index}行\t{file.FullName}"); } } } // 将当前行写入文件 FileAction.AppendStr(p, item.Replace(str, temp) + "\n"); } } } catch (Exception e) { errInfo.Add("错误:" + file.FullName + "\t" + e.Message); } }